001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not 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.
015 */
016package org.ametys.plugins.workspaces.cmis;
017
018import javax.servlet.http.HttpServletRequest;
019import javax.servlet.http.HttpServletRequestWrapper;
020
021import org.apache.commons.lang3.StringUtils;
022
023/**
024 * A wrapper for HttpServletRequest that correct the servletPath
025 *
026 */
027public class CmisHttpServletRequest extends HttpServletRequestWrapper
028{
029    private String _servletPath;
030    
031    /**
032     * default constructor
033     * @param request the HttpServletRequest to wrap
034     * @param source the cocoon matcher (without the ending slash)
035     */
036    public CmisHttpServletRequest(HttpServletRequest request, String source)
037    {
038        super(request);
039        String tmp = StringUtils.substringAfter(request.getRequestURI(), request.getContextPath());
040        _servletPath = tmp.substring(0, tmp.indexOf(source) + source.length());
041    }
042
043    @Override
044    public String getServletPath()
045    {
046        return _servletPath;
047    }
048}