View Javadoc

1   // WARNING: This file was automatically generated. Do not edit it directly,
2   //          or you will lose your changes.
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21  */
22  package org.apache.myfaces.trinidad.component.html;
23  
24  import java.util.ArrayDeque;
25  import java.util.Collections;
26  import java.util.Map;
27  import java.util.Queue;
28  import javax.faces.context.FacesContext;
29  import org.apache.myfaces.trinidad.bean.FacesBean;
30  import org.apache.myfaces.trinidad.bean.PropertyKey;
31  import org.apache.myfaces.trinidad.component.UIXComponentBase;
32  import org.apache.myfaces.trinidad.context.ComponentContextManager;
33  import org.apache.myfaces.trinidad.context.RequestContext;
34  import org.apache.myfaces.trinidad.context.SuspendedContextChanges;
35  import org.apache.myfaces.trinidad.util.ComponentUtils;
36  
37  /**
38   *
39   * <html:p>
40   *             Tag for the HTML head element, including the
41   *             document's title and any style sheets needed by th
42   *             current look-and-feel.  Page authors
43   *             that use this do not need to use a styleSheet component, as it
44   *             will automatically be included.
45   *           </html:p>
46   * <html:p>
47   *   The head component resets the Trinidad EL context when code re-enters the component via
48   *   an invoke on component call or a visit tree call. See the
49   *   org.apache.myfaces.trinidad.context.ComponentContextManager for more information.
50   * </html:p>
51   *
52   * <h4>Events:</h4>
53   * <table border="1" width="100%" cellpadding="3" summary="">
54   * <tr bgcolor="#CCCCFF" class="TableHeadingColor">
55   * <th align="left">Type</th>
56   * <th align="left">Phases</th>
57   * <th align="left">Description</th>
58   * </tr>
59   * <tr class="TableRowColor">
60   * <td valign="top"><code>org.apache.myfaces.trinidad.event.AttributeChangeEvent</code></td>
61   * <td valign="top" nowrap>Invoke<br>Application<br>Apply<br>Request<br>Values</td>
62   * <td valign="top">Event delivered to describe an attribute change.  Attribute change events are not delivered for any programmatic change to a property.  They are only delivered when a renderer changes a property without the application's specific request.  An example of an attribute change event might include the width of a column that supported client-side resizing.</td>
63   * </tr>
64   * </table>
65   */
66  public class HtmlHead extends UIXComponentBase
67  {
68    static public final FacesBean.Type TYPE = new FacesBean.Type(
69      UIXComponentBase.TYPE);
70    static public final PropertyKey TITLE_KEY =
71      TYPE.registerKey("title", String.class);
72    static public final PropertyKey PARTIAL_TRIGGERS_KEY =
73      TYPE.registerKey("partialTriggers", String[].class, null, 0, PropertyKey.Mutable.RARELY);
74  
75    static public final String COMPONENT_FAMILY =
76      "org.apache.myfaces.trinidad.Head";
77    static public final String COMPONENT_TYPE =
78      "org.apache.myfaces.trinidad.HtmlHead";
79  
80    /**
81     * Construct an instance of the HtmlHead.
82     */
83    public HtmlHead()
84    {
85      super("org.apache.myfaces.trinidad.Head");
86    }
87      /**
88     * Suspends any context changes before allowing invokeOnComponent or visitTree calls to continue,
89     * allowing components to undo any context changes during a re-entrant call.
90     * @param facesContext the faces context
91     * @see ComponentContextManager#suspend(FacesContext)
92     */
93    @Override
94    protected void setupVisitingContext(FacesContext facesContext)
95    {
96      ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
97        .getComponentContextManager();
98  
99      // Suspend any current component context during a visit tree for re-entrant
100     // component tree processing
101     SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
102 
103     Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
104     @SuppressWarnings("unchecked")
105     Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
106       reqMap.get(_SUSPENDED_CHANGES_KEY);
107     if (suspendedChangesQueue == null)
108     {
109       suspendedChangesQueue = Collections.asLifoQueue(new ArrayDeque<SuspendedContextChanges>());
110       reqMap.put(_SUSPENDED_CHANGES_KEY, suspendedChangesQueue);
111     }
112 
113     suspendedChangesQueue.offer(suspendedChanges);
114 
115     super.setupVisitingContext(facesContext);
116   }
117 
118   /**
119    * Re-applies the suspended context changes.
120    * @param facesContext the faces context
121    * @see #setupVisitingContext(FacesContext)
122    * @see ComponentContextManager#resume(FacesContext, SuspendedContextChanges)
123    */
124   @Override
125   protected void tearDownVisitingContext(FacesContext facesContext)
126   {
127     super.tearDownVisitingContext(facesContext);
128 
129     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
130       .getComponentContextManager();
131     Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
132     @SuppressWarnings("unchecked")
133     Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
134       reqMap.get(_SUSPENDED_CHANGES_KEY);
135     SuspendedContextChanges changes = suspendedChangesQueue.poll();
136     ctxMgr.resume(facesContext, changes);
137   }
138 
139   private final static String _SUSPENDED_CHANGES_KEY = HtmlHead.class.getName() +
140                                                        ".SUSPENDED_CHANGES";
141 
142   /**
143    * Gets The title of the document.  (This title doesn't have to match the
144    *             title on any contained panelPage.)
145    *
146    * @return  the new title value
147    */
148   final public String getTitle()
149   {
150     return ComponentUtils.resolveString(getProperty(TITLE_KEY));
151   }
152 
153   /**
154    * Sets The title of the document.  (This title doesn't have to match the
155    *             title on any contained panelPage.)
156    * 
157    * @param title  the new title value
158    */
159   final public void setTitle(String title)
160   {
161     setProperty(TITLE_KEY, (title));
162   }
163 
164   /**
165    * Gets the IDs of the components that should trigger a partial update.
166    *          This component will listen on the trigger components. If one of the
167    *          trigger components receives an event that will cause it to update
168    *          in some way, this component will request to be updated too.
169    *
170    * @return  the new partialTriggers value
171    */
172   final public String[] getPartialTriggers()
173   {
174     return (String[])getProperty(PARTIAL_TRIGGERS_KEY);
175   }
176 
177   /**
178    * Sets the IDs of the components that should trigger a partial update.
179    *          This component will listen on the trigger components. If one of the
180    *          trigger components receives an event that will cause it to update
181    *          in some way, this component will request to be updated too.
182    * 
183    * @param partialTriggers  the new partialTriggers value
184    */
185   final public void setPartialTriggers(String[] partialTriggers)
186   {
187     setProperty(PARTIAL_TRIGGERS_KEY, (partialTriggers));
188   }
189 
190   @Override
191   public String getFamily()
192   {
193     return COMPONENT_FAMILY;
194   }
195 
196   @Override
197   protected FacesBean.Type getBeanType()
198   {
199     return TYPE;
200   }
201 
202   /**
203    * Construct an instance of the HtmlHead.
204    */
205   protected HtmlHead(
206     String rendererType
207     )
208   {
209     super(rendererType);
210   }
211 
212   static
213   {
214     TYPE.lockAndRegister("org.apache.myfaces.trinidad.Head","org.apache.myfaces.trinidad.Head");
215   }
216 }