1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.xml.descriptor;
16  
17  import com.liferay.util.xml.ElementIdentifier;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.dom4j.Document;
23  import org.dom4j.Element;
24  
25  /**
26   * <a href="WebXML24Descriptor.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Jorge Ferrer
29   * @author Brian Wing Shun Chan
30   */
31  public class WebXML24Descriptor extends SimpleXMLDescriptor {
32  
33      public WebXML24Descriptor() {
34          _orderedChildren.put(
35              "jsp-config", new String[] {"taglib", "jsp-property-group"});
36      }
37  
38      public boolean canHandleType(String doctype, Document root) {
39          if (doctype.indexOf("web-app") != -1) {
40              return true;
41          }
42          else {
43              return false;
44          }
45      }
46  
47      public String[] getRootChildrenOrder() {
48          return _ROOT_ORDERED_CHILDREN;
49      }
50  
51      public String[] getChildrenOrder(Element parentElement) {
52          String parentName = parentElement.getQName().getName();
53  
54          if (_orderedChildren.containsKey(parentName)) {
55              return _orderedChildren.get(parentName);
56          }
57  
58          return new String[0];
59      }
60  
61      public ElementIdentifier[] getElementsIdentifiedByAttribute() {
62          return _ELEMENTS_IDENTIFIED_BY_ATTR;
63      }
64  
65      public ElementIdentifier[] getElementsIdentifiedByChild() {
66          return _ELEMENTS_IDENTIFIED_BY_CHILD;
67      }
68  
69      public String[] getUniqueElements() {
70          return _UNIQUE_ELEMENTS;
71      }
72  
73      public String[] getJoinableElements() {
74          return _JOINABLE_ELEMENTS;
75      }
76  
77      private static final String[] _ROOT_ORDERED_CHILDREN = {
78          "icon", "display-name", "description", "distributable", "context-param",
79          "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
80          "session-config", "mime-mapping", "welcome-file-list", "error-page",
81          "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
82          "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
83      };
84  
85      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
86      };
87  
88      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
89          new ElementIdentifier("context-param", "param-name"),
90          new ElementIdentifier("filter", "filter-name"),
91          //new ElementIdentifier("filter-mapping", "filter-name"),
92          new ElementIdentifier("servlet", "servlet-name"),
93          //new ElementIdentifier("servlet-mapping", "servlet-name"),
94          new ElementIdentifier("init-param", "param-name"),
95          new ElementIdentifier("taglib", "taglib-uri"),
96          new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
97          new ElementIdentifier("resource-ref", "res-ref-name"),
98          new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
99      };
100 
101     private static final String[] _UNIQUE_ELEMENTS = {
102         "icon", "display-name", "description", "distributable",
103         "session-config", "welcome-file-list", "jsp-config", "login-config"
104     };
105 
106     private static final String[] _JOINABLE_ELEMENTS = {
107         "welcome-file-list", "jsp-config"
108     };
109 
110     private Map<String, String[]> _orderedChildren =
111         new HashMap<String, String[]>();
112 
113 }