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 url 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 */ 123 public abstract Iterator<AjaxHandler> getAjaxHandlers(); 124 125 /** 126 * @since 2.0 127 */ 128 public abstract void popAjaxHandlerToStack(); 129 130 /** 131 * @since 2.0 132 */ 133 public abstract void pushAjaxHandlerToStack(AjaxHandler parent); 134 135 /** 136 * Check if this build is for build composite component metadata 137 * 138 * @return 139 * @since 2.0 140 */ 141 public abstract boolean isBuildingCompositeComponentMetadata(); 142 143 /** 144 * Pop the current composite component template client, removing the 145 * current template context from stack. 146 * 147 * @since 2.0.1 148 */ 149 public abstract void popCompositeComponentClient(); 150 151 /** 152 * Push the composite component tag handler identified by client on 153 * template context stack, triggering the creation of a new empty 154 * TemplateContext, that will be used to resolve templates used 155 * on that component later. 156 * 157 * @since 2.0.1 158 */ 159 public abstract void pushCompositeComponentClient(final TemplateClient client); 160 161 /** 162 * Push the passed template context instance onto the stack, so all 163 * slots to be resolved (using includeDefinition() call) will take 164 * into account the information there. 165 * 166 * @since 2.0.1 167 */ 168 public abstract void pushTemplateContext(TemplateContext templateContext); 169 170 /** 171 * Pop the passed template context instance from stack. This method is 172 * used by CompositeComponentResourceTagHandler to resolve templates 173 * according to the composite component level it is necessary. 174 * 175 * @since 2.0.1 176 */ 177 public abstract TemplateContext popTemplateContext(); 178 179 /** 180 * This method resolve the current definition to be added by cc:insertChildren 181 * or cc:insertFacet. 182 * 183 * @since 2.0.1 184 */ 185 public abstract boolean includeCompositeComponentDefinition(UIComponent parent, String name) 186 throws IOException, FaceletException, FacesException, ELException; 187 188 /** 189 * Return the current template context 190 * 191 * @since 2.0.8 192 * @return 193 */ 194 public TemplateContext getTemplateContext() 195 { 196 return null; 197 } 198 199 /** 200 * Push the passed page context instance onto the stack. 201 * 202 * @since 2.0.8 203 * @param client 204 */ 205 public void pushPageContext(PageContext client) 206 { 207 } 208 209 /** 210 * Pop the passed page context instance onto the stack. 211 * 212 * @since 2.0.8 213 * @param client 214 */ 215 public PageContext popPageContext() 216 { 217 return null; 218 } 219 220 /** 221 * Return the current page context 222 * 223 * @since 2.0.8 224 * @return 225 */ 226 public PageContext getPageContext() 227 { 228 return null; 229 } 230 231 /** 232 * Check if a variable has been resolved by this variable mapper 233 * or any parent "facelets contextual" variable mapper. 234 * 235 * @return 236 * @since 2.0.8 237 */ 238 public boolean isAnyFaceletsVariableResolved() 239 { 240 return true; 241 } 242 243 public boolean isAllowCacheELExpressions() 244 { 245 return false; 246 } 247 248 /** 249 * Indicates an expression will be resolved, so preparations 250 * should be done to detect if a contextual variable has been resolved. 251 * 252 * @since 2.0.8 253 */ 254 public void beforeConstructELExpression() 255 { 256 } 257 258 /** 259 * Cleanup all initialization done for construct an EL Expression. 260 * 261 * @since 2.0.8 262 */ 263 public void afterConstructELExpression() 264 { 265 } 266 267 /** 268 * Return the mode used to decide whether to cache or not EL expressions 269 * 270 * @since 2.0.8 271 */ 272 public ELExpressionCacheMode getELExpressionCacheMode() 273 { 274 return ELExpressionCacheMode.noCache; 275 } 276 277 public String generateUniqueFaceletTagId(String count, String base) 278 { 279 return count; 280 } 281 }