/* * Copyright (C) 2005 Alfresco, Inc. * * Licensed under the Mozilla Public License version 1.1 * with a permitted attribution clause. You may obtain a * copy of the License at * * http://www.alfresco.org/legal/license.txt * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. */ package org.alfresco.web.config; import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigException; import org.alfresco.config.xml.elementreader.ConfigElementReader; import org.dom4j.Element; /** * Custom element reader to parse config for client config values * * @author Kevin Roast */ public class ClientElementReader implements ConfigElementReader { public static final String ELEMENT_RECENTSPACESITEMS = "recent-spaces-items"; public static final String ELEMENT_ERRORPAGE = "error-page"; public static final String ELEMENT_LOGINPAGE = "login-page"; public static final String ELEMENT_HELPURL = "help-url"; public static final String ELEMENT_EDITLINKTYPE = "edit-link-type"; public static final String ELEMENT_SEARCHMINIMUM = "search-minimum"; public static final String ELEMENT_HOMESPACEPERMISSION = "home-space-permission"; public static final String ELEMENT_FROMEMAILADDRESS = "from-email-address"; public static final String ELEMENT_SHELFVISIBLE = "shelf-visible"; /** * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) */ @SuppressWarnings("unchecked") public ConfigElement parse(Element element) { ClientConfigElement configElement = null; if (element != null) { String name = element.getName(); if (name.equals(ClientConfigElement.CONFIG_ELEMENT_ID) == false) { throw new ConfigException("ClientElementReader can only parse " + ClientConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + name + "'"); } configElement = new ClientConfigElement(); // get the recent space max items Element recentSpaces = element.element(ELEMENT_RECENTSPACESITEMS); if (recentSpaces != null) { configElement.setRecentSpacesItems(Integer.parseInt(recentSpaces.getTextTrim())); } // get the shelf component default visibility Element shelfVisible = element.element(ELEMENT_SHELFVISIBLE); if (shelfVisible != null) { configElement.setShelfVisible(Boolean.parseBoolean(shelfVisible.getTextTrim())); } // get the Help url Element helpUrl = element.element(ELEMENT_HELPURL); if (helpUrl != null) { configElement.setHelpUrl(helpUrl.getTextTrim()); } // get the edit link type Element editLinkType = element.element(ELEMENT_EDITLINKTYPE); if (editLinkType != null) { configElement.setEditLinkType(editLinkType.getTextTrim()); } // get the minimum number of characters for valid search string Element searchMin = element.element(ELEMENT_SEARCHMINIMUM); if (searchMin != null) { configElement.setSearchMinimum(Integer.parseInt(searchMin.getTextTrim())); } // get the default permission for newly created users Home Spaces Element permission = element.element(ELEMENT_HOMESPACEPERMISSION); if (permission != null) { configElement.setHomeSpacePermission(permission.getTextTrim()); } // get the from address to use when sending emails from the client Element fromEmail = element.element(ELEMENT_FROMEMAILADDRESS); if (fromEmail != null) { configElement.setFromEmailAddress(fromEmail.getTextTrim()); } // get the error page Element errorPage = element.element(ELEMENT_ERRORPAGE); if (errorPage != null) { configElement.setErrorPage(errorPage.getTextTrim()); } // get the login page Element loginPage = element.element(ELEMENT_LOGINPAGE); if (loginPage != null) { configElement.setLoginPage(loginPage.getTextTrim()); } } return configElement; } }