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 /*** Describes the Taglib. This class could be generated by XDoclet
32 *
33 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
34 * @version $Revision: 219726 $
35 */
36 public class XMLTagLibrary extends TagLibrary {
37
38 /*** The Log to which logging calls will be made. */
39 private Log log = LogFactory.getLog(XMLTagLibrary.class);
40
41 private JexlExpressionFactory jexlFactory;
42
43 public XMLTagLibrary() {
44 registerTag("out", ExprTag.class);
45 registerTag("if", IfTag.class);
46 registerTag("forEach", ForEachTag.class);
47 registerTag("parse", ParseTag.class);
48 registerTag("set", SetTag.class);
49 registerTag("transform", TransformTag.class);
50 registerTag("param", ParamTag.class);
51
52
53 registerTag("expr", ExprTag.class);
54 registerTag("element", ElementTag.class);
55 registerTag("attribute", AttributeTag.class);
56 registerTag("replaceNamespace", ReplaceNamespaceTag.class);
57 registerTag("copy", CopyTag.class);
58 registerTag("copyOf", CopyOfTag.class);
59 registerTag("comment", CommentTag.class);
60 registerTag("doctype", DoctypeTag.class);
61 registerTag("sort", SortTag.class);
62
63 this.jexlFactory = new JexlExpressionFactory();
64 }
65
66 public Expression createExpression(
67 ExpressionFactory factory,
68 TagScript tagScript,
69 String attributeName,
70 String attributeValue) throws JellyException {
71
72
73
74 if (attributeName.equals("select") || attributeName.equals("sort")) {
75 if ( log.isDebugEnabled() ) {
76 log.debug( "Parsing XPath expression: " + attributeValue );
77 }
78
79 Expression xpathExpr = createXPathTextExpression( attributeValue );
80
81 return new XPathExpression(attributeValue,
82 xpathExpr,
83 tagScript);
84 }
85
86
87 return super.createExpression(factory, tagScript, attributeName, attributeValue);
88 }
89
90 protected Expression createXPathTextExpression(String exprText) throws JellyException {
91 return CompositeExpression.parse( exprText,
92 this.jexlFactory );
93 }
94 }