001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.container.url.impl;
018:
019: import java.util.StringTokenizer;
020:
021: import javax.servlet.http.HttpServletRequest;
022:
023: import org.apache.jetspeed.PortalContext;
024: import org.apache.jetspeed.container.state.NavigationalState;
025: import org.apache.jetspeed.container.url.BasePortalURL;
026:
027: /**
028: * PathInfoEncodingPortalURL encodes the NavigationalState as PathInfo element
029: * *
030: * @author <a href="mailto:ate@apache.org">Ate Douma</a>
031: * @version $Id: PathInfoEncodingPortalURL.java 605989 2007-12-20 18:26:54Z ate $
032: */
033: public class PathInfoEncodingPortalURL extends AbstractPortalURL {
034: public PathInfoEncodingPortalURL(NavigationalState navState,
035: PortalContext portalContext, BasePortalURL base) {
036: super (navState, portalContext, base);
037: }
038:
039: public PathInfoEncodingPortalURL(NavigationalState navState,
040: PortalContext portalContext) {
041: super (navState, portalContext);
042: }
043:
044: public PathInfoEncodingPortalURL(String characterEncoding,
045: NavigationalState navState, PortalContext portalContext) {
046: super (characterEncoding, navState, portalContext);
047: }
048:
049: public PathInfoEncodingPortalURL(HttpServletRequest request,
050: String characterEncoding, NavigationalState navState,
051: PortalContext portalContext) {
052: super (request, characterEncoding, navState, portalContext);
053: }
054:
055: protected void decodePathAndNavigationalState(
056: HttpServletRequest request) {
057: String path = null;
058: String encodedNavState = null;
059:
060: String pathInfo = request.getPathInfo();
061: if (pathInfo != null) {
062: StringTokenizer tokenizer = new StringTokenizer(request
063: .getPathInfo(), "/");
064: StringBuffer buffer = new StringBuffer();
065: String token;
066: boolean foundNavState = false;
067: String navStatePrefix = getNavigationalStateParameterName()
068: + ":";
069: while (tokenizer.hasMoreTokens()) {
070: token = tokenizer.nextToken();
071: if (!foundNavState && token.startsWith(navStatePrefix)) {
072: foundNavState = true;
073: if (token.length() > navStatePrefix.length()) {
074: encodedNavState = token
075: .substring(navStatePrefix.length());
076: }
077: } else {
078: buffer.append("/");
079: buffer.append(token);
080: }
081: }
082: if (buffer.length() > 0) {
083: path = buffer.toString();
084: } else {
085: path = "/";
086: }
087: }
088: setPath(path);
089: setEncodedNavigationalState(encodedNavState);
090: }
091:
092: protected String createPortletURL(String encodedNavState,
093: boolean secure) {
094: StringBuffer buffer = new StringBuffer(getBaseURL(secure));
095: buffer.append(getBasePath());
096: if (encodedNavState != null) {
097: buffer.append("/");
098: buffer.append(getNavigationalStateParameterName());
099: buffer.append(":");
100: buffer.append(encodedNavState);
101: }
102: if (getPath() != null) {
103: buffer.append(getPath());
104: }
105: return buffer.toString();
106: }
107:
108: public boolean isPathInfoEncodingNavState() {
109: return true;
110: }
111: }
|