001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            public boolean canHandleType(String doctype, Document root) {
037                    if (doctype.indexOf("web-app") != -1) {
038                            return true;
039                    }
040                    else {
041                            return false;
042                    }
043            }
044    
045            public String[] getRootChildrenOrder() {
046                    return _ROOT_ORDERED_CHILDREN;
047            }
048    
049            public String[] getChildrenOrder(Element parentElement) {
050                    String parentName = parentElement.getQName().getName();
051    
052                    if (_orderedChildren.containsKey(parentName)) {
053                            return _orderedChildren.get(parentName);
054                    }
055    
056                    return new String[0];
057            }
058    
059            public ElementIdentifier[] getElementsIdentifiedByAttribute() {
060                    return _ELEMENTS_IDENTIFIED_BY_ATTR;
061            }
062    
063            public ElementIdentifier[] getElementsIdentifiedByChild() {
064                    return _ELEMENTS_IDENTIFIED_BY_CHILD;
065            }
066    
067            public String[] getUniqueElements() {
068                    return _UNIQUE_ELEMENTS;
069            }
070    
071            public String[] getJoinableElements() {
072                    return _JOINABLE_ELEMENTS;
073            }
074    
075            private static final String[] _ROOT_ORDERED_CHILDREN = {
076                    "icon", "display-name", "description", "distributable", "context-param",
077                    "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
078                    "session-config", "mime-mapping", "welcome-file-list", "error-page",
079                    "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
080                    "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
081            };
082    
083            private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
084            };
085    
086            private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
087                    new ElementIdentifier("context-param", "param-name"),
088                    new ElementIdentifier("filter", "filter-name"),
089                    //new ElementIdentifier("filter-mapping", "filter-name"),
090                    new ElementIdentifier("servlet", "servlet-name"),
091                    //new ElementIdentifier("servlet-mapping", "servlet-name"),
092                    new ElementIdentifier("init-param", "param-name"),
093                    new ElementIdentifier("taglib", "taglib-uri"),
094                    new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
095                    new ElementIdentifier("resource-ref", "res-ref-name"),
096                    new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
097            };
098    
099            private static final String[] _UNIQUE_ELEMENTS = {
100                    "icon", "display-name", "description", "distributable",
101                    "session-config", "welcome-file-list", "jsp-config", "login-config"
102            };
103    
104            private static final String[] _JOINABLE_ELEMENTS = {
105                    "welcome-file-list", "jsp-config"
106            };
107    
108            private Map<String, String[]> _orderedChildren =
109                    new HashMap<String, String[]>();
110    
111    }