KickJava   Java API By Example, From Geeks To Geeks.

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


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 server details
26  *
27  * @author gavinc
28  */

29 public class ServerElementReader implements ConfigElementReader
30 {
31    public static final String JavaDoc ELEMENT_SERVER = "server";
32    public static final String JavaDoc ELEMENT_ERROR_PAGE = "error-page";
33    public static final String JavaDoc ELEMENT_LOGIN_PAGE = "login-page";
34    
35    /**
36     * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
37     */

38    public ConfigElement parse(Element element)
39    {
40       ServerConfigElement configElement = null;
41       
42       if (element != null)
43       {
44          String JavaDoc name = element.getName();
45          if (name.equals(ELEMENT_SERVER) == false)
46          {
47             throw new ConfigException("ServerElementReader can only parse " +
48                   ELEMENT_SERVER + "elements, " + "the element passed was '" +
49                   name + "'");
50          }
51          
52          configElement = new ServerConfigElement();
53          
54          // get the error page
55
Element errorPage = element.element(ELEMENT_ERROR_PAGE);
56          if (errorPage != null)
57          {
58             configElement.setErrorPage(errorPage.getTextTrim());
59          }
60          
61          // get the login page
62
Element loginPage = element.element(ELEMENT_LOGIN_PAGE);
63          if (loginPage != null)
64          {
65             configElement.setLoginPage(loginPage.getTextTrim());
66          }
67       }
68       
69       return configElement;
70    }
71 }
72
Popular Tags