1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jsl;
17
18 import org.apache.commons.jelly.JellyException;
19 import org.apache.commons.jelly.expression.Expression;
20 import org.apache.commons.jelly.expression.ExpressionFactory;
21 import org.apache.commons.jelly.impl.TagScript;
22 import org.apache.commons.jelly.tags.xml.ExprTag;
23 import org.apache.commons.jelly.tags.xml.XMLTagLibrary;
24 import org.apache.commons.jelly.expression.xpath.XPathExpression;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.dom4j.DocumentHelper;
28 import org.dom4j.rule.Pattern;
29
30 /*** Describes the Taglib. This class could be generated by XDoclet
31 *
32 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
33 * @version $Revision: 155420 $
34 */
35 public class JSLTagLibrary extends XMLTagLibrary {
36
37 /*** The Log to which logging calls will be made. */
38 private Log log = LogFactory.getLog(JSLTagLibrary.class);
39
40 public JSLTagLibrary() {
41 registerTag("stylesheet", StylesheetTag.class);
42 registerTag("style", StyleTag.class);
43 registerTag("template", TemplateTag.class);
44 registerTag("applyTemplates", ApplyTemplatesTag.class);
45 registerTag("valueOf", ExprTag.class);
46 }
47
48 public Expression createExpression(
49 ExpressionFactory factory,
50 TagScript tagScript,
51 String attributeName,
52 String attributeValue) throws JellyException {
53
54
55
56 if (attributeName.equals("select")) {
57 if ( log.isDebugEnabled() ) {
58 log.debug( "Parsing XPath expression: " + attributeValue );
59 }
60
61 Expression xpathExpr = createXPathTextExpression( attributeValue );
62
63 return new XPathExpression(attributeValue, xpathExpr, tagScript);
64 }
65
66 if (attributeName.equals("match")) {
67 if ( log.isDebugEnabled() ) {
68 log.debug( "Parsing XPath pattern: " + attributeValue );
69 }
70
71 try {
72 Pattern pattern = DocumentHelper.createPattern( attributeValue );
73 return new XPathPatternExpression(attributeValue, pattern);
74 }
75 catch (Exception e) {
76 throw new JellyException( "Could not parse XPath expression: \"" + attributeValue + "\" reason: " + e, e );
77 }
78 }
79
80
81 return super.createExpression(factory, tagScript, attributeName, attributeValue);
82 }
83
84
85 }