KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * PrintTag 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/PrintTag.java,v 1.4.2.1 2006/12/11 16:27:39 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  * Used to output value from PackageTag or CofaxPage Glossary
33  *
34  * @param name
35  * example: name="getSection:HEADLINE"
36  */

37 public class PrintTag extends TagSupport {
38
39     private String JavaDoc name = "";
40
41     JspWriter out;
42
43     /**
44      * Set's the name as key.
45      */

46     public void setName(String JavaDoc v) {
47         name = v;
48     }
49
50     /**
51      * Get the name use as key.
52      */

53     public String JavaDoc getName() {
54         return (name);
55     }
56
57     /**
58      * Print the "Value" base on the "Name" in packageTag glossary.
59      */

60     public int doStartTag() throws JspException {
61
62         PackageTag parent = (PackageTag) findAncestorWithClass(this, PackageTag.class);
63         out = pageContext.getOut();
64
65         while (parent != null) {
66
67             if (parent.fieldExists(name)) {
68                 printMessage(parent.getField(name));
69
70                 return (SKIP_BODY);
71             }
72
73             parent = (PackageTag) findAncestorWithClass(parent, PackageTag.class);
74         }// end while
75

76         ServletRequest req = pageContext.getRequest();
77         CofaxPage cofaxPage = (CofaxPage) req.getAttribute("cofaxPage");
78
79         HashMap glossary = cofaxPage.getGlossary().getKeyValues();
80
81         if (glossary.containsKey(name)) {
82
83             printMessage(glossary.get(name).toString());
84
85         } else {
86
87             printMessage("");
88         }
89
90         return SKIP_BODY;
91     }
92
93     /**
94      * Ends this Tag run.
95      */

96     public int doEndTag() throws JspException {
97         return EVAL_PAGE;
98     }
99
100     /**
101      * Print content to clients browser.
102      */

103     public void printMessage(String JavaDoc message) throws JspException {
104         try {
105             out.print(message);
106         } catch (Exception JavaDoc ex) {
107             throw new JspException("IO problems printMessage() " + ex);
108         }
109         return;
110     }
111
112 } // end PrintTag
113

114
Popular Tags