KickJava   Java API By Example, From Geeks To Geeks.

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


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.Node;
30 import org.dom4j.XPath;
31 import org.dom4j.DocumentHelper;
32 import org.dom4j.rule.Action;
33 import org.dom4j.rule.Pattern;
34 import org.dom4j.rule.Rule;
35 import org.dom4j.rule.RuleManager;
36 import org.dom4j.rule.pattern.DefaultPattern;
37
38 /** An Action which includes a piece of JSP
39   *
40   * @author James Strachan
41   */

42 public class JspAction implements Action {
43
44     /** Holds value of property jsp. */
45     private String JavaDoc jsp;
46     
47     /** Holds value of property pageContext. */
48     private PageContext JavaDoc pageContext;
49     
50
51     public JspAction() {
52     }
53
54     public JspAction(PageContext JavaDoc pageContext, String JavaDoc jsp) {
55         this.pageContext = pageContext;
56         this.jsp = jsp;
57     }
58
59     
60     /** Getter for property jsp.
61      * @return Value of property jsp.
62      */

63     public String JavaDoc getJsp() {
64         return jsp;
65     }
66     
67     /** Setter for property jsp.
68      * @param jsp New value of property jsp.
69      */

70     public void setJsp(String JavaDoc jsp) {
71         this.jsp = jsp;
72     }
73
74     /** Getter for property pageContext.
75      * @return Value of property pageContext.
76      */

77     public PageContext JavaDoc getPageContext() {
78         return pageContext;
79     }
80     
81     /** Setter for property pageContext.
82      * @param pageContext New value of property pageContext.
83      */

84     public void setPageContext(PageContext JavaDoc pageContext) {
85         this.pageContext = pageContext;
86     }
87     
88     
89     
90     // Action interface
91
//-------------------------------------------------------------------------
92
public void run( Node node ) throws Exception JavaDoc {
93         if ( pageContext == null ) {
94             throw new JspException JavaDoc( "No PageContext. Cannot process JSP: " + jsp );
95         }
96         else
97         if ( jsp == null ) {
98             throw new JspException JavaDoc( "No JSP! Cannot execute Action" );
99         }
100         else {
101             Object JavaDoc oldContext = TagHelper.getInputNodes( pageContext );
102             TagHelper.setInputNodes( pageContext, node );
103             
104             pageContext.include( jsp );
105             pageContext.getOut().flush();
106             
107             TagHelper.setInputNodes( pageContext, oldContext );
108         }
109     }
110 }
111
Popular Tags