View Javadoc

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 javax.servlet.http.HttpServletRequest;
20  
21  import org.apache.jetspeed.PortalContext;
22  import org.apache.jetspeed.container.state.NavigationalState;
23  import org.apache.jetspeed.container.url.BasePortalURL;
24  
25  /***
26   * QueryStringEncodingPortalURL encodes the NavigationalState as query parameter
27   * *
28   * @author <a href="mailto:ate@apache.org">Ate Douma</a>
29   * @version $Id: QueryStringEncodingPortalURL.java 516448 2007-03-09 16:25:47Z ate $
30   */
31  public class QueryStringEncodingPortalURL extends AbstractPortalURL
32  {
33      public QueryStringEncodingPortalURL(NavigationalState navState, PortalContext portalContext, BasePortalURL base)
34      {
35          super(navState, portalContext, base);
36      }
37  
38      public QueryStringEncodingPortalURL(NavigationalState navState, PortalContext portalContext)
39      {
40          super(navState, portalContext);
41      }
42  
43      public QueryStringEncodingPortalURL(String characterEncoding, NavigationalState navState, PortalContext portalContext)
44      {
45          super(characterEncoding, navState, portalContext);
46      }
47  
48      public QueryStringEncodingPortalURL(HttpServletRequest request, String characterEncoding, NavigationalState navState, PortalContext portalContext)
49      {
50          super(request, characterEncoding, navState, portalContext);
51      }
52  
53      protected void decodePathAndNavigationalState(HttpServletRequest request)
54      {
55          setEncodedNavigationalState(request.getParameter(getNavigationalStateParameterName()));
56          String path = null;
57          if (request.getPathInfo() != null)
58          {
59              path = request.getPathInfo();
60              int length = path.length();
61              if ( length > 1 && path.endsWith("/") )
62              {
63                  path = path.substring(0, length-1);
64              }
65          }
66          setPath(path);
67      }
68      
69      protected String createPortletURL(String encodedNavigationalState, boolean secure)
70      {
71          StringBuffer buffer = new StringBuffer(getBaseURL(secure));
72          buffer.append(getBasePath());
73          if ( getPath() != null )
74          {
75              buffer.append(getPath());
76          }
77          if ( encodedNavigationalState != null )
78          {
79              buffer.append("?");
80              buffer.append(getNavigationalStateParameterName());
81              buffer.append("=");
82              buffer.append(encodedNavigationalState);
83          }
84          return buffer.toString();
85      }    
86  }