KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > xtags > xpath > CopyOfTag


1 /*
2  * Copyright 1999,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
17 package org.apache.taglibs.xtags.xpath;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 import javax.servlet.ServletContext JavaDoc;
24 import javax.servlet.jsp.JspException JavaDoc;
25 import javax.servlet.jsp.JspWriter JavaDoc;
26 import javax.servlet.jsp.PageContext JavaDoc;
27 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
28
29 import org.dom4j.DocumentException;
30 import org.dom4j.Node;
31 import org.dom4j.XPath;
32 import org.dom4j.DocumentHelper;
33 import org.dom4j.io.OutputFormat;
34 import org.dom4j.io.XMLWriter;
35
36 /** A tag which performs a copy-of operation like the XSLT tag
37   *
38   * @author James Strachan
39   */

40 public class CopyOfTag extends AbstractTag {
41
42     /** Holds value of property xpath. */
43     private XPath xpath;
44     
45
46     public CopyOfTag() {
47     }
48
49     // Tag interface
50
//-------------------------------------------------------------------------
51
public int doStartTag() throws JspException JavaDoc {
52         return EVAL_BODY_INCLUDE;
53     }
54     
55     public int doEndTag() throws JspException JavaDoc {
56         Object JavaDoc input = getInputNodes();
57         if ( xpath != null ) {
58             input = xpath.selectNodes( input );
59         }
60         if ( input != null ) {
61             try {
62                 XMLWriter writer = TagHelper.getXMLWriter( pageContext, this );
63                 writer.write( input );
64             }
65             catch (IOException JavaDoc e) {
66                 handleException(e);
67             }
68         }
69         return EVAL_PAGE;
70     }
71
72     public void release() {
73         super.release();
74         xpath = null;
75     }
76
77     // Properties
78
//-------------------------------------------------------------------------
79

80     /** Setter for property select.
81      * @param select New value of property select.
82      */

83     public void setSelect(String JavaDoc select) {
84         if ( select != null && ! select.equals( "." ) ) {
85             xpath = createXPath( select );
86         }
87         else {
88             xpath = null;
89         }
90     }
91 }
92
Popular Tags