001    /**
002     * Copyright (c) 2000-2011 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            @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                    String[] childrenOrder = _orderedChildren.get(parentName);
056    
057                    if (childrenOrder == null) {
058                            childrenOrder = new String[0];
059                    }
060    
061                    return childrenOrder;
062            }
063    
064            @Override
065            public ElementIdentifier[] getElementsIdentifiedByAttribute() {
066                    return _ELEMENTS_IDENTIFIED_BY_ATTR;
067            }
068    
069            @Override
070            public ElementIdentifier[] getElementsIdentifiedByChild() {
071                    return _ELEMENTS_IDENTIFIED_BY_CHILD;
072            }
073    
074            @Override
075            public String[] getUniqueElements() {
076                    return _UNIQUE_ELEMENTS;
077            }
078    
079            @Override
080            public String[] getJoinableElements() {
081                    return _JOINABLE_ELEMENTS;
082            }
083    
084            private static final String[] _ROOT_ORDERED_CHILDREN = {
085                    "icon", "display-name", "description", "distributable", "context-param",
086                    "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
087                    "session-config", "mime-mapping", "welcome-file-list", "error-page",
088                    "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
089                    "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
090            };
091    
092            private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
093            };
094    
095            private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
096                    new ElementIdentifier("context-param", "param-name"),
097                    new ElementIdentifier("filter", "filter-name"),
098                    //new ElementIdentifier("filter-mapping", "filter-name"),
099                    new ElementIdentifier("servlet", "servlet-name"),
100                    //new ElementIdentifier("servlet-mapping", "servlet-name"),
101                    new ElementIdentifier("init-param", "param-name"),
102                    new ElementIdentifier("taglib", "taglib-uri"),
103                    new ElementIdentifier("resource-env-ref", "res-env-ref-name"),
104                    new ElementIdentifier("resource-ref", "res-ref-name"),
105                    new ElementIdentifier("ejb-local-ref", "ejb-ref-name")
106            };
107    
108            private static final String[] _UNIQUE_ELEMENTS = {
109                    "icon", "display-name", "description", "distributable",
110                    "session-config", "welcome-file-list", "jsp-config", "login-config"
111            };
112    
113            private static final String[] _JOINABLE_ELEMENTS = {
114                    "welcome-file-list", "jsp-config"
115            };
116    
117            private Map<String, String[]> _orderedChildren =
118                    new HashMap<String, String[]>();
119    
120    }