Coverage Report - org.seasar.teeda.core.context.creator.servlet.ServletExternalContextCreator
 
Classes in this File Line Coverage Branch Coverage Complexity
ServletExternalContextCreator
91%
10/11
83%
5/6
2.5
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.context.creator.servlet;
 17  
 
 18  
 import javax.faces.context.ExternalContext;
 19  
 import javax.faces.internal.EncodeUrlCustomizer;
 20  
 import javax.faces.internal.WindowIdEncodeUrlCustomizer;
 21  
 import javax.servlet.ServletContext;
 22  
 import javax.servlet.ServletRequest;
 23  
 import javax.servlet.ServletResponse;
 24  
 
 25  
 import org.seasar.teeda.core.context.creator.ExternalContextCreator;
 26  
 import org.seasar.teeda.core.context.servlet.ServletExternalContextImpl;
 27  
 import org.seasar.teeda.core.util.DIContainerUtil;
 28  
 
 29  
 /**
 30  
  * @author shot
 31  
  *
 32  
  */
 33  7
 public class ServletExternalContextCreator implements ExternalContextCreator {
 34  
 
 35  
     public ExternalContext create(Object context, Object request,
 36  
             Object response) {
 37  3
         if (!ServletEnvironmentUtil.isServletEnvironment(context, request,
 38  
                 response)) {
 39  0
             return null;
 40  
         }
 41  3
         return createExternalContext((ServletContext) context,
 42  
                 (ServletRequest) request, (ServletResponse) response);
 43  
     }
 44  
 
 45  
     protected ExternalContext createExternalContext(ServletContext context,
 46  
             ServletRequest request, ServletResponse response) {
 47  3
         ServletExternalContextImpl externalContext = new ServletExternalContextImpl(
 48  
                 context, request, response);
 49  3
         EncodeUrlCustomizer customizer = (EncodeUrlCustomizer) DIContainerUtil
 50  1
                 .getComponentNoException(EncodeUrlCustomizer.class);
 51  3
         if (customizer == null) {
 52  2
             customizer = new WindowIdEncodeUrlCustomizer();
 53  
         }
 54  3
         externalContext.setEncodeUrlCustomizer(customizer);
 55  3
         return externalContext;
 56  
     }
 57  
 
 58  
 }