1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.upload;
16  
17  import com.liferay.portal.kernel.util.ProgressTracker;
18  import com.liferay.portal.kernel.util.Validator;
19  
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpSession;
25  
26  import org.apache.commons.fileupload.FileItem;
27  import org.apache.commons.fileupload.FileItemFactory;
28  import org.apache.commons.fileupload.FileUploadException;
29  import org.apache.commons.fileupload.servlet.ServletFileUpload;
30  
31  /**
32   * <a href="LiferayFileUpload.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Myunghun Kim
35   * @author Brian Wing Shun Chan
36   */
37  public class LiferayFileUpload extends ServletFileUpload {
38  
39      public static final String FILE_NAME =
40          LiferayFileUpload.class.getName() + "_FILE_NAME";
41  
42      public static final String PERCENT = ProgressTracker.PERCENT;
43  
44      public LiferayFileUpload(
45          FileItemFactory fileItemFactory, HttpServletRequest request) {
46  
47          super(fileItemFactory);
48  
49          _session = request.getSession();
50      }
51  
52      public List<LiferayFileItem> parseRequest(HttpServletRequest request)
53          throws FileUploadException {
54  
55          _session.removeAttribute(LiferayFileUpload.FILE_NAME);
56          _session.removeAttribute(LiferayFileUpload.PERCENT);
57  
58          return super.parseRequest(request);
59      }
60  
61      /**
62       * @deprecated
63       */
64      @SuppressWarnings("rawtypes")
65      protected FileItem createItem(Map headers, boolean formField)
66          throws FileUploadException {
67  
68          LiferayFileItem item = (LiferayFileItem)super.createItem(
69              headers, formField);
70  
71          String fileName = item.getFileName();
72  
73          if (Validator.isNotNull(fileName)) {
74              _session.setAttribute(LiferayFileUpload.FILE_NAME, fileName);
75          }
76  
77          return item;
78      }
79  
80      private HttpSession _session;
81  
82  }