%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.desktop.impl.DesktopEncoderRedirectValveImpl |
|
|
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.desktop.impl; |
|
18 | ||
19 | import java.io.IOException; |
|
20 | ||
21 | import org.apache.commons.logging.Log; |
|
22 | import org.apache.commons.logging.LogFactory; |
|
23 | import org.apache.jetspeed.desktop.JetspeedDesktop; |
|
24 | import org.apache.jetspeed.pipeline.PipelineException; |
|
25 | import org.apache.jetspeed.pipeline.valve.AbstractValve; |
|
26 | import org.apache.jetspeed.pipeline.valve.ValveContext; |
|
27 | import org.apache.jetspeed.request.RequestContext; |
|
28 | ||
29 | /** |
|
30 | * DesktopEncoderRedirect Valve |
|
31 | * |
|
32 | * if request parameter encoder=desktop is NOT defined, |
|
33 | * redirect to same url with /desktop pipeline, |
|
34 | * otherwise, |
|
35 | * just invoke next valve |
|
36 | * |
|
37 | * Used by the /render pipeline (desktop-render-pipeline) to allow |
|
38 | * render requests that are not initiated via desktop javascript code to result |
|
39 | * in a page level navigation to the /desktop pipeline with the correct portlet rendering |
|
40 | * indicated in the original url. The encoder=desktop request parameter |
|
41 | * is used by desktop javascript code to indicate that the request is an "official" |
|
42 | * desktop ajax request. |
|
43 | * |
|
44 | * @author <a href="mailto:smilek@apache.org">Steve Milek</a> |
|
45 | * @version $Id: $ |
|
46 | */ |
|
47 | public class DesktopEncoderRedirectValveImpl extends AbstractValve |
|
48 | { |
|
49 | 0 | protected Log log = LogFactory.getLog(DesktopEncoderRedirectValveImpl.class); |
50 | ||
51 | 0 | private String desktopPipelinePath = null; |
52 | 0 | private String desktopRenderPipelinePath = null; |
53 | ||
54 | public DesktopEncoderRedirectValveImpl( String desktopPipelinePath, String desktopRenderPipelinePath ) |
|
55 | 0 | { |
56 | 0 | if ( desktopPipelinePath == null || desktopPipelinePath.length() == 0 ) |
57 | 0 | desktopPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_PIPELINE_PATH; |
58 | 0 | if ( desktopPipelinePath.charAt( 0 ) != '/' ) |
59 | 0 | desktopPipelinePath = "/" + desktopPipelinePath; |
60 | 0 | if ( desktopPipelinePath.charAt( desktopPipelinePath.length() -1 ) != '/' ) |
61 | 0 | desktopPipelinePath = desktopPipelinePath + "/"; |
62 | ||
63 | 0 | if ( desktopRenderPipelinePath == null || desktopRenderPipelinePath.length() == 0 ) |
64 | 0 | desktopRenderPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_RENDER_PIPELINE_PATH; |
65 | 0 | if ( desktopRenderPipelinePath.charAt( 0 ) != '/' ) |
66 | 0 | desktopRenderPipelinePath = "/" + desktopRenderPipelinePath; |
67 | 0 | if ( desktopRenderPipelinePath.charAt( desktopRenderPipelinePath.length() -1 ) != '/' ) |
68 | 0 | desktopRenderPipelinePath = desktopRenderPipelinePath + "/"; |
69 | ||
70 | 0 | this.desktopPipelinePath = desktopPipelinePath; |
71 | 0 | this.desktopRenderPipelinePath = desktopRenderPipelinePath; |
72 | 0 | } |
73 | ||
74 | public void invoke( RequestContext request, ValveContext context ) |
|
75 | throws PipelineException |
|
76 | { |
|
77 | try |
|
78 | { |
|
79 | 0 | if ( request.getPortalURL() == null ) |
80 | { |
|
81 | 0 | String encoding = request.getRequestParameter(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER); |
82 | 0 | if (encoding == null || ! encoding.equals(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER_VALUE)) |
83 | { |
|
84 | // redirect to page url with render encoding |
|
85 | try |
|
86 | { |
|
87 | 0 | String queryString = request.getRequest().getQueryString(); |
88 | 0 | String location = request.getRequest().getRequestURI(); |
89 | 0 | if ( queryString != null && queryString.length() > 0 ) |
90 | 0 | location += "?" + queryString; |
91 | 0 | location = location.replaceAll( this.desktopRenderPipelinePath, class="keyword">this.desktopPipelinePath ); |
92 | //log.info( "DesktopEncoderRedirectValveImpl redirecting request-uri=" + request.getRequest().getRequestURI() + " location=" + location ); |
|
93 | 0 | request.getResponse().sendRedirect( location ); |
94 | } |
|
95 | 0 | catch (IOException ioe){} |
96 | 0 | return; |
97 | } |
|
98 | } |
|
99 | } |
|
100 | 0 | catch (Exception e) |
101 | { |
|
102 | 0 | throw new PipelineException(e); |
103 | 0 | } |
104 | // Pass control to the next Valve in the Pipeline |
|
105 | 0 | context.invokeNext( request ); |
106 | 0 | } |
107 | ||
108 | public String toString() |
|
109 | { |
|
110 | 0 | return "DesktopValve"; |
111 | } |
|
112 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |