001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util.xml.descriptor;
016    
017    import com.liferay.util.xml.ElementIdentifier;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.dom4j.Document;
023    import org.dom4j.Element;
024    
025    /**
026     * @author Jorge Ferrer
027     * @author Brian Wing Shun Chan
028     */
029    public class WebXML24Descriptor extends SimpleXMLDescriptor {
030    
031            public WebXML24Descriptor() {
032                    _orderedChildren.put(
033                            "jsp-config", new String[] {"taglib", "jsp-property-group"});
034            }
035    
036            @Override
037            public boolean canHandleType(String doctype, Document root) {
038                    if (doctype.indexOf("web-app") != -1) {
039                            return true;
040                    }
041                    else {
042                            return false;
043                    }
044            }
045    
046            @Override
047            public String[] getRootChildrenOrder() {
048                    return _ROOT_ORDERED_CHILDREN;
049            }
050    
051            @Override
052            public String[] getChildrenOrder(Element parentElement) {
053                    String parentName = parentElement.getQName().getName();
054    
055                    if (_orderedChildren.containsKey(parentName)) {
056                            return _orderedChildren.get(parentName);
057                    }
058    
059                    return new String[0];
060            }
061    
062            @Override
063            public ElementIdentifier[] getElementsIdentifiedByAttribute() {
064                    return _ELEMENTS_IDENTIFIED_BY_ATTR;
065            }
066    
067            @Override
068            public ElementIdentifier[] getElementsIdentifiedByChild() {
069                    return _ELEMENTS_IDENTIFIED_BY_CHILD;
070            }
071    
072            @Override
073            public String[] getUniqueElements() {
074                    return _UNIQUE_ELEMENTS;
075            }
076    
077            @Override
078            public String[] getJoinableElements() {
079                    return _JOINABLE_ELEMENTS;
080            }
081    
082            private static final String[] _ROOT_ORDERED_CHILDREN = {
083                    "icon", "display-name", "description", "distributable", "context-param",
084                    "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
085                    "session-config", "mime-mapping", "welcome-file-list", "error-page",
086                    "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
087                    "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
088            };
089    
090            private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
091            };
092    
093            private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
094                    new ElementIdentifier("context-param", "param-name"),
095                    new ElementIdentifier("filter", "filter-name"),
096                    //new ElementIdentifier("filter-mapping", "filter-name"),
097                    new ElementIdentifier("servlet", "servlet-name"),
098                    //new ElementIdentifier("servlet-mapping", "servlet-name"),
099                    new ElementIdentifier("init-param", "param-name"),
100                    new ElementIdentifier("taglib", "taglib-uri"),
101                    new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
102                    new ElementIdentifier("resource-ref", "res-ref-name"),
103                    new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
104            };
105    
106            private static final String[] _UNIQUE_ELEMENTS = {
107                    "icon", "display-name", "description", "distributable",
108                    "session-config", "welcome-file-list", "jsp-config", "login-config"
109            };
110    
111            private static final String[] _JOINABLE_ELEMENTS = {
112                    "welcome-file-list", "jsp-config"
113            };
114    
115            private Map<String, String[]> _orderedChildren =
116                    new HashMap<String, String[]>();
117    
118    }