KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > taglibs > ApplyGlossaryTag


1 /*
2  * ApplyGlossaryTag is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/taglibs/ApplyGlossaryTag.java,v 1.3.2.1 2006/12/11 16:27:38 fxrobin Exp $
21  */

22
23 package org.cofax.taglibs;
24
25 import javax.servlet.*;
26 import javax.servlet.jsp.*;
27 import javax.servlet.jsp.tagext.*;
28 import java.util.*;
29 import org.cofax.*;
30
31 /**
32  * ApplyGlossaryTag sets a JSP variable from processing a string first against
33  * the outer glossary, and then against all inner rows of the packageTag
34  * request.
35  *
36  * @author Hung Dao
37  * @author Karl Martino
38  * @author Derek Dinh
39  * @created October 01, 2001
40  *
41  *
42  * @param name
43  * example: value="Hello requst:pathPart[0]"
44  * @param id
45  * example: "newString"
46  */

47 public class ApplyGlossaryTag extends TagSupport {
48
49     private String JavaDoc value = "";
50
51     private String JavaDoc id = "";
52
53     JspWriter out;
54
55     /**
56      * Set's the name as key.
57      */

58     public void setValue(String JavaDoc v) {
59         value = v;
60     }
61
62     /**
63      * Get the name use as key.
64      */

65     public String JavaDoc getValue() {
66         return (value);
67     }
68
69     /**
70      * Set's the name of the variable being set.
71      */

72     public void setId(String JavaDoc v) {
73         id = v;
74     }
75
76     /**
77      * Returns the name of the variable that is being set.
78      */

79     public String JavaDoc getId() {
80         return id;
81     }
82
83     /**
84      * Create the variable id based on processing the string, value, against the
85      * outer, then inner, glossaries.
86      */

87     public int doStartTag() throws JspException {
88
89         boolean emptyValue = false;
90         // Process for the outer glossary first.
91
ServletRequest req = pageContext.getRequest();
92         CofaxPage cofaxPage = (CofaxPage) req.getAttribute("cofaxPage");
93
94         String JavaDoc newValue = cofaxPage.applyGlossary(value);
95         if (newValue != null) {
96             pageContext.setAttribute(getId(), newValue);
97         } else {
98             emptyValue = true;
99         }
100
101         // Process for the inner glossary
102
PackageTag parent = (PackageTag) findAncestorWithClass(this, PackageTag.class);
103         out = pageContext.getOut();
104         if (parent != null) {
105             HashMap currentRow = parent.getRowData();
106             if (currentRow != null) {
107                 newValue = CofaxPage.applyGlossaryWithHashMap(value, currentRow);
108                 if (newValue != null) {
109                     pageContext.setAttribute(getId(), newValue);
110                 } else {
111                     emptyValue = true;
112                 }
113             }
114         }// end if
115

116         if (emptyValue) {
117             pageContext.setAttribute(getId(), "");
118         }
119
120         return SKIP_BODY;
121     }
122
123     /**
124      * Ends this Tag run.
125      */

126     public int doEndTag() throws JspException {
127         return EVAL_PAGE;
128     }
129
130     /**
131      * Print content to clients browser.
132      */

133     public void printMessage(String JavaDoc message) throws JspException {
134
135         try {
136             out.print(message);
137         } catch (Exception JavaDoc ex) {
138             throw new JspException("IO problems printMessage() " + ex);
139         }
140         return;
141     }
142
143 } // end ApplyGlossaryTag
144

145
Popular Tags