1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.webapp;
15
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.eclipse.jetty.util.resource.Resource;
22 import org.eclipse.jetty.xml.XmlParser;
23
24
25
26
27
28
29
30 public class FragmentDescriptor extends WebDescriptor
31 {
32 public static final String NAMELESS = "@@-NAMELESS-@@";
33 protected static int _counter = 0;
34
35 public enum OtherType {None, Before, After};
36 protected OtherType _otherType = OtherType.None;
37
38
39 protected List<String> _befores = new ArrayList<String>();
40 protected List<String> _afters = new ArrayList<String>();
41 protected String _name;
42
43
44 public FragmentDescriptor (Resource xml)
45 throws Exception
46 {
47 super (xml);
48 }
49
50 public String getName ()
51 {
52 return _name;
53 }
54
55 @Override
56 public void parse ()
57 throws Exception
58 {
59 super.parse();
60 processName();
61 }
62
63 public void processName ()
64 {
65 XmlParser.Node root = getRoot();
66 XmlParser.Node nameNode = root.get("name");
67 _name = NAMELESS+(_counter++);
68 if (nameNode != null)
69 {
70 String tmp = nameNode.toString(false,true);
71 if (tmp!=null && tmp.length()>0)
72 _name = tmp;
73 }
74 }
75 @Override
76 public void processOrdering ()
77 {
78
79 XmlParser.Node root = getRoot();
80
81 XmlParser.Node ordering = root.get("ordering");
82 if (ordering == null)
83 return;
84
85 _isOrdered = true;
86
87 processBefores(ordering);
88 processAfters(ordering);
89 }
90
91
92 public void processBefores (XmlParser.Node ordering)
93 {
94
95 XmlParser.Node before = ordering.get("before");
96 if (before == null)
97 return;
98
99 Iterator iter = before.iterator();
100 XmlParser.Node node = null;
101 while (iter.hasNext())
102 {
103 Object o = iter.next();
104 if (!(o instanceof XmlParser.Node)) continue;
105 node = (XmlParser.Node) o;
106 if (node.getTag().equalsIgnoreCase("others"))
107 {
108 if (_otherType != OtherType.None)
109 throw new IllegalStateException("Duplicate <other> clause detected in "+_xml.getURI());
110
111 _otherType = OtherType.Before;
112 }
113 else if (node.getTag().equalsIgnoreCase("name"))
114 _befores.add(node.toString(false,true));
115 }
116 }
117
118 public void processAfters (XmlParser.Node ordering)
119 {
120
121 XmlParser.Node after = ordering.get("after");
122 if (after == null)
123 return;
124
125 Iterator iter = after.iterator();
126 XmlParser.Node node = null;
127 while (iter.hasNext())
128 {
129 Object o = iter.next();
130 if (!(o instanceof XmlParser.Node)) continue;
131 node = (XmlParser.Node) o;
132 if (node.getTag().equalsIgnoreCase("others"))
133 {
134 if (_otherType != OtherType.After)
135 throw new IllegalStateException("Duplicate <other> clause detected in "+_xml.getURI());
136
137 _otherType = OtherType.After;
138
139 }
140 else if (node.getTag().equalsIgnoreCase("name"))
141 _afters.add(node.toString(false,true));
142 }
143 }
144
145 public List<String> getBefores()
146 {
147 return Collections.unmodifiableList(_befores);
148 }
149
150 public List<String> getAfters()
151 {
152 return Collections.unmodifiableList(_afters);
153 }
154
155 public OtherType getOtherType ()
156 {
157 return _otherType;
158 }
159
160 public List<String> getOrdering()
161 {
162 return null;
163 }
164 }