001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.upload;
016    
017    import com.liferay.portal.kernel.util.ProgressTracker;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.util.List;
021    import java.util.Map;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpSession;
025    
026    import org.apache.commons.fileupload.FileItem;
027    import org.apache.commons.fileupload.FileItemFactory;
028    import org.apache.commons.fileupload.FileUploadException;
029    import org.apache.commons.fileupload.servlet.ServletFileUpload;
030    
031    /**
032     * @author     Brian Myunghun Kim
033     * @author     Brian Wing Shun Chan
034     * @deprecated As of 7.0.0, with no direct replacement
035     */
036    @Deprecated
037    public class LiferayFileUpload extends ServletFileUpload {
038    
039            public static final String FILE_NAME =
040                    LiferayFileUpload.class.getName() + "_FILE_NAME";
041    
042            public static final String PERCENT = ProgressTracker.PERCENT;
043    
044            public LiferayFileUpload(
045                    FileItemFactory fileItemFactory, HttpServletRequest request) {
046    
047                    super(fileItemFactory);
048    
049                    _session = request.getSession();
050            }
051    
052            @Override
053            public List<FileItem> parseRequest(HttpServletRequest request)
054                    throws FileUploadException {
055    
056                    _session.removeAttribute(LiferayFileUpload.PERCENT);
057    
058                    return super.parseRequest(request);
059            }
060    
061            /**
062             * @deprecated As of 6.1.0
063             */
064            @Deprecated
065            @Override
066            @SuppressWarnings("rawtypes")
067            protected FileItem createItem(Map headers, boolean formField)
068                    throws FileUploadException {
069    
070                    LiferayFileItem item = (LiferayFileItem)super.createItem(
071                            headers, formField);
072    
073                    String fileName = item.getFileName();
074    
075                    if (Validator.isNotNull(fileName)) {
076                            _session.setAttribute(LiferayFileUpload.FILE_NAME, fileName);
077                    }
078    
079                    return item;
080            }
081    
082            private final HttpSession _session;
083    
084    }