View Javadoc

1   /*
2    * $Id: Head.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.components;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  import org.apache.struts2.views.annotations.StrutsTag;
28  import org.apache.struts2.StrutsConstants;
29  
30  import com.opensymphony.xwork2.inject.Inject;
31  import com.opensymphony.xwork2.util.ValueStack;
32  
33  /***
34   * <!-- START SNIPPET: javadoc -->
35   *
36   * Renders parts of the HEAD section for an HTML file. Encoding can be set using this tag.
37   * <!-- END SNIPPET: javadoc -->
38   *
39   * <p/> <b>Examples</b>
40   *
41   * <pre>
42   * <!-- START SNIPPET: example1 -->
43   * &lt;head&gt;
44   *   &lt;title&gt;My page&lt;/title&gt;
45   *   &lt;s:head/&gt;
46   * &lt;/head&gt;
47   * <!-- END SNIPPET: example1 -->
48   * </pre>
49   *
50   */
51  @StrutsTag(name="head", tldBodyContent="empty", tldTagClass="org.apache.struts2.views.jsp.ui.HeadTag",
52      description="Render a chunk of HEAD for your HTML file")
53  public class Head extends UIBean {
54      public static final String TEMPLATE = "head";
55  
56      private String encoding;
57  
58      public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
59          super(stack, request, response);
60      }
61  
62      protected String getDefaultTemplate() {
63          return TEMPLATE;
64      }
65  
66      @Inject(StrutsConstants.STRUTS_I18N_ENCODING)
67      public void setEncoding(String encoding) {
68          this.encoding = encoding;
69      }
70  
71      public void evaluateParams() {
72          super.evaluateParams();
73  
74          addParameter("encoding", encoding);
75      }
76  }