KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > ContextBasedTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html;
8
9
10 import java.net.URISyntaxException JavaDoc;
11
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13 import javax.servlet.http.HttpServletResponse JavaDoc;
14 import javax.servlet.jsp.JspException JavaDoc;
15
16 import com.inversoft.verge.mvc.view.ViewConstants;
17 import com.inversoft.verge.util.url.URLGenerator;
18 import com.inversoft.verge.util.url.config.CategoryConfig;
19
20
21 /**
22  * <p>
23  * This class is the base class for any tags that use or
24  * include the context path of the web application in URLs.
25  * </p>
26  *
27  * @author Brian Pontarelli
28  * @since 2.0
29  * @version 2.0
30  */

31 public abstract class ContextBasedTag extends HtmlBaseTag {
32
33     private Boolean JavaDoc context;
34     private String JavaDoc category;
35
36
37     /**
38      * Constructor for ContextBasedTag.
39      */

40     public ContextBasedTag() {
41         super();
42     }
43
44
45     /**
46      * Retrieves the tags context attribute which controls whether or not the
47      * generated path contains the context path or not
48      *
49      * @return Returns the tags context attribute
50      */

51     public Boolean JavaDoc getContext() {
52         return context;
53     }
54
55     /**
56      * Populates the tags context attribute which controls whether or not the
57      * generated path contains the context path or not
58      *
59      * @param context The value of the tags context attribute
60      */

61     public void setContext(Boolean JavaDoc context) {
62         this.context = context;
63     }
64
65     /**
66      * Retrieves the tags category attribute
67      *
68      * @return Returns the tags category attribute
69      */

70     public String JavaDoc getCategory() {
71         return category;
72     }
73
74     /**
75      * Populates the tags category attribute
76      *
77      * @param category The value of the tags category attribute
78      */

79     public void setCategory(String JavaDoc category) {
80         this.category = category;
81     }
82
83
84     /**
85      * Optionally appends the context path
86      */

87     protected void appendContextPlusURL(StringBuffer JavaDoc buf, String JavaDoc url)
88     throws JspException JavaDoc {
89         boolean contextBool = (context == null) ? true : context.booleanValue();
90         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
91         try {
92             CategoryConfig cc = URLGenerator.getCategory(request, category,
93                 ViewConstants.URL_CATEGORY_NAME);
94             URLGenerator.generateURL(buf, cc, url, contextBool, request,
95                 (HttpServletResponse JavaDoc) pageContext.getResponse());
96         } catch (URISyntaxException JavaDoc usi) {
97             throw new JspException JavaDoc(usi);
98         }
99     }
100 }
Popular Tags