Coverage Report - org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewHandler
0%
0/59
0%
0/36
10
 
 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.tag.jsf.core;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 import javax.el.ELException;
 26  
 import javax.el.MethodExpression;
 27  
 import javax.faces.FacesException;
 28  
 import javax.faces.component.UIComponent;
 29  
 import javax.faces.component.UIViewRoot;
 30  
 import javax.faces.event.PhaseEvent;
 31  
 import javax.faces.view.facelets.FaceletContext;
 32  
 import javax.faces.view.facelets.FaceletException;
 33  
 import javax.faces.view.facelets.TagAttribute;
 34  
 import javax.faces.view.facelets.TagConfig;
 35  
 import javax.faces.view.facelets.TagHandler;
 36  
 
 37  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
 38  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
 39  
 import org.apache.myfaces.shared.util.StringUtils;
 40  
 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 41  
 
 42  
 /**
 43  
  * Container for all JavaServer Faces core and custom component actions used on a page. <p/> See <a target="_new"
 44  
  * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/view.html">tag documentation</a>.
 45  
  * 
 46  
  * @author Jacob Hookom
 47  
  * @version $Id$
 48  
  */
 49  
 @JSFFaceletTag(
 50  
         name = "f:view",
 51  
         bodyContent = "empty", 
 52  
         componentClass="javax.faces.component.UIViewRoot")
 53  
 public final class ViewHandler extends TagHandler
 54  
 {
 55  
 
 56  0
     private final static Class<?>[] LISTENER_SIG = new Class<?>[] { PhaseEvent.class };
 57  
 
 58  
     @JSFFaceletAttribute
 59  
     private final TagAttribute locale;
 60  
 
 61  
     @JSFFaceletAttribute
 62  
     private final TagAttribute renderKitId;
 63  
 
 64  
     @JSFFaceletAttribute
 65  
     private final TagAttribute contentType;
 66  
 
 67  
     @JSFFaceletAttribute
 68  
     private final TagAttribute encoding;
 69  
 
 70  
     @JSFFaceletAttribute
 71  
     private final TagAttribute beforePhase;
 72  
 
 73  
     @JSFFaceletAttribute
 74  
     private final TagAttribute afterPhase;
 75  
     
 76  
     @JSFFaceletAttribute(name="transient")
 77  
     private final TagAttribute transientAttribute;
 78  
     
 79  
     private final TagAttribute contracts;
 80  
     
 81  
     private final TagAttribute oamEnableViewPool;
 82  
 
 83  
     /**
 84  
      * @param config
 85  
      */
 86  
     public ViewHandler(TagConfig config)
 87  
     {
 88  0
         super(config);
 89  0
         this.locale = this.getAttribute("locale");
 90  0
         this.renderKitId = this.getAttribute("renderKitId");
 91  0
         this.contentType = this.getAttribute("contentType");
 92  0
         this.encoding = this.getAttribute("encoding");
 93  0
         this.beforePhase = this.getAttribute("beforePhase");
 94  0
         this.afterPhase = this.getAttribute("afterPhase");
 95  0
         this.transientAttribute = this.getAttribute("transient");
 96  0
         this.contracts = this.getAttribute("contracts");
 97  0
         this.oamEnableViewPool = this.getAttribute("oamEnableViewPool");
 98  0
     }
 99  
 
 100  
     /**
 101  
      * See taglib documentation.
 102  
      * 
 103  
      * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
 104  
      */
 105  
     public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
 106  
             ELException
 107  
     {
 108  0
         UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
 109  0
         if (root != null)
 110  
         {
 111  0
             if (this.locale != null)
 112  
             {
 113  0
                 root.setLocale(ComponentSupport.getLocale(ctx, this.locale));
 114  
             }
 115  0
             if (this.renderKitId != null)
 116  
             {
 117  0
                 String v = this.renderKitId.getValue(ctx);
 118  0
                 root.setRenderKitId(v);
 119  
             }
 120  0
             String encodingValue = null;
 121  0
             if (this.contentType != null)
 122  
             {
 123  
                 // This value is read as rfc2616 section 3.7 Media Types.
 124  
                 // We should check and extract the param "charset" and assing
 125  
                 // it as encoding for this page.
 126  0
                 String v = this.contentType.getValue(ctx);
 127  0
                 if (v != null)
 128  
                 {
 129  0
                     int j = v.indexOf(';');
 130  0
                     if (j >= 0)
 131  
                     {
 132  0
                         int i = v.indexOf("charset",j);
 133  0
                         if (i >= 0)
 134  
                         {
 135  0
                             i = v.indexOf('=',i)+1;
 136  0
                             if (v.length() > i)
 137  
                             {
 138  0
                                 encodingValue = v.substring(i);
 139  
                             }
 140  
                             // Substract charset from encoding, it will be added 
 141  
                             // later on FaceletViewDeclarationLanguage.createResponseWriter
 142  
                             // by calling response.setContentType
 143  0
                             v = v.substring(0 , j);
 144  
                         }
 145  
                     }
 146  
                 }
 147  0
                 ctx.getFacesContext().getAttributes().put("facelets.ContentType", v);
 148  
             }
 149  0
             if (this.encoding != null)
 150  
             {
 151  0
                 String v = this.encoding.getValue(ctx);
 152  0
                 ctx.getFacesContext().getAttributes().put("facelets.Encoding", v);
 153  0
             }
 154  0
             else if (encodingValue != null)
 155  
             {
 156  0
                 ctx.getFacesContext().getAttributes().put("facelets.Encoding", encodingValue);
 157  
             }
 158  0
             if (this.beforePhase != null)
 159  
             {
 160  0
                 MethodExpression m = this.beforePhase.getMethodExpression(ctx, null, LISTENER_SIG);
 161  0
                 root.setBeforePhaseListener(m);
 162  
             }
 163  0
             if (this.afterPhase != null)
 164  
             {
 165  0
                 MethodExpression m = this.afterPhase.getMethodExpression(ctx, null, LISTENER_SIG);
 166  0
                 root.setAfterPhaseListener(m);
 167  
             }
 168  0
             if (this.transientAttribute != null)
 169  
             {
 170  0
                 root.setTransient(this.transientAttribute.getBoolean(ctx));
 171  
             }
 172  0
             if (this.contracts != null)
 173  
             {
 174  0
                 String contractsValue = this.contracts.getValue(ctx);
 175  0
                 if (contractsValue != null)
 176  
                 {
 177  0
                     String[] values = StringUtils.trim(
 178  
                         StringUtils.splitShortString(contractsValue, ','));
 179  0
                     if (values != null)
 180  
                     {
 181  0
                         List<String> list = new ArrayList<String>();
 182  0
                         for (String v : values)
 183  
                         {
 184  0
                             list.add(v);
 185  
                         }
 186  0
                         ctx.getFacesContext().setResourceLibraryContracts(list);
 187  
                     }
 188  
                 }
 189  
             }
 190  0
             if (this.oamEnableViewPool != null)
 191  
             {
 192  0
                 root.getAttributes().put("oamEnableViewPool", this.oamEnableViewPool.getBoolean(ctx));
 193  
             }
 194  
         }
 195  0
         this.nextHandler.apply(ctx, parent);
 196  0
     }
 197  
 
 198  
 }