%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.xml.ExprTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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: 1.5 $ |
|
31 | */ |
|
32 | public class ExprTag extends XPathTagSupport { |
|
33 | ||
34 | /** The XPath expression to evaluate. */ |
|
35 | private XPath select; |
|
36 | ||
37 | 11 | public ExprTag() { |
38 | 11 | } |
39 | ||
40 | // Tag interface |
|
41 | //------------------------------------------------------------------------- |
|
42 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
43 | 11 | Object xpathContext = getXPathContext(); |
44 | ||
45 | 11 | if (select == null) { |
46 | 0 | throw new MissingAttributeException( "select" ); |
47 | } |
|
48 | ||
49 | try { |
|
50 | 11 | String text = select.stringValueOf(xpathContext); |
51 | 11 | if ( text != null ) { |
52 | 11 | output.write(text); |
53 | } |
|
54 | 11 | } |
55 | catch (SAXException e) { |
|
56 | 0 | throw new JellyTagException(e); |
57 | } |
|
58 | catch (JaxenException e) { |
|
59 | 0 | throw new JellyTagException(e); |
60 | } |
|
61 | 11 | } |
62 | ||
63 | // Properties |
|
64 | //------------------------------------------------------------------------- |
|
65 | /** Sets the XPath expression to evaluate. */ |
|
66 | public void setSelect(XPath select) { |
|
67 | 11 | this.select = select; |
68 | 11 | } |
69 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |