1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.commons.jelly.tags.xml; |
17 |
|
|
18 |
|
import org.apache.commons.jelly.JellyException; |
19 |
|
import org.apache.commons.jelly.TagLibrary; |
20 |
|
import org.apache.commons.jelly.expression.Expression; |
21 |
|
import org.apache.commons.jelly.expression.ExpressionFactory; |
22 |
|
import org.apache.commons.jelly.expression.CompositeExpression; |
23 |
|
import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory; |
24 |
|
import org.apache.commons.jelly.expression.xpath.XPathExpression; |
25 |
|
import org.apache.commons.jelly.impl.TagScript; |
26 |
|
|
27 |
|
import org.apache.commons.logging.Log; |
28 |
|
import org.apache.commons.logging.LogFactory; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
60 |
public class XMLTagLibrary extends TagLibrary { |
37 |
|
|
38 |
|
|
39 |
16 |
private Log log = LogFactory.getLog(XMLTagLibrary.class); |
40 |
|
|
41 |
|
private JexlExpressionFactory jexlFactory; |
42 |
|
|
43 |
16 |
public XMLTagLibrary() { |
44 |
16 |
registerTag("out", ExprTag.class); |
45 |
16 |
registerTag("if", IfTag.class); |
46 |
16 |
registerTag("forEach", ForEachTag.class); |
47 |
16 |
registerTag("parse", ParseTag.class); |
48 |
16 |
registerTag("set", SetTag.class); |
49 |
16 |
registerTag("transform", TransformTag.class); |
50 |
16 |
registerTag("param", ParamTag.class); |
51 |
|
|
52 |
|
|
53 |
16 |
registerTag("expr", ExprTag.class); |
54 |
16 |
registerTag("element", ElementTag.class); |
55 |
16 |
registerTag("attribute", AttributeTag.class); |
56 |
16 |
registerTag("copy", CopyTag.class); |
57 |
16 |
registerTag("copyOf", CopyOfTag.class); |
58 |
16 |
registerTag("comment", CommentTag.class); |
59 |
16 |
registerTag("doctype", DoctypeTag.class); |
60 |
16 |
registerTag("sort", SortTag.class); |
61 |
|
|
62 |
16 |
this.jexlFactory = new JexlExpressionFactory(); |
63 |
16 |
} |
64 |
|
|
65 |
|
public Expression createExpression( |
66 |
|
ExpressionFactory factory, |
67 |
|
TagScript tagScript, |
68 |
|
String attributeName, |
69 |
|
String attributeValue) throws JellyException { |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
145 |
if (attributeName.equals("select") || attributeName.equals("sort")) { |
74 |
47 |
if ( log.isDebugEnabled() ) { |
75 |
0 |
log.debug( "Parsing XPath expression: " + attributeValue ); |
76 |
|
} |
77 |
|
|
78 |
47 |
Expression xpathExpr = createXPathTextExpression( attributeValue ); |
79 |
|
|
80 |
47 |
return new XPathExpression(attributeValue, |
81 |
|
xpathExpr, |
82 |
|
tagScript); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
98 |
return super.createExpression(factory, tagScript, attributeName, attributeValue); |
87 |
|
} |
88 |
|
|
89 |
|
protected Expression createXPathTextExpression(String exprText) throws JellyException { |
90 |
47 |
return CompositeExpression.parse( exprText, |
91 |
|
this.jexlFactory ); |
92 |
|
} |
93 |
|
} |