1 17 package org.alfresco.web.config; 18 19 import org.alfresco.config.ConfigElement; 20 import org.alfresco.config.ConfigException; 21 import org.alfresco.config.xml.elementreader.ConfigElementReader; 22 import org.dom4j.Element; 23 24 29 public class ClientElementReader implements ConfigElementReader 30 { 31 public static final String ELEMENT_RECENTSPACESITEMS = "recent-spaces-items"; 32 public static final String ELEMENT_ERRORPAGE = "error-page"; 33 public static final String ELEMENT_LOGINPAGE = "login-page"; 34 public static final String ELEMENT_HELPURL = "help-url"; 35 public static final String ELEMENT_EDITLINKTYPE = "edit-link-type"; 36 public static final String ELEMENT_SEARCHMINIMUM = "search-minimum"; 37 public static final String ELEMENT_SEARCHANDTERMS = "search-and-terms"; 38 public static final String ELEMENT_SEARCHMAXRESULTS = "search-max-results"; 39 public static final String ELEMENT_HOMESPACEPERMISSION = "home-space-permission"; 40 public static final String ELEMENT_FROMEMAILADDRESS = "from-email-address"; 41 public static final String ELEMENT_SHELFVISIBLE = "shelf-visible"; 42 43 46 @SuppressWarnings ("unchecked") 47 public ConfigElement parse(Element element) 48 { 49 ClientConfigElement configElement = null; 50 51 if (element != null) 52 { 53 String name = element.getName(); 54 if (name.equals(ClientConfigElement.CONFIG_ELEMENT_ID) == false) 55 { 56 throw new ConfigException("ClientElementReader can only parse " + 57 ClientConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + 58 name + "'"); 59 } 60 61 configElement = new ClientConfigElement(); 62 63 Element recentSpaces = element.element(ELEMENT_RECENTSPACESITEMS); 65 if (recentSpaces != null) 66 { 67 configElement.setRecentSpacesItems(Integer.parseInt(recentSpaces.getTextTrim())); 68 } 69 70 Element shelfVisible = element.element(ELEMENT_SHELFVISIBLE); 72 if (shelfVisible != null) 73 { 74 configElement.setShelfVisible(Boolean.parseBoolean(shelfVisible.getTextTrim())); 75 } 76 77 Element helpUrl = element.element(ELEMENT_HELPURL); 79 if (helpUrl != null) 80 { 81 configElement.setHelpUrl(helpUrl.getTextTrim()); 82 } 83 84 Element editLinkType = element.element(ELEMENT_EDITLINKTYPE); 86 if (editLinkType != null) 87 { 88 configElement.setEditLinkType(editLinkType.getTextTrim()); 89 } 90 91 Element searchMin = element.element(ELEMENT_SEARCHMINIMUM); 93 if (searchMin != null) 94 { 95 configElement.setSearchMinimum(Integer.parseInt(searchMin.getTextTrim())); 96 } 97 98 Element searchForceAnd = element.element(ELEMENT_SEARCHANDTERMS); 100 if (searchForceAnd != null) 101 { 102 configElement.setForceAndTerms(Boolean.parseBoolean(searchForceAnd.getTextTrim())); 103 } 104 105 Element searchMaxResults = element.element(ELEMENT_SEARCHMAXRESULTS); 107 if (searchMaxResults != null) 108 { 109 configElement.setSearchMaxResults(Integer.parseInt(searchMaxResults.getTextTrim())); 110 } 111 112 Element permission = element.element(ELEMENT_HOMESPACEPERMISSION); 114 if (permission != null) 115 { 116 configElement.setHomeSpacePermission(permission.getTextTrim()); 117 } 118 119 Element fromEmail = element.element(ELEMENT_FROMEMAILADDRESS); 121 if (fromEmail != null) 122 { 123 configElement.setFromEmailAddress(fromEmail.getTextTrim()); 124 } 125 126 Element errorPage = element.element(ELEMENT_ERRORPAGE); 128 if (errorPage != null) 129 { 130 configElement.setErrorPage(errorPage.getTextTrim()); 131 } 132 133 Element loginPage = element.element(ELEMENT_LOGINPAGE); 135 if (loginPage != null) 136 { 137 configElement.setLoginPage(loginPage.getTextTrim()); 138 } 139 } 140 141 return configElement; 142 } 143 } 144 | Popular Tags |