View Javadoc

1   /*
2    * $Id: Head.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.components;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.struts2.StrutsConstants;
24  import org.apache.struts2.config.Settings;
25  
26  import com.opensymphony.xwork2.util.ValueStack;
27  
28  /***
29   * <!-- START SNIPPET: javadoc -->
30   *
31   * Renders parts of the HEAD section for an HTML file. This is useful as some themes require certain CSS and JavaScript
32   * includes.<p/>
33   *
34   * If, for example, your page has ajax components integrated, without having the default theme set to ajax, you might
35   * want to use the head tag with <b>theme="ajax"</b> so that the typical ajax header setup will be included in the
36   * page.<p/>
37   *
38   * The tag also includes the option to set a custom datepicker theme if needed. See calendarcss parameter for
39   * description for details.<p/>
40   *
41   * If you use the ajax theme you can turn a debug flag on by setting the debug parameter to <tt>true</tt>.
42   *
43   * <!-- END SNIPPET: javadoc -->
44   *
45   * <p/> <b>Examples</b>
46   *
47   * <pre>
48   * <!-- START SNIPPET: example1 -->
49   * &lt;head&gt;
50   *   &lt;title&gt;My page&lt;/title&gt;
51   *   &lt;s:head/&gt;
52   * &lt;/head&gt;
53   * <!-- END SNIPPET: example1 -->
54   * </pre>
55   *
56   * <pre>
57   * <!-- START SNIPPET: example2 -->
58   * &lt;head&gt;
59   *   &lt;title&gt;My page&lt;/title&gt;
60   *   &lt;s:head theme="ajax" calendarcss="calendar-green"/&gt;
61   * &lt;/head&gt;
62   * <!-- END SNIPPET: example2 -->
63   * </pre>
64   *
65   * <pre>
66   * <!-- START SNIPPET: example3 -->
67   * &lt;head&gt;
68   *   &lt;title&gt;My page&lt;/title&gt;
69   *   &lt;s:head theme="ajax" debug="true"/&gt;
70   * &lt;/head&gt;
71   * <!-- END SNIPPET: example3 -->
72   * </pre>
73   *
74   * @s.tag name="head" tld-body-content="empty" tld-tag-class="org.apache.struts2.views.jsp.ui.HeadTag"
75   * description="Render a chunk of HEAD for your HTML file"
76   */
77  public class Head extends UIBean {
78      public static final String TEMPLATE = "head";
79  
80      private String calendarcss = "calendar-blue.css";
81      private boolean debug;
82  
83      public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
84          super(stack, request, response);
85      }
86  
87      protected String getDefaultTemplate() {
88          return TEMPLATE;
89      }
90  
91      public void evaluateParams() {
92          super.evaluateParams();
93  
94          if (calendarcss != null) {
95              String css = findString(calendarcss);
96              if (css != null && css.trim().length() > 0) {
97                  if (css.lastIndexOf(".css") < 0) {
98                      addParameter("calendarcss", css + ".css");
99                  } else {
100                     addParameter("calendarcss", css);
101                 }
102             }
103         }
104 
105         addParameter("encoding", Settings.get(StrutsConstants.STRUTS_I18N_ENCODING));
106         addParameter("debug", Boolean.valueOf(debug).toString());
107     }
108 
109     public String getCalendarcss() {
110         return calendarcss;
111     }
112 
113     /***
114      * The jscalendar css theme to use" default="calendar-blue.css
115      * @s.tagattribute required="false"
116      */
117     public void setCalendarcss(String calendarcss) {
118         this.calendarcss = calendarcss;
119     }
120 
121     public boolean isDebug() {
122         return debug;
123     }
124 
125     /***
126      * Set to true to enable debugging mode for AJAX themes
127      * @s.tagattribute required="false"
128      */
129     public void setDebug(boolean debug) {
130         this.debug = debug;
131     }
132 
133 
134 }