Coverage Report - org.apache.myfaces.shared.view.ViewDeclarationLanguageBase
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewDeclarationLanguageBase
0%
0/27
0%
0/4
2
 
 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.shared.view;
 20  
 
 21  
 import javax.faces.application.Application;
 22  
 import javax.faces.application.ViewHandler;
 23  
 import javax.faces.component.UIViewRoot;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.view.ViewDeclarationLanguage;
 26  
 
 27  
 import org.apache.myfaces.shared.application.InvalidViewIdException;
 28  
 
 29  
 /**
 30  
  * @since 2.0
 31  
  */
 32  0
 public abstract class ViewDeclarationLanguageBase extends ViewDeclarationLanguage
 33  
 {
 34  
     
 35  
     /**
 36  
      * Process the specification required algorithm that is generic to all PDL.
 37  
      * 
 38  
      * @param context
 39  
      * @param viewId
 40  
      */
 41  
     public UIViewRoot createView(FacesContext context, String viewId)
 42  
     {
 43  0
         checkNull(context, "context");
 44  
         //checkNull(viewId, "viewId");
 45  
 
 46  
         try
 47  
         {
 48  0
             viewId = calculateViewId(context, viewId);
 49  
             
 50  0
             Application application = context.getApplication();
 51  
 
 52  
             // Create a new UIViewRoot object instance using Application.createComponent(UIViewRoot.COMPONENT_TYPE).
 53  0
             UIViewRoot newViewRoot = (UIViewRoot) application.createComponent(
 54  
                 context, UIViewRoot.COMPONENT_TYPE, null);
 55  0
             UIViewRoot oldViewRoot = context.getViewRoot();
 56  0
             if (oldViewRoot == null)
 57  
             {
 58  
                 // If not, this method must call calculateLocale() and calculateRenderKitId(), and store the results
 59  
                 // as the values of the locale and renderKitId, proeprties, respectively, of the newly created
 60  
                 // UIViewRoot.
 61  0
                 ViewHandler handler = application.getViewHandler();
 62  0
                 newViewRoot.setLocale(handler.calculateLocale(context));
 63  0
                 newViewRoot.setRenderKitId(handler.calculateRenderKitId(context));
 64  0
             }
 65  
             else
 66  
             {
 67  
                 // If there is an existing UIViewRoot available on the FacesContext, this method must copy its locale
 68  
                 // and renderKitId to this new view root
 69  0
                 newViewRoot.setLocale(oldViewRoot.getLocale());
 70  0
                 newViewRoot.setRenderKitId(oldViewRoot.getRenderKitId());
 71  
             }
 72  
             
 73  
             // TODO: VALIDATE - The spec is silent on the following line, but I feel bad if I don't set it
 74  0
             newViewRoot.setViewId(viewId);
 75  
 
 76  0
             return newViewRoot;
 77  
         }
 78  0
         catch (InvalidViewIdException e)
 79  
         {
 80  
             // If no viewId could be identified, or the viewId is exactly equal to the servlet mapping, 
 81  
             // send the response error code SC_NOT_FOUND with a suitable message to the client.
 82  0
             sendSourceNotFound(context, e.getMessage());
 83  
             
 84  
             // TODO: VALIDATE - Spec is silent on the return value when an error was sent
 85  0
             return null;
 86  
         }
 87  
     }
 88  
 
 89  
     /**
 90  
      * {@inheritDoc}
 91  
      */
 92  
     @Override
 93  
     public UIViewRoot restoreView(FacesContext context, String viewId)
 94  
     {
 95  0
         checkNull(context, "context");
 96  
         //checkNull(viewId, "viewId");
 97  
 
 98  0
         Application application = context.getApplication();
 99  
         
 100  0
         ViewHandler applicationViewHandler = application.getViewHandler();
 101  
         
 102  0
         String renderKitId = applicationViewHandler.calculateRenderKitId(context);
 103  
 
 104  0
         UIViewRoot viewRoot = application.getStateManager().restoreView(context, viewId, renderKitId);
 105  
 
 106  0
         return viewRoot;
 107  
     }
 108  
 
 109  
     /**
 110  
      * Calculates the effective view identifier for the specified raw view identifier.
 111  
      * 
 112  
      * @param context le current FacesContext
 113  
      * @param viewId the raw view identifier
 114  
      * 
 115  
      * @return the effective view identifier
 116  
      */
 117  
     protected abstract String calculateViewId(FacesContext context, String viewId);
 118  
     
 119  
     /**
 120  
      * Send a source not found to the client. Although it can be considered ok in JSP mode,
 121  
      * I think it's pretty lame to have this kind of requirement at VDL level considering VDL 
 122  
      * represents the page --> JSF tree link, not the transport layer required to send a 
 123  
      * SC_NOT_FOUND.
 124  
      * 
 125  
      * @param context le current FacesContext
 126  
      * @param message the message associated with the error
 127  
      */
 128  
     protected abstract void sendSourceNotFound(FacesContext context, String message);
 129  
     
 130  
     /**
 131  
      * Check if the specified value of a param is <code>null</code>.
 132  
      * 
 133  
      * @param o the parameter's value
 134  
      * @param param the parameter's name
 135  
      * 
 136  
      * @throws NullPointerException if the value is <code>null</code>
 137  
      */
 138  
     protected void checkNull(final Object o, final String param)
 139  
     {
 140  0
         if (o == null)
 141  
         {
 142  0
             throw new NullPointerException(param + " can not be null.");
 143  
         }
 144  0
     }
 145  
 }