|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| package org.dom4j.rule; |
|
11 |
| |
|
12 |
| import java.util.List; |
|
13 |
| |
|
14 |
| import org.dom4j.Document; |
|
15 |
| import org.dom4j.Element; |
|
16 |
| import org.dom4j.Node; |
|
17 |
| import org.dom4j.XPath; |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| public class Stylesheet { |
|
28 |
| |
|
29 |
| private RuleManager ruleManager = new RuleManager(); |
|
30 |
| |
|
31 |
| |
|
32 |
| private String modeName; |
|
33 |
| |
|
34 |
| |
|
35 |
4
| public Stylesheet() {
|
|
36 |
| } |
|
37 |
| |
|
38 |
26
| public void addRule( Rule rule ) {
|
|
39 |
26
| ruleManager.addRule( rule );
|
|
40 |
| } |
|
41 |
| |
|
42 |
0
| public void removeRule( Rule rule ) {
|
|
43 |
0
| ruleManager.removeRule( rule );
|
|
44 |
| } |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
0
| public void run(Object input) throws Exception {
|
|
50 |
0
| run(input, this.modeName);
|
|
51 |
| } |
|
52 |
| |
|
53 |
0
| public void run(Object input, String mode) throws Exception {
|
|
54 |
0
| if (input instanceof Node) {
|
|
55 |
0
| run ((Node) input, mode);
|
|
56 |
| } |
|
57 |
0
| else if (input instanceof List) {
|
|
58 |
0
| run((List) input, mode);
|
|
59 |
| } |
|
60 |
| } |
|
61 |
| |
|
62 |
0
| public void run(List list) throws Exception {
|
|
63 |
0
| run(list, this.modeName);
|
|
64 |
| } |
|
65 |
| |
|
66 |
0
| public void run(List list, String mode) throws Exception {
|
|
67 |
0
| for (int i = 0, size = list.size(); i < size; i++) {
|
|
68 |
0
| Object object = list.get(i);
|
|
69 |
0
| if (object instanceof Node) {
|
|
70 |
0
| run((Node) object, mode);
|
|
71 |
| } |
|
72 |
| } |
|
73 |
| } |
|
74 |
| |
|
75 |
4
| public void run(Node node) throws Exception {
|
|
76 |
4
| run(node, this.modeName);
|
|
77 |
| } |
|
78 |
| |
|
79 |
4
| public void run(Node node, String mode) throws Exception {
|
|
80 |
4
| Mode mod = ruleManager.getMode(mode);
|
|
81 |
4
| mod.fireRule(node);
|
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
0
| public void applyTemplates(Object input, XPath xpath) throws Exception {
|
|
86 |
0
| applyTemplates(input, xpath, this.modeName);
|
|
87 |
| } |
|
88 |
| |
|
89 |
0
| public void applyTemplates(Object input, XPath xpath, String mode) throws Exception {
|
|
90 |
0
| List list = xpath.selectNodes(input);
|
|
91 |
0
| list.remove(input);
|
|
92 |
0
| applyTemplates(list, mode);
|
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| } |
|
100 |
| |
|
101 |
0
| public void applyTemplates(Object input, org.jaxen.XPath xpath) throws Exception {
|
|
102 |
0
| applyTemplates(input, xpath, this.modeName);
|
|
103 |
| } |
|
104 |
| |
|
105 |
0
| public void applyTemplates(Object input, org.jaxen.XPath xpath, String mode) throws Exception {
|
|
106 |
0
| List list = xpath.selectNodes(input);
|
|
107 |
0
| applyTemplates(list, mode);
|
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| } |
|
115 |
| |
|
116 |
28
| public void applyTemplates(Object input) throws Exception {
|
|
117 |
28
| applyTemplates(input, this.modeName);
|
|
118 |
| } |
|
119 |
| |
|
120 |
28
| public void applyTemplates(Object input, String mode) throws Exception {
|
|
121 |
| |
|
122 |
28
| Mode mod = ruleManager.getMode(mode);
|
|
123 |
| |
|
124 |
28
| if ( input instanceof Element ) {
|
|
125 |
20
| mod.applyTemplates( (Element) input );
|
|
126 |
| } |
|
127 |
8
| else if ( input instanceof Document ) {
|
|
128 |
4
| mod.applyTemplates( (Document) input );
|
|
129 |
| } |
|
130 |
4
| else if ( input instanceof List ) {
|
|
131 |
0
| List list = (List) input;
|
|
132 |
0
| for ( int i = 0, size = list.size(); i < size; i++ ) {
|
|
133 |
0
| Object object = list.get(i);
|
|
134 |
0
| if ( object != input ) {
|
|
135 |
0
| if ( object instanceof Element ) {
|
|
136 |
0
| mod.applyTemplates( (Element) object );
|
|
137 |
| } |
|
138 |
0
| else if ( object instanceof Document ) {
|
|
139 |
0
| mod.applyTemplates( (Document) object );
|
|
140 |
| } |
|
141 |
| } |
|
142 |
| } |
|
143 |
| } |
|
144 |
| } |
|
145 |
| |
|
146 |
0
| public void clear() {
|
|
147 |
0
| ruleManager.clear();
|
|
148 |
| } |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
0
| public String getModeName() {
|
|
157 |
0
| return modeName;
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
0
| public void setModeName(String modeName) {
|
|
163 |
0
| this.modeName = modeName;
|
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
0
| public Action getValueOfAction() {
|
|
170 |
0
| return ruleManager.getValueOfAction();
|
|
171 |
| } |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
4
| public void setValueOfAction(Action valueOfAction) {
|
|
177 |
4
| ruleManager.setValueOfAction( valueOfAction );
|
|
178 |
| } |
|
179 |
| |
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
| |
|
228 |
| |