001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.zip;
016    
017    import com.liferay.portal.kernel.zip.ZipReader;
018    import com.liferay.portal.kernel.zip.ZipReaderFactory;
019    import com.liferay.portal.util.ClassLoaderUtil;
020    
021    import java.io.File;
022    import java.io.IOException;
023    import java.io.InputStream;
024    
025    /**
026     * @author Raymond Augé
027     */
028    public class ZipReaderFactoryImpl implements ZipReaderFactory {
029    
030            @Override
031            public ZipReader getZipReader(File file) {
032                    ClassLoader portalClassLoader = ClassLoaderUtil.getPortalClassLoader();
033    
034                    ClassLoader contextClassLoader =
035                            ClassLoaderUtil.getContextClassLoader();
036    
037                    try {
038                            if (contextClassLoader != portalClassLoader) {
039                                    ClassLoaderUtil.setContextClassLoader(portalClassLoader);
040                            }
041    
042                            return new ZipReaderImpl(file);
043                    }
044                    finally {
045                            if (contextClassLoader != portalClassLoader) {
046                                    ClassLoaderUtil.setContextClassLoader(contextClassLoader);
047                            }
048                    }
049            }
050    
051            @Override
052            public ZipReader getZipReader(InputStream inputStream) throws IOException {
053                    ClassLoader portalClassLoader = ClassLoaderUtil.getPortalClassLoader();
054    
055                    ClassLoader contextClassLoader =
056                            ClassLoaderUtil.getContextClassLoader();
057    
058                    try {
059                            if (contextClassLoader != portalClassLoader) {
060                                    ClassLoaderUtil.setContextClassLoader(portalClassLoader);
061                            }
062    
063                            return new ZipReaderImpl(inputStream);
064                    }
065                    finally {
066                            if (contextClassLoader != portalClassLoader) {
067                                    ClassLoaderUtil.setContextClassLoader(contextClassLoader);
068                            }
069                    }
070            }
071    
072    }