PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/packager/src/net/rim/tumbler/config/WidgetConfig.java

https://github.com/arun11252/WebWorks
Java | 528 lines | 390 code | 108 blank | 30 comment | 27 complexity | 8cc134b499ab4f84ff787cd8621750ec MD5 | raw file
  1. /*
  2. * Copyright 2010-2011 Research In Motion Limited.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package net.rim.tumbler.config;
  17. import java.util.HashMap;
  18. import java.util.Hashtable;
  19. import java.util.Map;
  20. import java.util.Vector;
  21. import java.util.regex.Matcher;
  22. import java.util.regex.Pattern;
  23. import net.rim.tumbler.exception.ValidationException;
  24. import net.rim.tumbler.log.LogType;
  25. import net.rim.tumbler.log.Logger;
  26. import net.rim.tumbler.session.SessionManager;
  27. public class WidgetConfig {
  28. private String _content;
  29. private String _author;
  30. private String _authorEmail;
  31. private String _authorURL;
  32. private String _name;
  33. private String _version;
  34. private String _loadingScreenColour;
  35. private String _backgroundImage;
  36. private String _foregroundImage;
  37. private boolean _firstPageLoad;
  38. private boolean _remotePageLoad;
  39. private boolean _localPageLoad;
  40. private String _transitionType;
  41. private int _transitionDuration;
  42. private String _transitionDirection;
  43. private String _copyright;
  44. private String _description;
  45. private Vector<String> _hoverIconSrc;
  46. private Vector<String> _iconSrc;
  47. private String _id;
  48. private Map<String, String> _customHeaders;
  49. private String _backButton;
  50. private boolean _navigationMode;
  51. private String _contentType;
  52. private String _contentCharSet;
  53. private String _license;
  54. private String _licenseURL;
  55. private int _transportTimeout;
  56. private String[] _transportOrder;
  57. private boolean _multiAccess;
  58. private String _configXML;
  59. private Hashtable<WidgetAccess, Vector<WidgetFeature>> _accessTable;
  60. private Vector<String> _extensionClasses;
  61. // Cache fields
  62. private Boolean _cacheEnabled;
  63. private Boolean _aggressivelyCaching;
  64. private Integer _aggressiveCacheAge;
  65. private Integer _maxCacheable;
  66. private Integer _maxCacheSize; // Total cache size
  67. //Auto-Startup Fields
  68. private boolean _runOnStartup;
  69. private boolean _allowInvokeParams;
  70. private String _backgroundSource;
  71. private String _foregroundSource;
  72. // Debug issue
  73. private boolean _debugEnabled=false;
  74. public WidgetConfig() {
  75. // Set defaults
  76. _accessTable = new Hashtable<WidgetAccess, Vector<WidgetFeature>>();
  77. _hoverIconSrc = new Vector<String>();
  78. _customHeaders = new HashMap<String, String>();
  79. _iconSrc = new Vector<String>();
  80. _configXML = "config.xml";
  81. _transportTimeout = -1;
  82. _backgroundImage = null;
  83. _foregroundImage = null;
  84. _firstPageLoad = false;
  85. _remotePageLoad = false;
  86. _localPageLoad = false;
  87. _transitionType = null;
  88. _transitionDuration = -1;
  89. _transitionDirection = null;
  90. _cacheEnabled = null;
  91. _aggressivelyCaching = null;
  92. _aggressiveCacheAge= null;
  93. _maxCacheable = null;
  94. _maxCacheSize = null;
  95. _runOnStartup=false;
  96. _allowInvokeParams=false;
  97. _backgroundSource=null;
  98. _foregroundSource=null;
  99. _debugEnabled = SessionManager.getInstance().debugMode();
  100. }
  101. public void validate() {
  102. if (_version == null || _version.length() == 0) {
  103. Logger.logMessage(LogType.WARNING,
  104. "VALIDATION_CONFIGXML_MISSING_VERSION");
  105. _version = "1.0.0.0";
  106. }
  107. }
  108. public String getContent() {
  109. return _content;
  110. }
  111. public String getAuthor() {
  112. return _author;
  113. }
  114. public String getName() {
  115. return _name;
  116. }
  117. public String getVersion() {
  118. return _version;
  119. }
  120. public String getLoadingScreenColour() {
  121. return _loadingScreenColour;
  122. }
  123. public String getCopyright() {
  124. return _copyright;
  125. }
  126. public String getDescription() {
  127. return _description;
  128. }
  129. public Vector<String> getHoverIconSrc() {
  130. return _hoverIconSrc;
  131. }
  132. public Vector<String> getIconSrc() {
  133. return _iconSrc;
  134. }
  135. public void setContent(String content) {
  136. _content = content;
  137. }
  138. public void setAuthor(String author) {
  139. _author = author;
  140. }
  141. public void setName(String name) throws ValidationException {
  142. if (name == null || name.length() == 0) {
  143. throw new ValidationException(
  144. "EXCEPTION_CONFIGXML_MISSING_WIDGET_NAME");
  145. } else if ( name.indexOf(",") != -1 ) {
  146. throw new ValidationException(
  147. "EXCEPTION_CONFIGXML_INVALID_WIDGET_NAME" );
  148. }
  149. _name = name;
  150. }
  151. public void setVersion(String version) throws ValidationException {
  152. if (SessionManager.getInstance().isVerbose()) {
  153. Logger.logMessage(LogType.INFO,
  154. "PROGRESS_VALIDATING_CONFIG_XML_WIDGET_VERSION");
  155. }
  156. // version variable should look like one of the options:
  157. // version="a.b"
  158. // version="a.b.c"
  159. // version="a.b.c.d"
  160. String regex = "\\d{1,3}\\.\\d{1,3}(\\.\\d{1,3}){0,2}$";
  161. Pattern pattern = Pattern.compile(regex);
  162. Matcher matcher = pattern.matcher(version);
  163. if (!matcher.matches()) {
  164. throw new ValidationException("EXCEPTION_CONFIGXML_INVALID_VERSION");
  165. }
  166. _version = version;
  167. }
  168. public void setLoadingScreenColour(String screenColour)
  169. throws ValidationException {
  170. if (screenColour != null) {
  171. if (SessionManager.getInstance().isVerbose()) {
  172. Logger.logMessage(LogType.INFO,
  173. "PROGRESS_VALIDATING_CONFIG_XML_LOADINGSCREEN_COLOR");
  174. }
  175. // Color variable should look like: #000000
  176. String regex = "^#[A-Fa-f0-9]{6}$";
  177. Pattern pattern = Pattern.compile(regex);
  178. Matcher matcher = pattern.matcher(screenColour);
  179. if (!matcher.matches()) {
  180. throw new ValidationException(
  181. "EXCEPTION_CONFIGXML_LOADINGSCREEN_COLOUR");
  182. }
  183. }
  184. _loadingScreenColour = screenColour;
  185. }
  186. public String getBackgroundImage() {
  187. return _backgroundImage;
  188. }
  189. public void setBackgroundImage(String src) {
  190. _backgroundImage = src;
  191. }
  192. public String getForegroundImage() {
  193. return _foregroundImage;
  194. }
  195. public void setForegroundImage(String src) {
  196. _foregroundImage = src;
  197. }
  198. public boolean getFirstPageLoad() {
  199. return _firstPageLoad;
  200. }
  201. public void setFirstPageLoad(boolean value) {
  202. _firstPageLoad = value;
  203. }
  204. public boolean getRemotePageLoad() {
  205. return _remotePageLoad;
  206. }
  207. public void setRemotePageLoad(boolean value) {
  208. _remotePageLoad = value;
  209. }
  210. public boolean getLocalPageLoad() {
  211. return _localPageLoad;
  212. }
  213. public void setLocalPageLoad(boolean value) {
  214. _localPageLoad = value;
  215. }
  216. public String getTransitionType() {
  217. return _transitionType;
  218. }
  219. public void setTransitionType(String value) {
  220. _transitionType = value;
  221. }
  222. public int getTransitionDuration() {
  223. return _transitionDuration;
  224. }
  225. public void setTransitionDuration(int value) {
  226. _transitionDuration = value;
  227. }
  228. public String getTransitionDirection() {
  229. return _transitionDirection;
  230. }
  231. public void setTransitionDirection(String value) {
  232. _transitionDirection = value;
  233. }
  234. public void setCopyright(String copyright) {
  235. _copyright = copyright;
  236. }
  237. public void setDescription(String description) {
  238. _description = description;
  239. }
  240. public void addHoverIcon(String icon) {
  241. _hoverIconSrc.add(icon);
  242. }
  243. public void addIcon(String icon) {
  244. _iconSrc.add(icon);
  245. }
  246. public String getID() {
  247. return _id;
  248. }
  249. public void setID(String id) {
  250. _id = id;
  251. }
  252. public Map<String, String> getCustomHeaders() {
  253. return _customHeaders;
  254. }
  255. public void addHeader(String key, String value) {
  256. _customHeaders.put(key, value);
  257. }
  258. public String getBackButtonBehaviour() {
  259. return _backButton;
  260. }
  261. public void setBackButtonBehaviour(String value) {
  262. _backButton = value;
  263. }
  264. public boolean getNavigationMode() {
  265. return _navigationMode;
  266. }
  267. public void setNavigationMode(boolean value) {
  268. _navigationMode = value;
  269. }
  270. public String getContentType() {
  271. return _contentType;
  272. }
  273. public String getContentCharSet() {
  274. return _contentCharSet;
  275. }
  276. public void setContentType(String type) {
  277. _contentType = type;
  278. }
  279. public void setContentCharSet(String charSet) {
  280. _contentCharSet = charSet;
  281. }
  282. public String getLicense() {
  283. return _license;
  284. }
  285. public String getLicenseURL() {
  286. return _licenseURL;
  287. }
  288. public void setLicense(String license) {
  289. _license = license;
  290. }
  291. public void setLicenseURL(String licenseurl) {
  292. _licenseURL = licenseurl;
  293. }
  294. public void setAuthorURL(String authorURL) {
  295. _authorURL = authorURL;
  296. }
  297. public String getAuthorURL() {
  298. return _authorURL;
  299. }
  300. public void setAuthorEmail(String authorEmail) {
  301. _authorEmail = authorEmail;
  302. }
  303. public String getAuthorEmail() {
  304. return _authorEmail;
  305. }
  306. public void setTransportTimeout(int transportTimeout) {
  307. _transportTimeout = transportTimeout;
  308. }
  309. public int getTransportTimeout() {
  310. return _transportTimeout;
  311. }
  312. public void setTransportOrder(String[] transportOrder) {
  313. _transportOrder = transportOrder;
  314. }
  315. public String[] getTransportOrder() {
  316. return _transportOrder;
  317. }
  318. public boolean allowMultiAccess() {
  319. return _multiAccess;
  320. }
  321. public void setMultiAccess(boolean multiAccess) {
  322. _multiAccess = multiAccess;
  323. }
  324. public String getConfigXML() {
  325. return _configXML;
  326. }
  327. public void setConfigXML(String configXML) {
  328. _configXML = configXML;
  329. }
  330. public Hashtable<WidgetAccess, Vector<WidgetFeature>> getAccessTable() {
  331. return _accessTable;
  332. }
  333. public void setAccessTable(
  334. Hashtable<WidgetAccess, Vector<WidgetFeature>> table) {
  335. _accessTable = table;
  336. }
  337. public void setExtensionClasses(Vector<String> classes) {
  338. _extensionClasses = classes;
  339. }
  340. public Vector<String> getExtensionClasses() {
  341. return _extensionClasses;
  342. }
  343. // Cache field functions
  344. public Boolean isCacheEnabled() {
  345. return _cacheEnabled;
  346. }
  347. public void setCacheEnabled(boolean inputValue) {
  348. _cacheEnabled = inputValue;
  349. }
  350. public Boolean isAggressiveCacheEnabled() {
  351. return _aggressivelyCaching;
  352. }
  353. private void setAggressiveCache(boolean inputValue) {
  354. _aggressivelyCaching = inputValue;
  355. }
  356. public Integer getAggressiveCacheAge() {
  357. return _aggressiveCacheAge;
  358. }
  359. public void setAggressiveCacheAge(int inputValue) {
  360. // Enable aggressive cache flag if the value is above 0
  361. if (inputValue > 0){
  362. setAggressiveCache(true);
  363. } else if (inputValue == -1) {
  364. setAggressiveCache(false);
  365. }
  366. // Max value is 30 days
  367. if(inputValue <= 2592000){
  368. _aggressiveCacheAge = inputValue;
  369. }
  370. }
  371. public Integer getMaxCacheSize() {
  372. return _maxCacheSize;
  373. }
  374. public void setMaxCacheSize(int inputValue) {
  375. // Min value of 0, max value of 2048 KB
  376. final int kb_2048 = 2048 * 1024;
  377. if (inputValue >= 0 && inputValue <= (kb_2048)){
  378. _maxCacheSize = inputValue;
  379. } else if (inputValue > kb_2048) {
  380. _maxCacheSize = kb_2048;
  381. }
  382. }
  383. public Integer getMaxCacheItemSize() {
  384. return _maxCacheable;
  385. }
  386. public void setMaxCacheItemSize(int inputValue) {
  387. // -1 is a valid value
  388. if (inputValue >= -1){
  389. _maxCacheable = inputValue;
  390. }
  391. }
  392. //Auto-Startup Accessors and Mutators
  393. public Boolean isStartupEnabled() {
  394. return _runOnStartup;
  395. }
  396. public void setStartup(Boolean runOnStartup) {
  397. _runOnStartup = runOnStartup;
  398. }
  399. public String getBackgroundSource() {
  400. return _backgroundSource;
  401. }
  402. public String getForegroundSource() {
  403. return _foregroundSource;
  404. }
  405. public void setForegroundSource(String foregroundSource) {
  406. _foregroundSource = foregroundSource;
  407. }
  408. public void setBackgroundSource(String backgroundSource) {
  409. _backgroundSource = backgroundSource;
  410. }
  411. public Boolean allowInvokeParams() {
  412. return _allowInvokeParams;
  413. }
  414. public void setAllowInvokeParams(Boolean allowInvokeParams) {
  415. _allowInvokeParams = allowInvokeParams;
  416. }
  417. public boolean isDebugEnabled() {
  418. return _debugEnabled;
  419. }
  420. }