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.aggregator;
18  
19  import org.apache.jetspeed.PortalReservedParameters;
20  import org.apache.jetspeed.pipeline.PipelineException;
21  import org.apache.jetspeed.pipeline.valve.AbstractValve;
22  import org.apache.jetspeed.pipeline.valve.ValveContext;
23  import org.apache.jetspeed.request.RequestContext;
24  
25  /***
26   * FileServerValve
27   *
28   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
29   * @version $Id: $
30   */
31  public class FileServerValve extends AbstractValve
32  {
33      private String portletName;
34      private String portletEntity;
35      
36      public FileServerValve(String portletName, String portletEntity)
37      {
38          this.portletName = portletName;
39          this.portletEntity = portletEntity;
40      }
41          
42      public void invoke( RequestContext request, ValveContext context )
43          throws PipelineException
44      {
45          try
46          {
47              String entity = request.getRequestParameter(PortalReservedParameters.PORTLET_ENTITY);
48              if (entity == null)
49              {
50                  entity = (String)request.getAttribute(PortalReservedParameters.PORTLET_ENTITY);
51              }
52              if (entity == null)
53              {
54                  request.setAttribute(PortalReservedParameters.PORTLET_ENTITY, portletEntity);
55              }        
56  
57              String name = request.getRequestParameter(PortalReservedParameters.PORTLET);
58              if (name == null)
59              {
60                  name = (String)request.getAttribute(PortalReservedParameters.PORTLET);
61              }
62              if (name == null)
63              {
64                  request.setAttribute(PortalReservedParameters.PORTLET, portletName);
65              }        
66          }
67          catch (Exception e)
68          {
69              throw new PipelineException(e);
70          }
71          // Pass control to the next Valve in the Pipeline
72          context.invokeNext( request );
73      }
74  
75      public String toString()
76      {
77          return "FileServerValve";
78      }
79  }