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  
18  package org.apache.jetspeed.container.url.impl;
19  
20  import org.apache.jetspeed.container.state.NavigationalStateComponent;
21  import org.apache.jetspeed.pipeline.PipelineException;
22  import org.apache.jetspeed.pipeline.valve.AbstractValve;
23  import org.apache.jetspeed.pipeline.valve.ValveContext;
24  import org.apache.jetspeed.request.RequestContext;
25  import org.apache.jetspeed.desktop.JetspeedDesktop;
26  
27  /***
28   * Creates the PortalURL for the current Request
29   *
30   * @author <a href="mailto:ate@apache.org">Ate Douma</a>
31   * @version $Id: PortalURLValveImpl.java 588430 2007-10-26 00:08:07Z smilek $
32   */
33  public class PortalURLValveImpl extends AbstractValve
34  {
35      private NavigationalStateComponent navComponent;
36  
37      public PortalURLValveImpl(NavigationalStateComponent navComponent)
38      {
39          this.navComponent = navComponent;
40      }
41      
42      public void invoke(RequestContext request, ValveContext context)
43          throws PipelineException
44      {
45          try
46          {  
47              if ( request.getPortalURL() == null )
48              {
49                  String encoding = request.getRequestParameter(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER);
50                  if (encoding != null && encoding.equals(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER_VALUE))
51                  {
52                      request.setPortalURL(navComponent.createDesktopURL(request.getRequest(), request.getCharacterEncoding()));
53                      request.setAttribute( JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE, Boolean.TRUE );
54                  }
55                  else
56                  {
57                      request.setPortalURL(navComponent.createURL(request.getRequest(), request.getCharacterEncoding()));
58                  }
59                  
60              }
61          }
62          catch (Exception e)
63          {
64              throw new PipelineException(e);
65          }
66          // Pass control to the next Valve in the Pipeline
67          context.invokeNext( request );
68      }
69  
70      public String toString()
71      {
72          return "PortalURLValveImpl";
73      }
74  }