KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > taglibs > url > AbstractURLTag


1 package org.jahia.taglibs.url;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletRequest JavaDoc;
6 import javax.servlet.jsp.JspException JavaDoc;
7 import javax.servlet.jsp.JspWriter JavaDoc;
8 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
9
10 import org.jahia.data.JahiaData;
11
12 /**
13  * <p>Title: Abstract URL tag</p>
14  * <p>Description: This tag provides common services among all of Jahia's
15  * URL generation tags.</p>
16  * <p>Copyright: Copyright (c) 2002</p>
17  * <p>Company: Jahia Ltd</p>
18  * @author Serge Huber
19  * @version 1.0
20  */

21
22 public abstract class AbstractURLTag extends TagSupport JavaDoc {
23
24     private static org.apache.log4j.Logger logger =
25             org.apache.log4j.Logger.getLogger(AbstractURLTag.class);
26
27     private String JavaDoc name = null;
28     private boolean display = true;
29     private boolean withJSPopup = true;
30     private JahiaData jData = null;
31
32     public String JavaDoc getName() {
33         return name;
34     }
35     public void setName(String JavaDoc name) {
36         this.name = name;
37     }
38     public boolean isDisplay() {
39         return display;
40     }
41     public void setDisplay(boolean display) {
42         this.display = display;
43     }
44     public boolean isWithJSPopup() {
45         return withJSPopup;
46     }
47     public void setWithJSPopup(boolean withJSPopup) {
48         this.withJSPopup = withJSPopup;
49     }
50
51     protected JahiaData getJahiaData() {
52         return jData;
53     }
54
55     /**
56      * Called by the doStartTag() default implementation immediately after the
57      * JahiaData object has been retrieved (if available). Implement this method
58      * to initialize any data objects in your tag before the rest of the URL
59      * generation
60      */

61     protected abstract void init();
62
63     /**
64      * This method's implementation must return an object to be set if the
65      * id attribute was set on the tag. This will be the object stored in the
66      * page context with the corresponding ID only if it is non-null.
67      * If the method needs to get the actual ID for internal processing, it is
68      * available via the getId() method provided by the TagSupport implementation
69      * @return an Object to be stored on the page context with the corresponding
70      * id
71      */

72     protected abstract Object JavaDoc getIdObject();
73
74     protected abstract String JavaDoc getURL();
75
76     protected abstract String JavaDoc getJSPopupURL();
77
78     public int doStartTag() {
79
80         ServletRequest JavaDoc request = pageContext.getRequest();
81
82         jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");
83
84         init();
85
86         if (getId() != null) {
87             // remove previous page context object
88
pageContext.removeAttribute(id);
89
90             if (getIdObject() != null) {
91                 pageContext.setAttribute(id, getIdObject());
92             }
93         }
94
95         if (isDisplay()) {
96             try {
97                 String JavaDoc url = isWithJSPopup() ? getJSPopupURL() : getURL();
98                 if (url != null) {
99                   JspWriter JavaDoc out = pageContext.getOut();
100                   out.print(url);
101                 }
102             } catch (IOException JavaDoc ioe) {
103                 logger.error("AddContainerURLTag: doStartTag ", ioe);
104             }
105         }
106         return SKIP_BODY;
107     }
108
109
110     public int doEndTag ()
111         throws JspException JavaDoc {
112         super.doEndTag();
113         display = true;
114         name = null;
115         withJSPopup = true;
116         jData = null;
117         return EVAL_PAGE;
118     }
119
120 }
121
Popular Tags