org.richfaces.request.MultipartRequest25 Maven / Gradle / Ivy
The newest version!
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.richfaces.request;
import java.io.IOException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.richfaces.exception.FileUploadException;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.model.UploadedFile;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
public class MultipartRequest25 extends BaseMultipartRequest {
private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
private static final Function, Object> MULTIMAP_VALUE_TRANSFORMER = new Function, Object>() {
public Object apply(Collection input) {
if (input.isEmpty()) {
return null;
}
if (input.size() == 1) {
return Iterables.get(input, 0);
}
return input.toArray(new String[input.size()]);
}
};
private MultipartRequestParser requestParser;
private ResponseState responseState;
private Iterable uploadedFiles;
private Multimap params;
public MultipartRequest25(HttpServletRequest request, String uploadId, ProgressControl progressControl,
MultipartRequestParser requestParser) {
super(request, uploadId, progressControl);
this.requestParser = requestParser;
}
private void parseIfNecessary() {
if (responseState != null) {
return;
}
try {
requestParser.parse();
uploadedFiles = requestParser.getUploadedFiles();
params = requestParser.getParameters();
responseState = ResponseState.ok;
} catch (FileUploadException e) {
LOGGER.error(e.getMessage(), e);
responseState = ResponseState.serverError;
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Enumeration getParameterNames() {
Collection