01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: private NavigationalStateComponent navComponent;
35:
36: public PortalURLValveImpl(NavigationalStateComponent navComponent) {
37: this .navComponent = navComponent;
38: }
39:
40: public void invoke(RequestContext request, ValveContext context)
41: throws PipelineException {
42: try {
43: if (request.getPortalURL() == null) {
44: String encoding = request
45: .getRequestParameter(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER);
46: if (encoding != null
47: && encoding
48: .equals(JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER_VALUE)) {
49: request.setPortalURL(navComponent.createDesktopURL(
50: request.getRequest(), request
51: .getCharacterEncoding()));
52: request
53: .setAttribute(
54: JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE,
55: Boolean.TRUE);
56: } else {
57: request.setPortalURL(navComponent.createURL(request
58: .getRequest(), request
59: .getCharacterEncoding()));
60: }
61:
62: }
63: } catch (Exception e) {
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: return "PortalURLValveImpl";
72: }
73: }
|