KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ValueTag 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/ValueTag.java,v 1.4.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  * ValueTag sets a JSP variable from the PackageTag or CofaxPage glossary.
33  *
34  * @author Hung Dao
35  * @author Karl Martino
36  * @author Derek Dinh
37  * @created October 01, 2001
38  *
39  *
40  * @param name
41  * example: name="getSection:HEADLINE"
42  * @param var
43  * example: "Today Kids"
44  */

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

56     public void setName(String JavaDoc v) {
57         name = v;
58     }
59
60     /**
61      * Get the name use as key.
62      */

63     public String JavaDoc getName() {
64         return (name);
65     }
66
67     /**
68      * Set's the name of the variable being set.
69      */

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

77     public String JavaDoc getId() {
78         return id;
79     }
80
81     /**
82      * Print the "Value" base on the "Name" in packageTag glossary.
83      */

84     public int doStartTag() throws JspException {
85
86         PackageTag parent = (PackageTag) findAncestorWithClass(this, PackageTag.class);
87         out = pageContext.getOut();
88
89         while (parent != null) {
90
91             if (parent.fieldExists(name)) {
92
93                 pageContext.setAttribute(getId(), parent.getField(name));
94                 return (SKIP_BODY);
95             }
96
97             parent = (PackageTag) findAncestorWithClass(parent, PackageTag.class);
98         }// end while
99

100         ServletRequest req = pageContext.getRequest();
101         CofaxPage cofaxPage = (CofaxPage) req.getAttribute("cofaxPage");
102         HashMap glossary = cofaxPage.getGlossary().getKeyValues();
103
104         if (glossary.containsKey(name)) {
105
106             pageContext.setAttribute(getId(), glossary.get(name));
107
108         } else {
109             pageContext.setAttribute(getId(), "");
110         }
111
112         return SKIP_BODY;
113     }
114
115     /**
116      * Ends this Tag run.
117      */

118     public int doEndTag() throws JspException {
119         return EVAL_PAGE;
120     }
121
122     /**
123      * Print content to clients browser.
124      */

125     public void printMessage(String JavaDoc message) throws JspException {
126
127         try {
128             out.print(message);
129         } catch (Exception JavaDoc ex) {
130             throw new JspException("IO problems printMessage() " + ex);
131         }
132         return;
133     }
134
135 } // end ValueTag
136

137
Popular Tags