1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.util.xml.descriptor;
24  
25  import com.liferay.util.xml.ElementIdentifier;
26  
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  import org.dom4j.Document;
31  import org.dom4j.Element;
32  
33  /**
34   * <a href="WebXML24Descriptor.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Jorge Ferrer
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class WebXML24Descriptor extends SimpleXMLDescriptor {
41  
42      public WebXML24Descriptor() {
43          _orderedChildren.put(
44              "jsp-config", new String[] {"taglib", "jsp-property-group"});
45      }
46  
47      public boolean canHandleType(String doctype, Document root) {
48          if (doctype.indexOf("web-app") != -1) {
49              return true;
50          }
51          else {
52              return false;
53          }
54      }
55  
56      public String[] getRootChildrenOrder() {
57          return _ROOT_ORDERED_CHILDREN;
58      }
59  
60      public String[] getChildrenOrder(Element parentElement) {
61          String parentName = parentElement.getQName().getName();
62  
63          if (_orderedChildren.containsKey(parentName)){
64              return _orderedChildren.get(parentName);
65          }
66  
67          return new String[0];
68      }
69  
70      public ElementIdentifier[] getElementsIdentifiedByAttribute() {
71          return _ELEMENTS_IDENTIFIED_BY_ATTR;
72      }
73  
74      public ElementIdentifier[] getElementsIdentifiedByChild() {
75          return _ELEMENTS_IDENTIFIED_BY_CHILD;
76      }
77  
78      public String[] getUniqueElements() {
79          return _UNIQUE_ELEMENTS;
80      }
81  
82      public String[] getJoinableElements() {
83          return _JOINABLE_ELEMENTS;
84      }
85  
86      private static final String[] _ROOT_ORDERED_CHILDREN = {
87          "icon", "display-name", "description", "distributable", "context-param",
88          "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
89          "session-config", "mime-mapping", "welcome-file-list", "error-page",
90          "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
91          "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
92      };
93  
94      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
95      };
96  
97      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
98          new ElementIdentifier("context-param", "param-name"),
99          new ElementIdentifier("filter", "filter-name"),
100         //new ElementIdentifier("filter-mapping", "filter-name"),
101         new ElementIdentifier("servlet", "servlet-name"),
102         //new ElementIdentifier("servlet-mapping", "servlet-name"),
103         new ElementIdentifier("init-param", "param-name"),
104         new ElementIdentifier("taglib", "taglib-uri"),
105         new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
106         new ElementIdentifier("resource-ref", "res-ref-name"),
107         new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
108     };
109 
110     private static final String[] _UNIQUE_ELEMENTS = {
111         "icon", "display-name", "description", "distributable",
112         "session-config", "welcome-file-list", "jsp-config", "login-config"
113     };
114 
115     private static final String[] _JOINABLE_ELEMENTS = {
116         "welcome-file-list", "jsp-config"
117     };
118 
119     private Map<String, String[]> _orderedChildren =
120         new HashMap<String, String[]>();
121 
122 }