Coverage Report - javax.faces.internal.WindowIdEncodeUrlCustomizer
 
Classes in this File Line Coverage Branch Coverage Complexity
WindowIdEncodeUrlCustomizer
94%
16/17
100%
4/4
2
 
 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 javax.faces.internal;
 17  
 
 18  
 import javax.faces.context.ExternalContext;
 19  
 
 20  
 import org.seasar.framework.util.AssertionUtil;
 21  
 import org.seasar.framework.util.StringUtil;
 22  
 
 23  
 /**
 24  
  * @author shot
 25  
  */
 26  9
 public class WindowIdEncodeUrlCustomizer implements EncodeUrlCustomizer {
 27  
 
 28  
     private static final long serialVersionUID = 1L;
 29  
 
 30  
     public String encodeActionUrl(final ExternalContext externalContext,
 31  
             final String url) {
 32  9
         return encodeResourceUrl(externalContext, url);
 33  
     }
 34  
 
 35  
     public String encodeResourceUrl(final ExternalContext externalContext,
 36  
             final String url) {
 37  15
         AssertionUtil.assertNotNull("url is null.", url);
 38  15
         AssertionUtil
 39  
                 .assertNotNull("externalContext is null.", externalContext);
 40  15
         final String wid = WindowIdUtil.getWindowId(externalContext);
 41  15
         if (StringUtil.isEmpty(wid)) {
 42  5
             return url;
 43  
         }
 44  10
         final StringBuffer buf = new StringBuffer(url.length() +
 45  
                 WindowIdUtil.WID.length() + 2);
 46  10
         buf.append(url);
 47  10
         if (url.lastIndexOf("?") > -1) {
 48  5
             buf.append("&");
 49  
         } else {
 50  5
             buf.append("?");
 51  
         }
 52  10
         buf.append(WindowIdUtil.WID);
 53  10
         buf.append("=");
 54  10
         buf.append(wid);
 55  10
         return buf.toString();
 56  
     }
 57  
 
 58  
     //do nothing
 59  
     public String encodeNamespace(final String name) {
 60  0
         return name;
 61  
     }
 62  
 
 63  
 }