2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.upload;
\r
17 import com.liferay.portal.kernel.util.ProgressTracker;
\r
18 import com.liferay.portal.kernel.util.Validator;
\r
20 import java.util.ArrayList;
\r
21 import java.util.List;
\r
22 import java.util.Map;
\r
24 import javax.servlet.http.HttpServletRequest;
\r
25 import javax.servlet.http.HttpSession;
\r
27 import org.apache.commons.fileupload.FileItem;
\r
28 import org.apache.commons.fileupload.FileItemFactory;
\r
29 import org.apache.commons.fileupload.FileUploadException;
\r
30 import org.apache.commons.fileupload.servlet.ServletFileUpload;
\r
33 * @author Brian Myunghun Kim
\r
34 * @author Brian Wing Shun Chan
\r
36 public class LiferayFileUpload extends ServletFileUpload {
\r
38 public static final String FILE_NAME =
\r
39 LiferayFileUpload.class.getName() + "_FILE_NAME";
\r
41 public static final String PERCENT = ProgressTracker.PERCENT;
\r
43 public LiferayFileUpload(
\r
44 FileItemFactory fileItemFactory, HttpServletRequest request) {
\r
46 super(fileItemFactory);
\r
48 _session = request.getSession();
\r
52 public List<LiferayFileItem> parseRequest(HttpServletRequest request)
\r
53 throws FileUploadException {
\r
55 _session.removeAttribute(LiferayFileUpload.FILE_NAME);
\r
56 _session.removeAttribute(LiferayFileUpload.PERCENT);
\r
58 return super.parseRequest(request);
\r
65 @SuppressWarnings("rawtypes")
\r
66 protected FileItem createItem(Map headers, boolean formField)
\r
67 throws FileUploadException {
\r
69 LiferayFileItem item = (LiferayFileItem)super.createItem(
\r
70 headers, formField);
\r
72 String fileName = item.getFileName();
\r
74 if (Validator.isNotNull(fileName)) {
\r
75 _session.setAttribute(LiferayFileUpload.FILE_NAME, fileName);
\r
81 private HttpSession _session;
\r