KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23
24 import org.dom4j.Node;
25 import org.dom4j.XPath;
26
27 /** The remove tag removes nodes from the current document which matches
28   * the given XPath expression.
29   *
30   * @author James Strachan
31   */

32 public class RemoveTag extends AbstractTag {
33     
34     /** Holds the XPath selection instance. */
35     private XPath xpath;
36     
37     public RemoveTag() {
38     }
39
40     
41     // BodyTag interface
42
//-------------------------------------------------------------------------
43
public int doStartTag() throws JspException JavaDoc {
44         if ( xpath != null ) {
45             List JavaDoc list = xpath.selectNodes( getInputNodes() );
46             if ( list != null ) {
47                 for ( Iterator JavaDoc iter = list.iterator(); iter.hasNext(); ) {
48                     Object JavaDoc value = iter.next();
49                     if ( value instanceof Node ) {
50                         Node node = (Node) value;
51                         node.detach();
52                     }
53                 }
54             }
55         }
56         return SKIP_BODY;
57     }
58
59     public void release() {
60         super.release();
61         xpath = null;
62     }
63
64     
65     // Properties
66
//-------------------------------------------------------------------------
67

68     /** Sets the select XPath expression
69       */

70     public void setSelect(String JavaDoc select) {
71         this.xpath = createXPath( select );
72     }
73
74     /** Sets the XPath selection expression
75       */

76     public void setSelectXPath(XPath xpath) {
77         this.xpath = xpath;
78     }
79     
80 }
81
Popular Tags