001: /*
002: * $Id: Head.java 497654 2007-01-19 00:21:57Z rgielen $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.struts2.views.annotations.StrutsTag;
027: import org.apache.struts2.views.annotations.StrutsTagAttribute;
028: import org.apache.struts2.StrutsConstants;
029:
030: import com.opensymphony.xwork2.inject.Inject;
031: import com.opensymphony.xwork2.util.ValueStack;
032:
033: /**
034: * <!-- START SNIPPET: javadoc -->
035: *
036: * Renders parts of the HEAD section for an HTML file. This is useful as some themes require certain CSS and JavaScript
037: * includes.<p/>
038: *
039: * If, for example, your page has ajax components integrated, without having the default theme set to ajax, you might
040: * want to use the head tag with <b>theme="ajax"</b> so that the typical ajax header setup will be included in the
041: * page.<p/>
042: *
043: * The tag also includes the option to set a custom datepicker theme if needed. See calendarcss parameter for
044: * description for details.<p/>
045: *
046: * If you use the ajax theme you can turn a debug flag on by setting the debug parameter to <tt>true</tt>.
047: *
048: * <!-- END SNIPPET: javadoc -->
049: *
050: * <p/> <b>Examples</b>
051: *
052: * <pre>
053: * <!-- START SNIPPET: example1 -->
054: * <head>
055: * <title>My page</title>
056: * <s:head/>
057: * </head>
058: * <!-- END SNIPPET: example1 -->
059: * </pre>
060: *
061: * <pre>
062: * <!-- START SNIPPET: example2 -->
063: * <head>
064: * <title>My page</title>
065: * <s:head theme="ajax" calendarcss="calendar-green"/>
066: * </head>
067: * <!-- END SNIPPET: example2 -->
068: * </pre>
069: *
070: * <pre>
071: * <!-- START SNIPPET: example3 -->
072: * <head>
073: * <title>My page</title>
074: * <s:head theme="ajax" debug="true"/>
075: * </head>
076: * <!-- END SNIPPET: example3 -->
077: * </pre>
078: *
079: */
080: @StrutsTag(name="head",tldBodyContent="empty",tldTagClass="org.apache.struts2.views.jsp.ui.HeadTag",description="Render a chunk of HEAD for your HTML file")
081: public class Head extends UIBean {
082: public static final String TEMPLATE = "head";
083:
084: private String calendarcss = "calendar-blue.css";
085: private boolean debug;
086: private String encoding;
087:
088: public Head(ValueStack stack, HttpServletRequest request,
089: HttpServletResponse response) {
090: super (stack, request, response);
091: }
092:
093: protected String getDefaultTemplate() {
094: return TEMPLATE;
095: }
096:
097: @Inject(StrutsConstants.STRUTS_I18N_ENCODING)
098: public void setEncoding(String encoding) {
099: this .encoding = encoding;
100: }
101:
102: public void evaluateParams() {
103: super .evaluateParams();
104:
105: if (calendarcss != null) {
106: String css = findString(calendarcss);
107: if (css != null && css.trim().length() > 0) {
108: if (css.lastIndexOf(".css") < 0) {
109: addParameter("calendarcss", css + ".css");
110: } else {
111: addParameter("calendarcss", css);
112: }
113: }
114: }
115:
116: addParameter("encoding", encoding);
117: addParameter("debug", Boolean.valueOf(debug).toString());
118: }
119:
120: public String getCalendarcss() {
121: return calendarcss;
122: }
123:
124: @StrutsTagAttribute(description="The jscalendar css theme to use",defaultValue="calendar-blue.css")
125: public void setCalendarcss(String calendarcss) {
126: //TODO remove this one
127: this .calendarcss = calendarcss;
128: }
129:
130: public boolean isDebug() {
131: return debug;
132: }
133:
134: @StrutsTagAttribute(description="Set to true to enable debugging mode for AJAX themes")
135: public void setDebug(boolean debug) {
136: this.debug = debug;
137: }
138:
139: }
|