1 /* 2 * Copyright 2002-2005 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.web.multipart.support; 18 19 import java.util.Collections; 20 import java.util.Iterator; 21 import java.util.Map; 22 23 import javax.servlet.http.HttpServletRequest; 24 import javax.servlet.http.HttpServletRequestWrapper; 25 26 import org.springframework.web.multipart.MultipartFile; 27 import org.springframework.web.multipart.MultipartHttpServletRequest; 28 29 /** 30 * Abstract base implementation of the MultipartHttpServletRequest interface. 31 * Provides management of pre-generated MultipartFile instances. 32 * 33 * @author Juergen Hoeller 34 * @since 06.10.2003 35 */ 36 public abstract class AbstractMultipartHttpServletRequest extends HttpServletRequestWrapper 37 implements MultipartHttpServletRequest { 38 39 private Map multipartFiles; 40 41 42 /** 43 * Wrap the given HttpServletRequest in a MultipartHttpServletRequest. 44 * @param request the request to wrap 45 */ 46 protected AbstractMultipartHttpServletRequest(HttpServletRequest request) { 47 super(request); 48 } 49 50 /** 51 * Set a Map with parameter names as keys and MultipartFile objects as values. 52 * To be invoked by subclasses on initialization. 53 */ 54 protected void setMultipartFiles(Map multipartFiles) { 55 this.multipartFiles = Collections.unmodifiableMap(multipartFiles); 56 } 57 58 59 public Iterator getFileNames() { 60 return this.multipartFiles.keySet().iterator(); 61 } 62 63 public MultipartFile getFile(String name) { 64 return (MultipartFile) this.multipartFiles.get(name); 65 } 66 67 public Map getFileMap() { 68 return this.multipartFiles; 69 } 70 71 } 72