View Javadoc

1   /*
2    * Copyright 2002-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.struts.faces.taglib;
18  
19  
20  import javax.faces.component.UIComponent;
21  import javax.servlet.jsp.JspException;
22  import javax.servlet.jsp.PageContext;
23  import org.apache.struts.Globals;
24  
25  
26  /***
27   * <p>Render an HTML <code>&lt;html&gt;</code> element for
28   * the <em>Struts-Faces Integration Library</em>.</p>
29   *
30   * @version $Rev: 421138 $ $Date: 2006-07-11 22:41:40 -0700 (Tue, 11 Jul 2006) $
31   */
32  
33  public class HtmlTag extends AbstractFacesTag {
34  
35  
36      // ---------------------------------------------------------- Tag Attributes
37  
38  
39      /***
40       * <p>Set a locale if not set yet.</p>
41       */
42      private String locale = null;
43  
44      public void setLocale(String locale) {
45          this.locale = locale;
46      }
47  
48  
49      /***
50       * <p>Render Struts HTML tags as xhtml.</p>
51       */
52      private String xhtml = null;
53  
54      public void setXhtml(String xhtml) {
55          this.xhtml = xhtml;
56      }
57  
58  
59      // ---------------------------------------------------------- Public Methods
60  
61  
62      /***
63       * <p>Return the type of component to be created for this tag.</p>
64       */
65      public String getComponentType() {
66  
67          return ("org.apache.struts.faces.Html");
68  
69      }
70  
71  
72      /***
73       * <p>Override <code>doStartTag()</code> method to also set a page
74       * context attribute if <code>xhtml</code> is <code>>true</code>.</p>
75       */
76      public int doStartTag() throws JspException {
77  
78          int result = super.doStartTag();
79          if (xhtml != null) {
80              pageContext.setAttribute(Globals.XHTML_KEY, "true",
81                                       PageContext.PAGE_SCOPE);
82          }
83          return (result);
84  
85      }
86  
87  
88      /***
89       * <p>Return the <code>rendererType</code> to be used for rendering
90       * our component.</p>
91       */
92      public String getRendererType() {
93  
94          return ("org.apache.struts.faces.Html");
95  
96      }
97  
98  
99      /***
100      * <p>Release resources allocated to this tag instance.</p>
101      */
102     public void release() {
103 
104         super.release();
105         this.locale = null;
106         this.xhtml = null;
107 
108     }
109 
110 
111     // ------------------------------------------------------- Protected Methods
112 
113 
114     /***
115      * <p>Override attributes set on this tag instance.</p>
116      *
117      * @param component Component whose attributes should be overridden
118      */
119     protected void setProperties(UIComponent component) {
120 
121         super.setProperties(component);
122         setBooleanAttribute(component, "locale", locale);
123         setBooleanAttribute(component, "xhtml", xhtml);
124 
125     }
126 
127 
128 }