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  
20  package org.apache.myfaces.tobago.internal.application;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.apache.myfaces.tobago.portlet.PortletUtils;
25  import org.apache.myfaces.tobago.util.DebugUtils;
26  import org.apache.myfaces.tobago.util.RequestUtils;
27  
28  import javax.faces.FacesException;
29  import javax.faces.application.ViewHandler;
30  import javax.faces.component.UIViewRoot;
31  import javax.faces.context.FacesContext;
32  import java.io.IOException;
33  import java.util.Locale;
34  
35  /**
36   * Not longer needed.
37   *
38   * @deprecated since Tobago 1.6.0
39   */
40  @Deprecated
41  public class ViewHandlerImpl extends ViewHandler {
42  
43    private static final Logger LOG = LoggerFactory.getLogger(ViewHandlerImpl.class);
44  
45    private ViewHandler base;
46  
47    public ViewHandlerImpl(ViewHandler base) {
48      if (LOG.isInfoEnabled()) {
49        LOG.info("Hiding RI base implementation: " + base);
50      }
51      this.base = base;
52    }
53  
54    public Locale calculateLocale(FacesContext facesContext) {
55      return base.calculateLocale(facesContext);
56    }
57  
58    public String calculateRenderKitId(FacesContext facesContext) {
59      return base.calculateRenderKitId(facesContext);
60    }
61  
62    public UIViewRoot createView(FacesContext facesContext, String viewId) {
63      if (LOG.isDebugEnabled()) {
64        LOG.debug("creating new view with viewId:        '{}'", viewId);
65      }
66      UIViewRoot viewRoot = base.createView(facesContext, viewId);
67      // ensure tobago UIViewRoot RI don't create the component via application
68      if (!(viewRoot instanceof org.apache.myfaces.tobago.component.UIViewRoot)) {
69        UIViewRoot tobagoViewRoot = (UIViewRoot)
70            facesContext.getApplication().createComponent(UIViewRoot.COMPONENT_TYPE);
71        if (!(tobagoViewRoot instanceof org.apache.myfaces.tobago.component.UIViewRoot)) {
72          LOG.warn("Application creating wrong UIViewRoot, forcing Tobago");
73          tobagoViewRoot = new org.apache.myfaces.tobago.component.UIViewRoot();
74        }
75        tobagoViewRoot.setLocale(viewRoot.getLocale());
76        tobagoViewRoot.setViewId(viewId);
77        tobagoViewRoot.setRenderKitId(viewRoot.getRenderKitId());
78        viewRoot = tobagoViewRoot;
79      }
80      return viewRoot;
81    }
82  
83    public String getActionURL(FacesContext facesContext, String viewId) {
84  
85      if (PortletUtils.isRenderResponse(facesContext)) {
86        return PortletUtils.setViewIdForUrl(facesContext, viewId);
87      }
88  
89      return base.getActionURL(facesContext, viewId);
90    }
91  
92    public String getResourceURL(FacesContext facesContext, String path) {
93      return base.getResourceURL(facesContext, path);
94    }
95  
96    public void renderView(FacesContext facesContext, UIViewRoot viewRoot)
97        throws IOException, FacesException {
98      // standard
99      base.renderView(facesContext, viewRoot);
100 
101     if (LOG.isDebugEnabled()) {
102       LOG.debug("VIEW");
103       LOG.debug(DebugUtils.toString(facesContext.getViewRoot(), 0));
104     }
105   }
106 
107   public UIViewRoot restoreView(FacesContext facesContext, String viewId) {
108     if (LOG.isDebugEnabled()) {
109       LOG.debug("restore view with viewId:             '{}'", viewId);
110     }
111     // this is only needed in the first request, the later will be handled by faces
112     // TODO: maybe find a way to make this unneeded
113     RequestUtils.ensureEncoding(facesContext);
114     UIViewRoot viewRoot = base.restoreView(facesContext, viewId);
115     return viewRoot;
116   }
117 
118   public void writeState(FacesContext facesContext) throws IOException {
119     base.writeState(facesContext);
120   }
121 
122 }
123