KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > extra > spath > SPathTag


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.standard.extra.spath;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 /**
24  * <p>Tag handler that exposes SPath functionality.</p>
25  *
26  * @author Shawn Bayern
27  */

28
29 public class SPathTag extends TagSupport JavaDoc {
30
31     //*********************************************************************
32
// Internal state
33

34     private String JavaDoc select; // tag attribute
35
private String JavaDoc var; // tag attribute
36

37     //*********************************************************************
38
// Construction and initialization
39

40     /**
41      * Constructs a new handler. As with TagSupport, subclasses should
42      * not provide other constructors and are expected to call the
43      * superclass constructor.
44      */

45     public SPathTag() {
46         super();
47         init();
48     }
49
50     // resets local state
51
private void init() {
52     select = var = null;
53     }
54
55
56     //*********************************************************************
57
// Tag logic
58

59     // applies XPath expression from 'select' and exposes a filter as 'var'
60
public int doStartTag() throws JspException JavaDoc {
61       try {
62     SPathFilter s = new SPathFilter(new SPathParser(select).expression());
63     pageContext.setAttribute(var, s);
64     return SKIP_BODY;
65       } catch (ParseException ex) {
66     throw new JspTagException JavaDoc(ex.toString(), ex);
67       }
68     }
69
70     // Releases any resources we may have (or inherit)
71
public void release() {
72         super.release();
73         init();
74     }
75
76
77     //*********************************************************************
78
// Attribute accessors
79

80     public void setSelect(String JavaDoc select) {
81     this.select = select;
82     }
83
84     public void setVar(String JavaDoc var) {
85     this.var = var;
86     }
87 }
88
Popular Tags