KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > HtmlTag


1 package fr.improve.struts.taglib.layout;
2
3 /*
4  * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/HtmlTag.java,v 1.2 2001/02/11 00:14:50 craigmcc Exp $
5  * $Revision: 1.2 $
6  * $Date: 2001/02/11 00:14:50 $
7  *
8  * ====================================================================
9  *
10  * The Apache Software License, Version 1.1
11  *
12  * Copyright (c) 1999 The Apache Software Foundation. All rights
13  * reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  *
19  * 1. Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  *
22  * 2. Redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in
24  * the documentation and/or other materials provided with the
25  * distribution.
26  *
27  * 3. The end-user documentation included with the redistribution, if
28  * any, must include the following acknowlegement:
29  * "This product includes software developed by the
30  * Apache Software Foundation (http://www.apache.org/)."
31  * Alternately, this acknowlegement may appear in the software itself,
32  * if and wherever such third-party acknowlegements normally appear.
33  *
34  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
35  * Foundation" must not be used to endorse or promote products derived
36  * from this software without prior written permission. For written
37  * permission, please contact apache@apache.org.
38  *
39  * 5. Products derived from this software may not be called "Apache"
40  * nor may "Apache" appear in their names without prior written
41  * permission of the Apache Group.
42  *
43  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
44  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
47  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
50  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54  * SUCH DAMAGE.
55  * ====================================================================
56  *
57  * This software consists of voluntary contributions made by many
58  * individuals on behalf of the Apache Software Foundation. For more
59  * information on the Apache Software Foundation, please see
60  * <http://www.apache.org/>.
61  *
62  */

63
64 import javax.servlet.http.HttpServletRequest JavaDoc;
65 import javax.servlet.jsp.JspException JavaDoc;
66
67 import fr.improve.struts.taglib.layout.event.EndLayoutEvent;
68 import fr.improve.struts.taglib.layout.event.StartLayoutEvent;
69 import fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent;
70 import fr.improve.struts.taglib.layout.event.StaticCodeIncludeListener;
71 import fr.improve.struts.taglib.layout.util.LayoutUtils;
72 import fr.improve.struts.taglib.layout.util.TagUtils;
73
74 /**
75  * Renders an HTML &lt;html&gt; element with appropriate language attributes if
76  * there is a current Locale available in the user's session.
77  * Also render an &lt;head&gt; element with a link to the stylesheet to use,
78  * a link to the struts-layout javascript and a &lt;base&gt; element
79  *
80  * NOTE: the property locale needs to have a getter called isLocale for SUN 1.3.1 VM and getLocale for IBM 1.3.0
81  *
82  * PENDING add a layout attribute (boolean) to choose if the table and br should be generated or not.
83  *
84  * @author Jean-Noel Ribette
85  */

