Coverage Report - org.seasar.teeda.core.util.ExternalContextUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
ExternalContextUtil
71%
15/21
70%
7/10
2.75
 
 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.util;
 17  
 
 18  
 import javax.faces.application.ViewHandler;
 19  
 import javax.faces.context.ExternalContext;
 20  
 import javax.faces.context.FacesContext;
 21  
 
 22  
 import org.seasar.framework.util.AssertionUtil;
 23  
 import org.seasar.teeda.core.portlet.FacesPortlet;
 24  
 
 25  
 /**
 26  
  * @author higa
 27  
  * @author manhole
 28  
  */
 29  
 public class ExternalContextUtil {
 30  
 
 31  0
     private ExternalContextUtil() {
 32  0
     }
 33  
 
 34  
     public static String getViewId(ExternalContext externalContext) {
 35  
         // PortletSupport
 36  8
         if (PortletUtil.isPortlet(FacesContext.getCurrentInstance())) {
 37  0
             String viewId = (String) externalContext.getRequestMap().get(
 38  
                     FacesPortlet.VIEW_ID);
 39  0
             if (viewId == null) {
 40  0
                 viewId = (String) externalContext.getRequestMap().get(
 41  
                         FacesPortlet.DEFAULT_PAGE);
 42  
             }
 43  0
             return viewId;
 44  
         } else {
 45  8
             String viewId = externalContext.getRequestPathInfo();
 46  8
             if (viewId == null) {
 47  4
                 viewId = externalContext.getRequestServletPath();
 48  4
                 final int dot = viewId.lastIndexOf('.');
 49  4
                 if (dot >= 0) {
 50  3
                     final String suffix = getSuffix(externalContext);
 51  3
                     viewId = viewId.substring(0, dot) + suffix;
 52  
                 }
 53  
             }
 54  8
             return viewId;
 55  
         }
 56  
     }
 57  
 
 58  
     private static String getSuffix(ExternalContext externalContext) {
 59  3
         final String defaultSuffix = externalContext
 60  
                 .getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
 61  3
         if (defaultSuffix != null) {
 62  1
             return defaultSuffix;
 63  
         }
 64  2
         return ViewHandler.DEFAULT_SUFFIX;
 65  
     }
 66  
 
 67  
     public static String encodeActionURL(FacesContext context, String url) {
 68  1
         AssertionUtil.assertNotNull("FacesContext", context);
 69  1
         return context.getExternalContext().encodeActionURL(url);
 70  
     }
 71  
 }