001
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
029 public class WebXML24Descriptor extends SimpleXMLDescriptor {
030
031 public WebXML24Descriptor() {
032 _orderedChildren.put(
033 "servlet",
034 new String[] {
035 "icon", "servlet-name", "display-name", "description",
036 "servlet-class", "jsp-file", "init-param", "load-on-startup",
037 "run-as", "security-role-ref"
038 });
039 _orderedChildren.put(
040 "jsp-config", new String[] {"taglib", "jsp-property-group"});
041 }
042
043 @Override
044 public boolean canHandleType(String doctype, Document root) {
045 if (doctype.indexOf("web-app") != -1) {
046 return true;
047 }
048 else {
049 return false;
050 }
051 }
052
053 @Override
054 public String[] getChildrenOrder(Element parentElement) {
055 String parentName = parentElement.getQName().getName();
056
057 String[] childrenOrder = _orderedChildren.get(parentName);
058
059 if (childrenOrder == null) {
060 childrenOrder = new String[0];
061 }
062
063 return childrenOrder;
064 }
065
066 @Override
067 public ElementIdentifier[] getElementsIdentifiedByAttribute() {
068 return _ELEMENTS_IDENTIFIED_BY_ATTR;
069 }
070
071 @Override
072 public ElementIdentifier[] getElementsIdentifiedByChild() {
073 return _ELEMENTS_IDENTIFIED_BY_CHILD;
074 }
075
076 @Override
077 public String[] getJoinableElements() {
078 return _JOINABLE_ELEMENTS;
079 }
080
081 @Override
082 public String[] getRootChildrenOrder() {
083 return _ROOT_ORDERED_CHILDREN;
084 }
085
086 @Override
087 public String[] getUniqueElements() {
088 return _UNIQUE_ELEMENTS;
089 }
090
091 private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_ATTR = {
092 };
093
094 private static final ElementIdentifier[] _ELEMENTS_IDENTIFIED_BY_CHILD = {
095 new ElementIdentifier("context-param", "param-name"),
096 new ElementIdentifier("filter", "filter-name"),
097
098 new ElementIdentifier("servlet", "servlet-name"),
099
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[] _JOINABLE_ELEMENTS = {
108 "welcome-file-list", "jsp-config"
109 };
110
111 private static final String[] _ROOT_ORDERED_CHILDREN = {
112 "icon", "display-name", "description", "distributable", "context-param",
113 "filter", "filter-mapping", "listener", "servlet", "servlet-mapping",
114 "session-config", "mime-mapping", "welcome-file-list", "error-page",
115 "jsp-config", "resource-env-ref", "resource-ref", "security-constraint",
116 "login-config", "security-role", "env-entry", "ejb-ref", "ejb-local-ref"
117 };
118
119 private static final String[] _UNIQUE_ELEMENTS = {
120 "icon", "display-name", "description", "distributable",
121 "session-config", "welcome-file-list", "jsp-config", "login-config"
122 };
123
124 private Map<String, String[]> _orderedChildren =
125 new HashMap<String, String[]>();
126
127 }