1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class WebXML24Descriptor extends SimpleXMLDescriptor {
40  
41      public WebXML24Descriptor() {
42          _orderedChildren.put(
43              "jsp-config", new String[] {"taglib", "jsp-property-group"});
44      }
45  
46      public boolean canHandleType(String doctype, Document root) {
47          if (doctype.indexOf("web-app") != -1) {
48              return true;
49          }
50          else {
51              return false;
52          }
53      }
54  
55      public String[] getRootChildrenOrder() {
56          return _ROOT_ORDERED_CHILDREN;
57      }
58  
59      public String[] getChildrenOrder(Element parentElement) {
60          String parentName = parentElement.getQName().getName();
61  
62          if (_orderedChildren.containsKey(parentName)) {
63              return _orderedChildren.get(parentName);
64          }
65  
66          return new String[0];
67      }
68  
69      public ElementIdentifier[] getElementsIdentifiedByAttribute() {
70          return _ELEMENTS_IDENTIFIED_BY_ATTR;
71      }
72  
73      public ElementIdentifier[] getElementsIdentifiedByChild() {
74          return _ELEMENTS_IDENTIFIED_BY_CHILD;
75      }
76  
77      public String[] getUniqueElements() {
78          return _UNIQUE_ELEMENTS;
79      }
80  
81      public String[] getJoinableElements() {
82          return _JOINABLE_ELEMENTS;
83      }
84  
85      private static final String[] _ROOT_ORDERED_CHILDREN = {
86          "icon", "display-name", "description", "distributable", "context-param",
87          "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
88          "session-config", "mime-mapping", "welcome-file-list", "error-page",
89          "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
90          "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
91      };
92  
93      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
94      };
95  
96      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
97          new ElementIdentifier("context-param", "param-name"),
98          new ElementIdentifier("filter", "filter-name"),
99          //new ElementIdentifier("filter-mapping", "filter-name"),
100         new ElementIdentifier("servlet", "servlet-name"),
101         //new ElementIdentifier("servlet-mapping", "servlet-name"),
102         new ElementIdentifier("init-param", "param-name"),
103         new ElementIdentifier("taglib", "taglib-uri"),
104         new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
105         new ElementIdentifier("resource-ref", "res-ref-name"),
106         new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
107     };
108 
109     private static final String[] _UNIQUE_ELEMENTS = {
110         "icon", "display-name", "description", "distributable",
111         "session-config", "welcome-file-list", "jsp-config", "login-config"
112     };
113 
114     private static final String[] _JOINABLE_ELEMENTS = {
115         "welcome-file-list", "jsp-config"
116     };
117 
118     private Map<String, String[]> _orderedChildren =
119         new HashMap<String, String[]>();
120 
121 }