KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > micronova > jsp > tag > CallTag


1 /*
2
3 Copyright 2003-2007 MicroNova (R)
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or
7 without modification, are permitted provided that the following
8 conditions are met:
9
10     * Redistributions of source code must retain the above copyright
11     notice, this list of conditions and the following disclaimer.
12
13     * Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17     * Neither the name of MicroNova nor the names of its contributors
18     may be used to endorse or promote products derived from this
19     software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32
33 */

34
35
36 package com.micronova.jsp.tag;
37
38 import com.micronova.util.*;
39 import com.micronova.util.servlet.*;
40 import java.util.*;
41 import java.util.regex.*;
42 import javax.servlet.*;
43 import javax.servlet.jsp.*;
44 import javax.servlet.http.*;
45
46 /** dispatching function call. */
47
48 public class CallTag extends MapTag
49 {
50     protected String JavaDoc _path;
51     protected String JavaDoc _contextPath;
52     protected boolean _doesForward;
53
54     public final static String JavaDoc BODYPROPERTY = "parameter";
55     public final static String JavaDoc RETURNPROPERTY = "_return";
56     public final static String JavaDoc VALUEPROPERTY = "value";
57
58     protected void init()
59     {
60         super.init();
61
62         _path = null;
63         _contextPath = null;
64         _bodyProperty = BODYPROPERTY;
65         _doesForward = false;
66     }
67
68     /** converts relative path (not string with a "/") to absolute, if necessary */
69
70     public String JavaDoc getPath(String JavaDoc path, HttpServletRequest request)
71     {
72         if (!path.startsWith("/"))
73         {
74             path = request.getServletPath().replaceFirst("/[^/]*$", "") + "/" + path;
75         }
76
77         return path;
78     }
79
80     public String JavaDoc getContextPath(String JavaDoc contextPath)
81     {
82         if (contextPath != null)
83         {
84             if (!contextPath.startsWith("/"))
85             {
86                 contextPath = "/" + contextPath;
87             }
88         }
89
90         return contextPath;
91     }
92
93     protected Object JavaDoc processValue(Object JavaDoc tagValue) throws Exception JavaDoc
94     {
95         super.processValue(tagValue);
96
97         NestedMap map = _map;
98
99         Map returnMap = map.getSubMap(RETURNPROPERTY);
100         
101         returnMap.put(VALUEPROPERTY, null);
102         
103         HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
104         
105         String JavaDoc path = getPath(_path, request);
106         String JavaDoc contextPath = getContextPath(_contextPath);
107         
108         if (_doesForward)
109         {
110             HttpDispatch.forward(pageContext, path, contextPath, map);
111         }
112         else
113         {
114             tagValue = HttpDispatch.include(pageContext, path, contextPath, map);
115         }
116         
117         Object JavaDoc returnValue = returnMap.get(VALUEPROPERTY);
118         
119         if (!isEmptyString(returnValue))
120         {
121             tagValue = returnValue;
122         }
123         
124         return tagValue;
125     }
126
127     protected void copyFromSource(Object JavaDoc source) throws Exception JavaDoc
128     {
129         super.copyFromSource(source);
130     }
131
132     public void setPath(Object JavaDoc expression) throws Exception JavaDoc
133     {
134         _path = (String JavaDoc)evaluateAttribute("path", expression, String JavaDoc.class);
135     }
136
137     public void setContextPath(Object JavaDoc expression) throws Exception JavaDoc
138     {
139         _contextPath = (String JavaDoc)evaluateAttribute("contextPath", expression, String JavaDoc.class);
140     }
141
142     public void setBody(Object JavaDoc expression) throws Exception JavaDoc
143     {
144         _body = evaluateAttribute("body", expression, Object JavaDoc.class);
145     }
146
147     public void setDoesForward(Object JavaDoc expression) throws Exception JavaDoc
148     {
149         _doesForward = ((Boolean JavaDoc)evaluateAttribute("doesForward", expression, Boolean JavaDoc.class)).booleanValue();
150     }
151 }
152
Popular Tags