001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.components;
006:
007: import com.opensymphony.xwork.util.OgnlValueStack;
008: import com.opensymphony.webwork.config.Configuration;
009: import com.opensymphony.webwork.WebWorkConstants;
010:
011: import javax.servlet.http.HttpServletRequest;
012: import javax.servlet.http.HttpServletResponse;
013:
014: /**
015: * <!-- START SNIPPET: javadoc -->
016: *
017: * Renders parts of the HEAD section for an HTML file. This is useful as some themes require certain CSS and JavaScript
018: * includes.<p/>
019: *
020: * If, for example, your page has ajax components integrated, without having the default theme set to ajax, you might
021: * want to use the head tag with <b>theme="ajax"</b> so that the typical ajax header setup will be included in the
022: * page.<p/>
023: *
024: * The tag also includes the option to set a custom datepicker theme if needed. See calendarcss parameter for
025: * description for details.<p/>
026: *
027: * If you use the ajax theme you can turn a debug flag on by setting the debug parameter to <tt>true</tt>.
028: *
029: * <!-- END SNIPPET: javadoc -->
030: *
031: * <p/> <b>Examples</b>
032: *
033: * <pre>
034: * <!-- START SNIPPET: example1 -->
035: * <head>
036: * <title>My page</title>
037: * <ww:head/>
038: * </head>
039: * <!-- END SNIPPET: example1 -->
040: * </pre>
041: *
042: * <pre>
043: * <!-- START SNIPPET: example2 -->
044: * <head>
045: * <title>My page</title>
046: * <ww:head theme="ajax" calendarcss="calendar-green"/>
047: * </head>
048: * <!-- END SNIPPET: example2 -->
049: * </pre>
050: *
051: * <pre>
052: * <!-- START SNIPPET: example3 -->
053: * <head>
054: * <title>My page</title>
055: * <ww:head theme="ajax" debug="true"/>
056: * </head>
057: * <!-- END SNIPPET: example3 -->
058: * </pre>
059: *
060: * @author Patrick Lightbody
061: * @author Rainer Hermanns
062: * @author Rene Gielen
063: * @ww.tag name="head" tld-body-content="empty" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.HeadTag"
064: * description="Render a chunk of HEAD for your HTML file"
065: * @since 2.2
066: */
067: public class Head extends UIBean {
068: public static final String TEMPLATE = "head";
069:
070: private String calendarcss = "calendar-blue.css";
071: private boolean debug;
072:
073: public Head(OgnlValueStack stack, HttpServletRequest request,
074: HttpServletResponse response) {
075: super (stack, request, response);
076: }
077:
078: protected String getDefaultTemplate() {
079: return TEMPLATE;
080: }
081:
082: public void evaluateParams() {
083: super .evaluateParams();
084:
085: if (calendarcss != null) {
086: String css = findString(calendarcss);
087: if (css != null && css.trim().length() > 0) {
088: if (css.lastIndexOf(".css") < 0) {
089: addParameter("calendarcss", css + ".css");
090: } else {
091: addParameter("calendarcss", css);
092: }
093: }
094: }
095:
096: addParameter("encoding", Configuration
097: .get(WebWorkConstants.WEBWORK_I18N_ENCODING));
098: addParameter("debug", Boolean.valueOf(debug).toString());
099: }
100:
101: public String getCalendarcss() {
102: return calendarcss;
103: }
104:
105: /**
106: * The jscalendar css theme to use" default="calendar-blue.css
107: * @ww.tagattribute required="false"
108: */
109: public void setCalendarcss(String calendarcss) {
110: this .calendarcss = calendarcss;
111: }
112:
113: public boolean isDebug() {
114: return debug;
115: }
116:
117: /**
118: * Set to true to enable debugging mode for AJAX themes
119: * @ww.tagattribute required="false"
120: */
121: public void setDebug(boolean debug) {
122: this.debug = debug;
123: }
124:
125: }
|