View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets;
20  
21  import java.io.IOException;
22  import java.util.Iterator;
23  
24  import javax.el.ELException;
25  import javax.faces.FacesException;
26  import javax.faces.application.Resource;
27  import javax.faces.component.UIComponent;
28  import javax.faces.view.facelets.FaceletContext;
29  import javax.faces.view.facelets.FaceletException;
30  
31  import org.apache.myfaces.view.facelets.tag.jsf.core.AjaxHandler;
32  
33  
34  /**
35   * This class contains methods that belongs to original FaceletContext shipped in
36   * facelets code before 2.0, but does not take part from api, so are considered 
37   * implementation details. This includes methods related to template handling
38   * feature of facelets (called by ui:composition, ui:define and ui:insert).
39   * 
40   * The methods here are only used by the current implementation and the intention
41   * is not expose it as public api.
42   * 
43   * Aditionally, it also contains methods used by the current implementation for
44   * implement new features, like composite components and UniqueIdVendor support.
45   * 
46   * @author Leonardo Uribe (latest modification by $Author$)
47   * @version $Revision$ $Date$
48   * 
49   * @since 2.0
50   */
51  public abstract class AbstractFaceletContext extends FaceletContext
52  {    
53      /**
54       * Return the current FaceletCompositionContext instance from this
55       * build.
56       * 
57       * @return the current FaceletCompositionContext instance
58       */
59      public abstract FaceletCompositionContext getFaceletCompositionContext();
60      
61      /**
62       * Push the passed TemplateClient onto the stack for Definition Resolution
63       * @param client
64       * @see TemplateClient
65       */
66      public abstract void pushClient(TemplateClient client);
67  
68      /**
69       * Pop the last added pushed TemplateClient
70       * @see TemplateClient
71       */
72      public abstract TemplateManager popClient(TemplateClient client);
73      
74      /**
75       * Pop the last added extended TemplateClient
76       * @param client
77       */
78      public abstract TemplateManager popExtendedClient(TemplateClient client);
79  
80      public abstract void extendClient(TemplateClient client);
81  
82      /**
83       * This method will walk through the TemplateClient stack to resolve and
84       * apply the definition for the passed name.
85       * If it's been resolved and applied, this method will return true.
86       * 
87       * @param parent the UIComponent to apply to
88       * @param name name or null of the definition you want to apply
89       * @return true if successfully applied, otherwise false
90       * @throws IOException
91       * @throws FaceletException
92       * @throws FacesException
93       * @throws ELException
94       */
95      public abstract boolean includeDefinition(UIComponent parent, String name)
96              throws IOException, FaceletException, FacesException, ELException;
97      
98      /**
99       * Apply the facelet referenced by a url containing a composite component
100      * definition to the current UIComponent. In other words, apply the section
101      * composite:implementation in the facelet to the current component.
102      * 
103      * We need to do this here because DefaultFacelet is the one who has and
104      * handle the current FaceletFactory instance.
105      * 
106      * @param parent
107      * @param resource
108      * @throws IOException
109      * @throws FaceletException
110      * @throws FacesException
111      * @throws ELException 
112      */
113     public abstract void applyCompositeComponent(UIComponent parent, Resource resource)
114             throws IOException, FaceletException, FacesException, ELException;
115 
116     /**
117      * Return a descending iterator containing the ajax handlers to be applied
118      * to an specific component that implements ClientBehaviorHolder interface,
119      * according to the conditions specified on jsf 2.0 spec section 10.4.1.1.
120      * 
121      * @since 2.0
122      * @return 
123      */
124     public abstract Iterator<AjaxHandler> getAjaxHandlers();
125     
126     /**
127      * @since 2.0
128      */
129     public abstract void popAjaxHandlerToStack();
130     
131     /**
132      * @since 2.0
133      */
134     public abstract void pushAjaxHandlerToStack(AjaxHandler parent);
135     
136     /**
137      * Check if this build is for build composite component metadata
138      * 
139      * @return
140      * @since 2.0
141      */
142     public abstract boolean isBuildingCompositeComponentMetadata();
143 
144     /**
145      * Pop the current composite component template client, removing the
146      * current template context from stack.
147      * 
148      * @since 2.0.1
149      */
150     public abstract void popCompositeComponentClient();
151 
152     /**
153      * Push the composite component tag handler identified by client on 
154      * template context stack, triggering the creation of a new empty 
155      * TemplateContext, that will be used to resolve templates used 
156      * on that component later.
157      * 
158      * @since 2.0.1
159      * @param client 
160      */
161     public abstract void pushCompositeComponentClient(final TemplateClient client);
162 
163     /**
164      * Push the passed template context instance onto the stack, so all
165      * slots to be resolved (using includeDefinition() call) will take
166      * into account the information there.
167      * 
168      * @since 2.0.1
169      * @param templateContext 
170      */
171     public abstract void pushTemplateContext(TemplateContext templateContext);
172 
173     /**
174      * Pop the passed template context instance from stack. This method is
175      * used by CompositeComponentResourceTagHandler to resolve templates
176      * according to the composite component level it is necessary.
177      * 
178      * @since 2.0.1
179      */
180     public abstract TemplateContext popTemplateContext();
181 
182     /**
183      * This method resolve the current definition to be added by cc:insertChildren
184      * or cc:insertFacet.
185      *  
186      * @since 2.0.1
187      * @param parent
188      * @param name
189      * @return
190      * @throws IOException
191      * @throws FaceletException
192      * @throws FacesException
193      * @throws ELException 
194      */
195     public abstract boolean includeCompositeComponentDefinition(UIComponent parent, String name)
196         throws IOException, FaceletException, FacesException, ELException;
197     
198     /**
199      * Return the current template context
200      * 
201      * @since 2.0.8
202      * @return
203      */
204     public TemplateContext getTemplateContext()
205     {
206         return null;
207     }
208 
209     /**
210      * Push the passed page context instance onto the stack.
211      * 
212      * @since 2.0.8
213      * @param client
214      */
215     public void pushPageContext(PageContext client)
216     {
217     }
218     
219     /**
220      * Pop the passed page context instance onto the stack.
221      * 
222      * @since 2.0.8
223      */
224     public PageContext popPageContext()
225     {
226         return null;
227     }
228     
229     /**
230      * Return the current page context
231      * 
232      * @since 2.0.8
233      * @return
234      */
235     public PageContext getPageContext()
236     {
237         return null;
238     }
239     
240     /**
241      * Check if a variable has been resolved by this variable mapper
242      * or any parent "facelets contextual" variable mapper.
243      * 
244      * @return
245      * @since 2.0.8
246      */
247     public boolean isAnyFaceletsVariableResolved()
248     {
249         return true;
250     }
251     
252     public boolean isAllowCacheELExpressions()
253     {
254         return false;
255     }
256     
257     /**
258      * Indicates an expression will be resolved, so preparations
259      * should be done to detect if a contextual variable has been resolved.
260      * 
261      * @since 2.0.8
262      */
263     public void beforeConstructELExpression()
264     {
265     }
266     
267     /**
268      * Cleanup all initialization done for construct an EL Expression.
269      * 
270      * @since 2.0.8
271      */
272     public void afterConstructELExpression()
273     {
274     }
275 
276     /**
277      * Return the mode used to decide whether to cache or not EL expressions
278      * 
279      * @since 2.0.8
280      */
281     public ELExpressionCacheMode getELExpressionCacheMode()
282     {
283         return ELExpressionCacheMode.noCache;
284     }
285     
286     public String generateUniqueFaceletTagId(String count, String base)
287     {
288         return count;
289     }
290 }