Source code: com/newsfighter/layout/jsptags/LogoTag.java
1 /*
2 * LogoTag.java
3 *
4 * Created on February 16, 2003, 4:30 PM
5 * Written by N. Alex Rupp, Minneapolis
6 */
7
8 package com.newsfighter.layout.jsptags;
9
10 import javax.servlet.jsp.*;
11 import javax.servlet.jsp.tagext.*;
12
13 /** <!-- =============================================================== -->
14 * The <code>LogoTag</code> layout component creates a specialized
15 * panel for logo and menu graphics at the top of the page. Because
16 * there are so many ways one might want to lay out their logo graphics,
17 * this class will most likely undergo radical changes in future
18 * versions of the Newsfighter software.
19 * @author <a href="mailto:n_alex_rupp@users.sourceforge.net">N. Alex Rupp</a>
20 */
21 public class LogoTag extends BodyTagSupport {
22
23 /** <!-- =============================================================== -->
24 * reference to the {@link SkinFactory} object.
25 */
26 private SkinFactory factory;
27
28 /** <!-- =============================================================== -->
29 * A reference to the enclosing {@link ManagerTag} instance.
30 */
31 private ManagerTag manager;
32
33 /** <!-- =============================================================== -->
34 * records the name of the skin the page author wishes to use. defaults
35 * to the "default" skin.
36 */
37 private String skin;
38
39 // ============================================================
40 // skin support fuctions, required for all skinnable tags.
41
42 // initSkinSystem() should be called at the beginning of doStartTag().
43 /** <!-- =============================================================== -->
44 * Initializes the {@link SkinFactory} and the {@link ManagerTag}
45 * instances. First it checks to see if the skin attribute has been
46 * set. If it has, this means the enclosing {@link ManagerTag}'s
47 * instance of the {@link SkinFactory} object must be overridden, and
48 * it tells <code>setSkinFactory </code> to create a new one.
49 *
50 * initSkinSystem() should be called at the beginning of doStartTag().
51 *
52 * @see GutterTag
53 * @see PanelTag
54 */
55 private void initSkinSystem() {
56 // get the manager's skin information if you haven't any of your own.
57 if (this.skin == null) {
58 this.getManagerSkin();
59 }
60 // if you don't have a skinfactory by now, you should.
61 if (this.factory == null) {
62 this.setSkinFactory(this.skin);
63 }
64 }
65
66 /** <!-- =============================================================== -->
67 * Sets the value of the <code>skin</code> attribute to override that
68 * set by the {@link ManagerTag}.
69 * @param skinName the name of the skin this layout component
70 * should use, overrides that set by
71 * {@link ManagerTag}. Can be specified in the
72 * JSP tag, as per the JSP tag library descriptor
73 * for this library.
74 */
75 public void setSkin(String skinName){
76 // whenever you reset the skinName, you need to get a new skinfactory.
77 this.setSkinFactory(skinName);
78 this.skin = skinName;
79 }
80
81 /** <!-- =============================================================== -->
82 * returns the value of this.skin.
83 *
84 * @return this.skin
85 */
86 public String getSkin() {
87 return this.skin;
88 }
89
90 /** <!-- =============================================================== -->
91 * Creates a new {@link SkinFactory} object and stores a reference to
92 * it in the local <code>factory</code> variable.
93 * @param skinName must equate to the value
94 * of the <code>skin</code> variable,
95 * user-specified in the JSP tag.
96 * @see setSkin().
97 * @see getSkin().
98 */
99 private void setSkinFactory(String skinName) {
100 // this creates the real path to the skin.xml descriptor.
101 String path = "/layout/skins/" + skinName + "/skin.xml";
102 this.factory = new SkinFactory(pageContext.getServletContext().getRealPath(path));
103 }
104
105 /** <!-- =============================================================== -->
106 * Stores a reference to the enclosing (@link ManagerTag)'s
107 * {@link SkinFactory} in the local <code>factory</code> parameter.
108 */
109 private void getManagerSkin() {
110 // if you don't have a reference to the manager tag, you should.
111 if (this.manager == null) {
112 initManager();
113 }
114 // get the manager tag's factory and skin info.
115 this.factory = this.manager.getSkinFactory();
116 this.skin = this.manager.getSkin();
117 }
118
119 /** <!-- =============================================================== -->
120 * Initializes the <code>manager</code> attribute.
121 */
122 private void initManager() {
123 // this creates the reference to the required enclosing manager tag instance.
124 this.manager = (ManagerTag)findAncestorWithClass(this, ManagerTag.class);
125 try {
126 if (this.manager == null) {
127 throw new JspTagException("A panel tag must be nested within a manager tag.");
128 }
129 } catch (JspTagException e) {
130 e.printStackTrace();
131 }
132 }
133
134 /** <!-- =============================================================== -->
135 * doStartTag is called by the JSP container when the tag is encountered.
136 * This writes a table column in HTML which contains a spacer.gif of the
137 * specified width. Since this class does not enclose any other layout
138 * components, it returns <code>EVAL_BODY</code>.
139 * @return <code>EVAL_BODY_INCLUDE</code>
140 */
141 public int doStartTag() {
142 initSkinSystem();
143 try {
144 // " + factory + "
145 JspWriter out = pageContext.getOut();
146 out.println("");
147 out.println("<!-- begin logo panel -->");
148 out.println("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"" + factory.getLogoWidth() + "\">");
149 out.println("\t<tr>");
150 out.println("\t\t<td>");
151 out.println("");
152 out.println("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" >");
153 out.println("\t<tr>");
154 out.println("\t\t<td align=\"top\"><a id=\"menu\" href=\"/\"><img src=\"/layout/skins/" + this.getSkin() +
155 "/" + factory.getLogoImageSrc("1") +
156 "\" border=\"0\" height=\"" + factory.getLogoImageHeight("1") +
157 "\" width=\"" + factory.getLogoImageWidth("1") + "\"></a></td>");
158
159 out.println("\t</tr>");
160 out.println("</table>");
161 out.println("");
162 out.println("\t\t</td>");
163 out.println("\t\t<td>");
164 out.println("");
165 out.println("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">");
166 out.println("\t<tr>");
167 out.println("\t\t<td><img align=\"top\" src=\"/layout/skins/" + this.getSkin() +
168 "/" + factory.getLogoImageSrc("2") +
169 "\" border=\"0\" height=\"" + factory.getLogoImageHeight("2") +
170 "\" width=\"" + factory.getLogoImageWidth("2") + "\"></td>");
171
172 out.println("\t</tr>");
173 out.println("\t<tr>");
174 out.println("\t\t<td align=\"right\">");
175 out.println("");
176 out.println("<!-- begin menu -->");
177 out.println("<span id=\"" + factory.getMenuCssId() + "\">");
178
179 } catch (Exception ex) {
180 throw new Error(" ==== Error in LogoTag doStartTag()");
181 }
182 // Must return EVAL_BODY because we are supporting a body for this
183 // tag.
184 return EVAL_BODY_INCLUDE;
185 }
186 /** <!-- =============================================================== -->
187 * doEndTag is called by the JSP container when the tag is closed.
188 *
189 * @return <code>EVAL_PAGE</code>
190 */
191 public int doEndTag(){
192 try {
193 JspWriter out = pageContext.getOut();
194 out.print("</span>");
195 out.println("<img align=\"top\" src=\"/layout/spacer.gif\" height=\"" +
196 factory.getMenuHeight() + "\" width=\"" +
197 factory.getMenuRightMargin() + "\"/>");
198 out.println("<!-- end menu ---->");
199 out.println("");
200 out.println("\t\t</td>");
201 out.println("\t</tr>");
202 out.println("\t<tr>");
203 out.println("\t\t<td><img src=\"/layout/skins/" + this.getSkin() +
204 "/" + factory.getLogoImageSrc("3") +
205 "\" border=\"0\" height=\"" + factory.getLogoImageHeight("3") +
206 "\" width=\"" + factory.getLogoImageWidth("3") + "\"></a></td>");
207
208 out.println("\t<tr>");
209 out.println("</table>");
210 out.println("");
211 out.println("\t\t</td>");
212 out.println("\t</tr>");
213 out.println("</table>");
214 out.println("<!-- end logo panel -->");
215
216 } catch (Exception ex){
217 throw new Error("==== Error in LogoTag doEndTag()");
218 }
219 return EVAL_PAGE;
220 }
221 }
222