001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.ui.web.rest; 021 022import java.util.Collections; 023import java.util.Enumeration; 024import java.util.HashMap; 025import java.util.Map; 026 027import javax.servlet.http.HttpServletRequest; 028import javax.servlet.http.HttpServletRequestWrapper; 029 030import org.nuxeo.ecm.platform.url.api.DocumentView; 031 032/** 033 * TODO: document me. Used in get methods to get request params to the filter. Encapuslates the request into a wrapper 034 * to do so. 035 * 036 * @author tiry 037 */ 038public class FancyURLRequestWrapper extends HttpServletRequestWrapper { 039 040 private DocumentView docView; 041 042 public FancyURLRequestWrapper(HttpServletRequest request) { 043 super(request); 044 } 045 046 public FancyURLRequestWrapper(HttpServletRequest request, DocumentView docView) { 047 super(request); 048 this.docView = docView; 049 } 050 051 @Override 052 @SuppressWarnings("unchecked") 053 public Map<String, String[]> getParameterMap() { 054 Map<String, String[]> result = super.getParameterMap(); 055 if (result == null) { 056 result = new HashMap<String, String[]>(); 057 } else { 058 // copy parameter map from parent class to avoid modifying the 059 // original 060 result = new HashMap<String, String[]>(result); 061 } 062 if (docView != null) { 063 for (Map.Entry<String, String> param : docView.getParameters().entrySet()) { 064 result.put(param.getKey(), new String[] { param.getValue() }); 065 } 066 } 067 return result; 068 } 069 070 @Override 071 public String[] getParameterValues(String name) { 072 if (docView != null) { 073 String value = docView.getParameter(name); 074 if (value != null) { 075 return new String[] { value }; 076 } 077 } 078 return super.getParameterValues(name); 079 } 080 081 @Override 082 public String getParameter(String name) { 083 if (docView != null) { 084 String value = docView.getParameter(name); 085 if (value != null) { 086 return value; 087 } 088 } 089 return super.getParameter(name); 090 } 091 092 @Override 093 public Enumeration<String> getParameterNames() { 094 return Collections.enumeration(getParameterMap().keySet()); 095 } 096 097}