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.JellyTagException;
19 import org.apache.commons.jelly.MissingAttributeException;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.apache.commons.jelly.xpath.XPathTagSupport;
22 import org.jaxen.JaxenException;
23 import org.jaxen.XPath;
24 import org.xml.sax.SAXException;
25
26 /*** A tag which performs a string XPath expression; similar to <xsl:value-of>
27 * in XSLT
28 *
29 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
30 * @version $Revision: 155420 $
31 */
32 public class ExprTag extends XPathTagSupport {
33
34 /*** The XPath expression to evaluate. */
35 private XPath select;
36
37 public ExprTag() {
38 }
39
40
41
42 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
43 Object xpathContext = getXPathContext();
44
45 if (select == null) {
46 throw new MissingAttributeException( "select" );
47 }
48
49 try {
50 String text = select.stringValueOf(xpathContext);
51 if ( text != null ) {
52 output.write(text);
53 }
54 }
55 catch (SAXException e) {
56 throw new JellyTagException(e);
57 }
58 catch (JaxenException e) {
59 throw new JellyTagException(e);
60 }
61 }
62
63
64
65 /*** Sets the XPath expression to evaluate. */
66 public void setSelect(XPath select) {
67 this.select = select;
68 }
69 }