1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.util.xml.descriptor;
21  
22  import com.liferay.util.xml.ElementIdentifier;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.dom4j.Document;
28  import org.dom4j.Element;
29  
30  /**
31   * <a href="WebXML24Descriptor.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Jorge Ferrer
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class WebXML24Descriptor extends SimpleXMLDescriptor {
38  
39      public WebXML24Descriptor() {
40          _orderedChildren.put(
41              "jsp-config", new String[] {"taglib", "jsp-property-group"});
42      }
43  
44      public boolean canHandleType(String doctype, Document root) {
45          if (doctype.indexOf("web-app") != -1) {
46              return true;
47          }
48          else {
49              return false;
50          }
51      }
52  
53      public String[] getRootChildrenOrder() {
54          return _ROOT_ORDERED_CHILDREN;
55      }
56  
57      public String[] getChildrenOrder(Element parentElement) {
58          String parentName = parentElement.getQName().getName();
59  
60          if (_orderedChildren.containsKey(parentName)){
61              return _orderedChildren.get(parentName);
62          }
63  
64          return new String[0];
65      }
66  
67      public ElementIdentifier[] getElementsIdentifiedByAttribute() {
68          return _ELEMENTS_IDENTIFIED_BY_ATTR;
69      }
70  
71      public ElementIdentifier[] getElementsIdentifiedByChild() {
72          return _ELEMENTS_IDENTIFIED_BY_CHILD;
73      }
74  
75      public String[] getUniqueElements() {
76          return _UNIQUE_ELEMENTS;
77      }
78  
79      public String[] getJoinableElements() {
80          return _JOINABLE_ELEMENTS;
81      }
82  
83      private static final String[] _ROOT_ORDERED_CHILDREN = {
84          "icon", "display-name", "description", "distributable", "context-param",
85          "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
86          "session-config", "mime-mapping", "welcome-file-list", "error-page",
87          "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
88          "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
89      };
90  
91      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
92      };
93  
94      private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
95          new ElementIdentifier("context-param", "param-name"),
96          new ElementIdentifier("filter", "filter-name"),
97          //new ElementIdentifier("filter-mapping", "filter-name"),
98          new ElementIdentifier("servlet", "servlet-name"),
99          //new ElementIdentifier("servlet-mapping", "servlet-name"),
100         new ElementIdentifier("init-param", "param-name"),
101         new ElementIdentifier("taglib", "taglib-uri"),
102         new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
103         new ElementIdentifier("resource-ref", "res-ref-name"),
104         new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
105     };
106 
107     private static final String[] _UNIQUE_ELEMENTS = {
108         "icon", "display-name", "description", "distributable",
109         "session-config", "welcome-file-list", "jsp-config", "login-config"
110     };
111 
112     private static final String[] _JOINABLE_ELEMENTS = {
113         "welcome-file-list", "jsp-config"
114     };
115 
116     private Map<String, String[]> _orderedChildren =
117         new HashMap<String, String[]>();
118 
119 }