001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.rendering.util;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.roller.util.URLUtilities;
025:
026: /**
027: * Represents a request for a weblog resource file.
028: *
029: * /roller-ui/rendering/resources/*
030: */
031: public class WeblogResourceRequest extends WeblogRequest {
032:
033: private static Log log = LogFactory
034: .getLog(WeblogResourceRequest.class);
035:
036: // lightweight attributes
037: private String resourcePath = null;
038:
039: public WeblogResourceRequest() {
040: }
041:
042: /**
043: * Construct the WeblogResourceRequest by parsing the incoming url
044: */
045: public WeblogResourceRequest(HttpServletRequest request)
046: throws InvalidRequestException {
047:
048: // let our parent take care of their business first
049: // parent determines weblog handle and locale if specified
050: super (request);
051:
052: String servlet = request.getServletPath();
053:
054: // we only want the path info left over from after our parents parsing
055: String pathInfo = this .getPathInfo();
056:
057: // parse the request object and figure out what we've got
058: log.debug("parsing path " + pathInfo);
059:
060: /*
061: * any path is okay ...
062: *
063: * /<path>/<to>/<resource>
064: */
065: if (pathInfo != null && pathInfo.trim().length() > 1) {
066:
067: this .resourcePath = pathInfo;
068: if (pathInfo.startsWith("/")) {
069: this .resourcePath = pathInfo.substring(1);
070: }
071:
072: // Fix for ROL-1065: even though a + should mean space in a URL, folks
073: // who upload files with plus signs expect them to work without
074: // escaping. This is essentially what other systems do (e.g. JIRA) to
075: // enable this.
076: this .resourcePath = this .resourcePath.replaceAll("\\+",
077: "%2B");
078:
079: // now we really decode the URL
080: this .resourcePath = URLUtilities.decode(this .resourcePath);
081:
082: } else {
083: throw new InvalidRequestException(
084: "invalid resource path info, "
085: + request.getRequestURL());
086: }
087:
088: if (log.isDebugEnabled()) {
089: log.debug("resourcePath = " + this .resourcePath);
090: }
091: }
092:
093: public String getResourcePath() {
094: return resourcePath;
095: }
096:
097: public void setResourcePath(String resourcePath) {
098: this .resourcePath = resourcePath;
099: }
100:
101: protected boolean isLocale(String potentialLocale) {
102: // We don't support locales in the resource Servlet so we've got to
103: // keep parent from treating upload sub-directory name as a locale.
104: return false;
105: }
106: }
|