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.HashMap;
23  import java.util.Map;
24  
25  import javax.el.ELException;
26  import javax.faces.FacesException;
27  import javax.faces.application.Resource;
28  import javax.faces.component.UIViewRoot;
29  import javax.faces.context.FacesContext;
30  import javax.faces.context.ResponseWriter;
31  
32  import org.apache.myfaces.view.facelets.compiler.Compiler;
33  
34  /**
35   * Expose protected api of FaceletViewDeclarationLanguage to 
36   * junit tests.
37   * 
38   * @author Leonardo Uribe (latest modification by $Author: jakobk $)
39   * @version $Revisio$ $Date: 2010-04-12 10:30:11 -0500 (Mon, 12 Apr 2010) $
40   */
41  public class MockFaceletViewDeclarationLanguage extends
42          FaceletViewDeclarationLanguage
43  {
44  
45      private String _renderedViewId;
46      private Map<Resource, Resource> _scriptComponentResources;
47      
48      public MockFaceletViewDeclarationLanguage(FacesContext context)
49      {
50          super(context);
51      }
52      
53      public void buildView(FacesContext context, UIViewRoot view, String xmlFile) throws IOException
54      {
55          _renderedViewId = xmlFile;
56          buildView(context, view);
57      }
58      
59      @Override
60      public String getRenderedViewId(FacesContext context, String actionId)
61      {
62          return _renderedViewId;//super.getRenderedViewId(context, actionId);
63      }    
64  
65      @Override
66      public String calculateViewId(FacesContext context, String viewId)
67      {
68          String calculatedViewId = super.calculateViewId(context, viewId);
69          if (calculatedViewId == null)
70          {
71              //can't calculate it, just passthrough the received one
72              calculatedViewId = viewId;
73          }
74          return calculatedViewId;
75      }
76  
77      @Override
78      public Compiler createCompiler(FacesContext context)
79      {
80          return super.createCompiler(context);
81      }
82  
83      @Override
84      public FaceletFactory createFaceletFactory(FacesContext context,
85              Compiler compiler)
86      {
87          return super.createFaceletFactory(context, compiler);
88      }
89  
90      @Override
91      public ResponseWriter createResponseWriter(FacesContext context)
92              throws IOException, FacesException
93      {
94          return super.createResponseWriter(context);
95      }
96  
97      @Override
98      public String getDefaultSuffix(FacesContext context)
99              throws FacesException
100     {
101         return super.getDefaultSuffix(context);
102     }
103 
104     @Override
105     public String getResponseContentType(FacesContext context, String orig)
106     {
107         return super.getResponseContentType(context, orig);
108     }
109 
110     @Override
111     public String getResponseEncoding(FacesContext context, String orig)
112     {
113         return super.getResponseEncoding(context, orig);
114     }
115 
116     @Override
117     public void handleFaceletNotFound(FacesContext context, String viewId)
118             throws FacesException, IOException
119     {
120         super.handleFaceletNotFound(context, viewId);
121     }
122 
123     @Override
124     public void handleRenderException(FacesContext context, Exception e)
125             throws IOException, ELException, FacesException
126     {
127         super.handleRenderException(context, e);
128     }
129 
130     @Override
131     public void initialize(FacesContext context)
132     {
133         super.initialize(context);
134     }
135 
136     @Override
137     public void loadDecorators(FacesContext context, Compiler compiler)
138     {
139         super.loadDecorators(context, compiler);
140     }
141 
142     @Override
143     public void loadLibraries(FacesContext context, Compiler compiler)
144     {
145         super.loadLibraries(context, compiler);
146     }
147 
148     @Override
149     public void loadOptions(FacesContext context, Compiler compiler)
150     {
151         super.loadOptions(context, compiler);
152     }
153 
154     @Override
155     public void sendSourceNotFound(FacesContext context, String message)
156     {
157         super.sendSourceNotFound(context, message);
158     }
159 
160     @Override
161     public Resource getScriptComponentResource(FacesContext context,
162             Resource componentResource)
163     {
164         if (_scriptComponentResources != null)
165         {
166             Resource installedResource = _scriptComponentResources.get(componentResource);
167             if (installedResource != null)
168             {
169                 // if we have a Resource installed for this componentResource, return it
170                 return installedResource;
171             }
172         }
173         return super.getScriptComponentResource(context, componentResource);
174     }
175     
176     /**
177      * This method sets the scriptResource for a given componentResource so that
178      * a call to getScriptComponentResource() with the given componentResource
179      * will return the installed scriptResource.
180      * @param componentResource
181      * @param scriptResource
182      */
183     public void setScriptComponentResource(Resource componentResource, Resource scriptResource)
184     {
185         if (_scriptComponentResources == null)
186         {
187             _scriptComponentResources = new HashMap<Resource, Resource>();
188         }
189         _scriptComponentResources.put(componentResource, scriptResource);
190     }
191     
192     //public Facelet getFacelet(String viewId) throws IOException
193     //{
194     //    return super._getFacelet(viewId);
195     //}
196 
197 }