KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > config > ClientElementReader


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

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 /**
25  * Custom element reader to parse config for client config values
26  *
27  * @author Kevin Roast
28  */

29 public class ClientElementReader implements ConfigElementReader
30 {
31    public static final String JavaDoc ELEMENT_RECENTSPACESITEMS = "recent-spaces-items";
32    public static final String JavaDoc ELEMENT_ERRORPAGE = "error-page";
33    public static final String JavaDoc ELEMENT_LOGINPAGE = "login-page";
34    public static final String JavaDoc ELEMENT_HELPURL = "help-url";
35    public static final String JavaDoc ELEMENT_EDITLINKTYPE = "edit-link-type";
36    public static final String JavaDoc ELEMENT_SEARCHMINIMUM = "search-minimum";
37    public static final String JavaDoc ELEMENT_SEARCHANDTERMS = "search-and-terms";
38    public static final String JavaDoc ELEMENT_SEARCHMAXRESULTS = "search-max-results";
39    public static final String JavaDoc ELEMENT_HOMESPACEPERMISSION = "home-space-permission";
40    public static final String JavaDoc ELEMENT_FROMEMAILADDRESS = "from-email-address";
41    public static final String JavaDoc ELEMENT_SHELFVISIBLE = "shelf-visible";
42    
43    /**
44     * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
45     */

46    @SuppressWarnings JavaDoc("unchecked")
47    public ConfigElement parse(Element element)
48    {
49       ClientConfigElement configElement = null;
50       
51       if (element != null)
52       {
53          String JavaDoc 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          // get the recent space max items
64
Element recentSpaces = element.element(ELEMENT_RECENTSPACESITEMS);
65          if (recentSpaces != null)
66          {
67             configElement.setRecentSpacesItems(Integer.parseInt(recentSpaces.getTextTrim()));
68          }
69          
70          // get the shelf component default visibility
71
Element shelfVisible = element.element(ELEMENT_SHELFVISIBLE);
72          if (shelfVisible != null)
73          {
74             configElement.setShelfVisible(Boolean.parseBoolean(shelfVisible.getTextTrim()));
75          }
76          
77          // get the Help url
78
Element helpUrl = element.element(ELEMENT_HELPURL);
79          if (helpUrl != null)
80          {
81             configElement.setHelpUrl(helpUrl.getTextTrim());
82          }
83          
84          // get the edit link type
85
Element editLinkType = element.element(ELEMENT_EDITLINKTYPE);
86          if (editLinkType != null)
87          {
88             configElement.setEditLinkType(editLinkType.getTextTrim());
89          }
90          
91          // get the minimum number of characters for valid search string
92
Element searchMin = element.element(ELEMENT_SEARCHMINIMUM);
93          if (searchMin != null)
94          {
95             configElement.setSearchMinimum(Integer.parseInt(searchMin.getTextTrim()));
96          }
97          
98          // get the search force AND terms setting
99
Element searchForceAnd = element.element(ELEMENT_SEARCHANDTERMS);
100          if (searchForceAnd != null)
101          {
102             configElement.setForceAndTerms(Boolean.parseBoolean(searchForceAnd.getTextTrim()));
103          }
104          
105          // get the search max results size
106
Element searchMaxResults = element.element(ELEMENT_SEARCHMAXRESULTS);
107          if (searchMaxResults != null)
108          {
109             configElement.setSearchMaxResults(Integer.parseInt(searchMaxResults.getTextTrim()));
110          }
111          
112          // get the default permission for newly created users Home Spaces
113
Element permission = element.element(ELEMENT_HOMESPACEPERMISSION);
114          if (permission != null)
115          {
116             configElement.setHomeSpacePermission(permission.getTextTrim());
117          }
118          
119          // get the from address to use when sending emails from the client
120
Element fromEmail = element.element(ELEMENT_FROMEMAILADDRESS);
121          if (fromEmail != null)
122          {
123             configElement.setFromEmailAddress(fromEmail.getTextTrim());
124          }
125          
126          // get the error page
127
Element errorPage = element.element(ELEMENT_ERRORPAGE);
128          if (errorPage != null)
129          {
130             configElement.setErrorPage(errorPage.getTextTrim());
131          }
132          
133          // get the login page
134
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