86
87 public class HtmlTag extends PanelTag implements StaticCodeIncludeListener {
88
89     /**
90      * Should we set the current Locale for this user if needed?
91      */

92     protected boolean locale = false;
93
94     /**
95      * Are we rendering an xhtml page?
96      */

97     protected boolean xhtml = false;
98     
99     /**
100      * onload event handler.
101      */

102     protected String JavaDoc onload;
103     
104     /**
105      * content align.
106      */

107     protected String JavaDoc contentAlign = "center";
108     
109     /**
110      * layout ?
111      */

112     protected boolean layout = true;
113     
114     /**
115      * Static code.
116      */

117     protected StringBuffer JavaDoc staticCode = new StringBuffer JavaDoc();
118
119     protected org.apache.struts.taglib.html.BaseTag baseTag =
120         new org.apache.struts.taglib.html.BaseTag();
121     protected org.apache.struts.taglib.html.HtmlTag htmlTag =
122         new org.apache.struts.taglib.html.HtmlTag();
123         
124     public HtmlTag() {
125         super();
126         width = "80%";
127         align ="center";
128         contentAlign = "center";
129         layout = true;
130     }
131     
132     /**
133      * @see fr.improve.struts.taglib.layout.event.StaticCodeIncludeListener#processStaticCodeIncludeEvent(fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent)
134      */

135     public Object JavaDoc processStaticCodeIncludeEvent(StaticCodeIncludeLayoutEvent in_event) throws JspException JavaDoc {
136         String JavaDoc lc_value = (String JavaDoc) in_event.getValue();
137         staticCode.append(lc_value);
138         return "";
139     }
140             
141     /**
142      * Process a StartLayoutEvent.
143      * @return type of Layout tag
144      */

145     public Object JavaDoc processStartLayoutEvent(StartLayoutEvent in_event) throws JspException JavaDoc {
146         return Boolean.FALSE;
147     }
148     public Object JavaDoc processEndLayoutEvent(EndLayoutEvent in_event) throws JspException JavaDoc {
149         return Boolean.FALSE;
150     }
151
152 public void doBeforeBody(StringBuffer JavaDoc sb) {
153     sb.append("<br><table cellspacing=\"0\" cellpadding=\"10\" width=\"100%\" align=\"");
154     sb.append(contentAlign);
155     sb.append("\" border=\"0\">");
156 }
157 protected void doEndHtml(StringBuffer JavaDoc sb) {
158     DynMenuTag2.includeScriptCode(sb, pageContext);
159     sb.append("</body>");
160 }
161 /**
162  * Process the end of this tag.
163  *
164  * @exception JspException if a JSP exception has occurred
165  */

166 public int doEndLayoutTag() throws JspException JavaDoc {
167
168     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
169     if (layout) {
170         sb.append("</td>");
171         sb.append("</tr>");
172         sb.append("</table>");
173     }
174     
175     if (staticCode.length()!=0) {
176         sb.append(staticCode.toString());
177         staticCode = new StringBuffer JavaDoc();
178     }
179     
180     doEndHtml(sb);
181     TagUtils.write(pageContext, sb.toString());
182     htmlTag.doEndTag();
183
184     return (EVAL_PAGE);
185
186 }
187 protected void doPrintHead(StringBuffer JavaDoc sb) throws JspException JavaDoc {
188     if (key != null) {
189         sb.append("\t<title>");
190         sb.append(getLabel());
191         sb.append("</title>\n");
192     }
193     sb.append("\t<link rel=\"stylesheet\" HREF='");
194     sb.append(getSkin().getCssDirectory(pageContext.getRequest()));
195     sb.append("/");
196     sb.append(LayoutUtils.getSkin(pageContext.getSession()).getCssFileName());
197     sb.append("' type=\"text/css\">\n");
198     sb.append("\t<script language=\"Javascript\" SRC=\"");
199     sb.append(getSkin().getConfigDirectory(pageContext.getRequest()));
200     sb.append("/javascript.js\"></script>");
201     sb.append("<script>var imgsrc=\"");
202     sb.append(getSkin().getImageDirectory(pageContext.getRequest()));
203     if (!getSkin().getImageDirectory(pageContext.getRequest()).endsWith("/"))
204         sb.append("/");
205     sb.append("\"; var scriptsrc=\"");
206     sb.append(getSkin().getConfigDirectory(pageContext.getRequest()));
207     if (!getSkin().getConfigDirectory(pageContext.getRequest()).endsWith("/")) sb.append("/");
208     sb.append("\"; var langue=\"");
209     sb.append(LayoutUtils.getLocale(pageContext).getLanguage());
210     sb.append("\"; var contextPath=\"");
211     sb.append(((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath());
212     sb.append("\";</script>");
213 }
214 /**
215  * Process the start of this tag.
216  *
217  * @exception JspException if a JSP exception has occurred
218  */

219 public int doStartLayoutTag() throws JspException JavaDoc {
220
221     // append the html tag
222
LayoutUtils.copyProperties(htmlTag,this);
223     htmlTag.doStartTag();
224     
225     // append the head tag
226
TagUtils.write(pageContext, "\n<head>\n\t");
227     
228     LayoutUtils.copyProperties(baseTag,this);
229     baseTag.doStartTag();
230     baseTag.doEndTag();
231     TagUtils.write(pageContext, "\n");
232     
233     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
234     doPrintHead(sb);
235     TagUtils.write(pageContext, sb.toString());
236         
237
238     sb.setLength(0);
239     sb.append("\n</head>\n");
240     
241     sb.append("<body");
242     if (onload!=null) {
243         sb.append(" onload=\"");
244         sb.append(onload);
245         sb.append("\"");
246     }
247     sb.append(">\n");
248
249     // append the title table
250
if (styleClass!=null) {
251         doStartPanel(sb);
252         if (key!=null) doPrintTitle(sb);
253         doEndPanel(sb);
254     }
255     
256     // prepare the body layout
257
if (layout) {
258         doBeforeBody(sb);
259         sb.append("<tr>");
260         sb.append("<td align=\"center\">");
261     }
262
263     TagUtils.write(pageContext, sb.toString());
264     return (EVAL_BODY_INCLUDE);
265
266 }
267 public boolean getLocale() {
268         return locale;
269     }
270     public boolean getXhtml() {
271         return xhtml;
272     }
273     public boolean isLocale() {
274         return locale;
275     }
276 /**
277   * Release any acquired resources.
278   */

279 public void release() {
280     super.release();
281
282     htmlTag.release();
283     baseTag.release();
284     
285     locale = false;
286     xhtml = false;
287     
288     width = "80%";
289     align = "center";
290     
291     onload = null;
292     layout = true;
293     contentAlign = "center";
294 }
295 /**
296  * Creation date: (30/05/01 16:07:40)
297  * @param newLocale boolean
298  */

299 public void setLocale(boolean newLocale) {
300     locale = newLocale;
301 }
302     public void setXhtml(boolean xhtml) {
303         this.xhtml = xhtml;
304     }
305     public String JavaDoc getOnload() {
306         return onload;
307     }
308
309     public void setOnload(String JavaDoc in_onload) {
310         onload = in_onload;
311     }
312     
313     public void setAlign(String JavaDoc in_align) {
314         contentAlign = in_align;
315     }
316     
317     public void setLayout(boolean in_layout) {
318         layout = in_layout;
319     }
320
321 }
322
Popular Tags