KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * PrintIfTag 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/PrintIfTag.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  * Used to check if output value exists from PackageTag or CofaxPage Glossaries.
33  * If no output, then it returns SKIP_BODY otherwise it returns the value found.
34  *
35  * @param name
36  * example: name="getSection:HEADLINE"
37  */

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

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

54     public String JavaDoc getName() {
55         return (name);
56     }
57
58     /**
59      * Set's the name as key.
60      */

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

68     public String JavaDoc getValue() {
69         return (value);
70     }
71
72     /**
73      * Check the "Value" exist or not base on the "Name" in packageTag glossary.
74      */

75     public int doStartTag() throws JspException {
76
77         PackageTag parent = (PackageTag) findAncestorWithClass(this, PackageTag.class);
78
79         while (parent != null) {
80             if (parent.fieldExists(name)) {
81
82                 if (parent.getField(name).trim().length() > 0) {
83                     if ((value == null) || (value.equals(""))) {
84                         return (EVAL_BODY_INCLUDE);
85                     } else if (parent.getField(name).equals(value)) {
86                         return (EVAL_BODY_INCLUDE);
87                     }
88                 }
89             }
90             parent = (PackageTag) findAncestorWithClass(parent, PackageTag.class);
91         }
92
93         ServletRequest req = pageContext.getRequest();
94         CofaxPage cofaxPage = (CofaxPage) req.getAttribute("cofaxPage");
95
96         HashMap glossary = cofaxPage.getGlossary().getKeyValues();
97
98         if (glossary.containsKey(name)) {
99             if (glossary.get(name).toString().trim().length() > 0) {
100                 if ((value == null) || (value.equals(""))) {
101                     return (EVAL_BODY_INCLUDE);
102                 } else if (glossary.get(name).toString().equals(value)) {
103                     return (EVAL_BODY_INCLUDE);
104                 }
105             }
106         } else {
107         }
108
109         return SKIP_BODY;
110     }
111
112     /**
113      * Ends this Tag run.
114      */

115     public int doEndTag() throws JspException {
116         return EVAL_PAGE;
117     }
118 }
119
Popular Tags