Coverage report

  %line %branch
org.apache.jetspeed.container.url.impl.DesktopEncodingPortalURL
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.container.url.impl;
 18  
 
 19  
 import java.io.UnsupportedEncodingException;
 20  
 import java.util.Map;
 21  
 import java.util.StringTokenizer;
 22  
 
 23  
 import javax.portlet.PortletMode;
 24  
 import javax.portlet.WindowState;
 25  
 import javax.servlet.http.HttpServletRequest;
 26  
 
 27  
 import org.apache.jetspeed.PortalContext;
 28  
 import org.apache.jetspeed.PortalReservedParameters;
 29  
 import org.apache.jetspeed.container.state.NavigationalState;
 30  
 import org.apache.jetspeed.container.url.BasePortalURL;
 31  
 import org.apache.jetspeed.desktop.JetspeedDesktop;
 32  
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 33  
 import org.apache.pluto.om.window.PortletWindow;
 34  
 import org.apache.pluto.om.entity.PortletEntity;
 35  
 import org.apache.pluto.om.portlet.PortletDefinition;
 36  
 
 37  
 /**
 38  
  * DesktopEncodingPortalURL encodes action URLs to target desktop specific /action pipeline,
 39  
  * and render URLs to target desktop specific /render pipeline
 40  
  * 
 41  
  * The query parameters "entity" and "portlet" are added to each url. These parameters are needed in a /render
 42  
  * request and are used by the desktop javascript code for both /render and /action requests.
 43  
  * 
 44  
  * @author <a href="mailto:ate@apache.org">Ate Douma</a>
 45  
  * @version $Id: PathInfoEncodingPortalURL.java 367856 2006-01-11 01:04:09Z taylor $
 46  
  */
 47  
 public class DesktopEncodingPortalURL extends AbstractPortalURL
 48  
 {
 49  0
     private String baseActionPath = null;
 50  0
     private String baseRenderPath = null;
 51  
     
 52  0
     private String desktopActionPipelinePath = null;
 53  0
     private String desktopRenderPipelinePath = null;
 54  
     
 55  
     
 56  
     public DesktopEncodingPortalURL(NavigationalState navState, PortalContext portalContext, String desktopRenderPipelinePath, String desktopActionPipelinePath)
 57  
     {
 58  0
         super(navState, portalContext);
 59  0
         initializePipelinePaths( desktopRenderPipelinePath, desktopActionPipelinePath );
 60  0
     }
 61  
     
 62  
     public DesktopEncodingPortalURL(NavigationalState navState, PortalContext portalContext, String desktopRenderPipelinePath, String desktopActionPipelinePath, BasePortalURL base)
 63  
     {
 64  0
         super(navState, portalContext, base);
 65  0
         initializePipelinePaths( desktopRenderPipelinePath, desktopActionPipelinePath );
 66  0
     }
 67  
 
 68  
     public DesktopEncodingPortalURL(String characterEncoding, NavigationalState navState, PortalContext portalContext)
 69  
     {
 70  0
         super(characterEncoding, navState, portalContext);
 71  0
         initializePipelinePaths( null, class="keyword">null );
 72  0
     }
 73  
 
 74  
     public DesktopEncodingPortalURL(HttpServletRequest request, String characterEncoding, NavigationalState navState, PortalContext portalContext)
 75  
     {
 76  0
         super(request, characterEncoding, navState, portalContext);
 77  0
         initializePipelinePaths( null, class="keyword">null );
 78  0
     }
 79  
     
 80  
     private void initializePipelinePaths( String desktopRenderPipelinePath, String desktopActionPipelinePath )
 81  
     {
 82  0
         if ( desktopActionPipelinePath == null || desktopActionPipelinePath.length() == 0 )
 83  0
             desktopActionPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_ACTION_PIPELINE_PATH;
 84  0
         if ( desktopActionPipelinePath.charAt( 0 ) != '/' )
 85  0
             desktopActionPipelinePath = "/" + desktopActionPipelinePath;
 86  0
         if ( desktopActionPipelinePath.length() > 1 && desktopActionPipelinePath.charAt( desktopActionPipelinePath.length() -1 ) == '/' )
 87  0
             desktopActionPipelinePath = desktopActionPipelinePath.substring( 0, desktopActionPipelinePath.length() -1 );
 88  
 
 89  0
         if ( desktopRenderPipelinePath == null || desktopRenderPipelinePath.length() == 0 )
 90  0
             desktopRenderPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_RENDER_PIPELINE_PATH;
 91  0
         if ( desktopRenderPipelinePath.charAt( 0 ) != '/' )
 92  0
             desktopRenderPipelinePath = "/" + desktopRenderPipelinePath;
 93  0
         if ( desktopRenderPipelinePath.length() > 1 && desktopRenderPipelinePath.charAt( desktopRenderPipelinePath.length() -1 ) == '/' )
 94  0
             desktopRenderPipelinePath = desktopRenderPipelinePath.substring( 0, desktopRenderPipelinePath.length() -1 );
 95  
         
 96  0
         this.desktopRenderPipelinePath = desktopRenderPipelinePath;
 97  0
         this.desktopActionPipelinePath = desktopActionPipelinePath;        
 98  0
     }
 99  
 
 100  
     protected void decodeBasePath(HttpServletRequest request)
 101  
     {
 102  0
         super.decodeBasePath(request);
 103  0
         if ( this.baseActionPath == null )
 104  
         {
 105  0
             this.baseActionPath = contextPath + class="keyword">this.desktopActionPipelinePath;
 106  0
             this.baseRenderPath = contextPath + class="keyword">this.desktopRenderPipelinePath;
 107  
         }
 108  0
     }
 109  
     
 110  
     protected void decodePathAndNavigationalState(HttpServletRequest request)
 111  
     {
 112  0
         String path = null;
 113  0
         String encodedNavState = null;
 114  
 
 115  0
         String pathInfo = request.getPathInfo();
 116  0
         if (pathInfo != null)
 117  
         {
 118  0
             StringTokenizer tokenizer = new StringTokenizer(request.getPathInfo(),"/");
 119  0
             StringBuffer buffer = new StringBuffer();
 120  
             String token;
 121  0
             boolean foundNavState = false;
 122  0
             String navStatePrefix = getNavigationalStateParameterName() +":";
 123  0
             while (tokenizer.hasMoreTokens())
 124  
             {
 125  0
                 token = tokenizer.nextToken();
 126  0
                 if (!foundNavState && token.startsWith(navStatePrefix))
 127  
                 {
 128  0
                     foundNavState = true;
 129  0
                     if ( token.length() > navStatePrefix.length() )
 130  
                     {
 131  0
                         encodedNavState = token.substring(navStatePrefix.length());
 132  
                     }
 133  
                 }
 134  
                 else
 135  
                 {
 136  0
                     buffer.append("/");
 137  0
                     buffer.append(token);
 138  
                 }
 139  
             }
 140  0
             if ( buffer.length() > 0 )
 141  
             {
 142  0
                 path = buffer.toString();
 143  
             }
 144  
             else
 145  
             {
 146  0
                 path = "/";
 147  
             }
 148  
         }
 149  0
         setPath(path);
 150  0
         setEncodedNavigationalState(encodedNavState);
 151  0
     }
 152  
 
 153  
     protected String createPortletURL(String encodedNavState, boolean secure)
 154  
     {
 155  0
         return createPortletURL(encodedNavState, secure, null, false);
 156  
     }
 157  
     
 158  
     protected String createPortletURL(String encodedNavState, boolean secure, PortletWindow window, class="keyword">boolean action)
 159  
     {   
 160  0
         return createPortletURL(encodedNavState, secure, window, action, false, false);
 161  
     }
 162  
     
 163  
     protected String createPortletURL(String encodedNavState, boolean secure, PortletWindow window, class="keyword">boolean action, class="keyword">boolean resource, class="keyword">boolean desktopRequestNotAjax)
 164  
     {   
 165  0
         StringBuffer buffer = new StringBuffer("");
 166  0
         buffer.append(getBaseURL(secure));
 167  0
         if (action)
 168  
         {
 169  0
             buffer.append(this.baseActionPath);
 170  
         }
 171  
         else
 172  
         {
 173  0
             buffer.append(this.baseRenderPath);        
 174  
         }            
 175  0
         if ( encodedNavState != null )
 176  
         {
 177  0
             buffer.append("/");
 178  0
             buffer.append(getNavigationalStateParameterName());
 179  0
             buffer.append(":");
 180  0
             buffer.append(encodedNavState);
 181  
         }
 182  0
         if ( getPath() != null )
 183  
         {
 184  0
             buffer.append(getPath());
 185  
         }
 186  
         
 187  0
         if ( !resource )
 188  
         {
 189  0
         	if ( ! desktopRequestNotAjax )
 190  
             {
 191  0
         		PortletEntity pe = window.getPortletEntity();
 192  0
         		buffer.append( "?entity=" ).append( pe.getId() );
 193  
             
 194  0
         		PortletDefinition portlet = pe.getPortletDefinition();
 195  0
         		MutablePortletApplication app = (MutablePortletApplication)portlet.getPortletApplicationDefinition();
 196  0
         		String uniqueName = app.getName() + "::" + portlet.getName();
 197  0
         		buffer.append( "&portlet=" ).append( uniqueName );
 198  0
             }
 199  
         }
 200  
         else
 201  
         {
 202  0
             buffer.append("?encoder=desktop");
 203  
         }
 204  
 
 205  0
         return buffer.toString();
 206  
     }        
 207  
     
 208  
     public String createPortletURL(PortletWindow window, Map parameters, PortletMode mode, WindowState state, boolean action, class="keyword">boolean secure)
 209  
     {
 210  
         try
 211  
         {
 212  0
             boolean resource = !action && parameters.containsKey(PortalReservedParameters.PORTLET_RESOURCE_URL_REQUEST_PARAMETER);
 213  0
             boolean desktopRequestNotAjax = false;
 214  0
             if ( parameters.containsKey(JetspeedDesktop.DESKTOP_REQUEST_NOT_AJAX_PARAMETER) )
 215  
             {
 216  0
             	desktopRequestNotAjax = true;
 217  0
             	parameters.remove(JetspeedDesktop.DESKTOP_REQUEST_NOT_AJAX_PARAMETER);
 218  
             }
 219  0
             return createPortletURL(this.getNavigationalState().encode(window,parameters,mode,state,action), secure, window, action, resource, desktopRequestNotAjax);
 220  
         }
 221  0
         catch (UnsupportedEncodingException e)
 222  
         {
 223  
             // should never happen
 224  0
             e.printStackTrace();
 225  
             // to keep the compiler happy
 226  0
             return null;
 227  
         }
 228  
     }    
 229  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.