001    /**
002     * Copyright (c) 2000-2010 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.util.PortalClassLoaderUtil;
018    import com.liferay.portal.kernel.zip.ZipReader;
019    import com.liferay.portal.kernel.zip.ZipReaderFactory;
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            public ZipReader getZipReader(File file) {
031                    ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
032    
033                    Thread currentThread = Thread.currentThread();
034    
035                    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
036    
037                    try {
038                            if (contextClassLoader != portalClassLoader) {
039                                    currentThread.setContextClassLoader(portalClassLoader);
040                            }
041    
042                            return new ZipReaderImpl(file);
043                    }
044                    finally {
045                            if (contextClassLoader != portalClassLoader) {
046                                    currentThread.setContextClassLoader(contextClassLoader);
047                            }
048                    }
049            }
050    
051            public ZipReader getZipReader(InputStream inputStream) throws IOException {
052                    ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
053    
054                    Thread currentThread = Thread.currentThread();
055    
056                    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
057    
058                    try {
059                            if (contextClassLoader != portalClassLoader) {
060                                    currentThread.setContextClassLoader(portalClassLoader);
061                            }
062    
063                            return new ZipReaderImpl(inputStream);
064                    }
065                    finally {
066                            if (contextClassLoader != portalClassLoader) {
067                                    currentThread.setContextClassLoader(contextClassLoader);
068                            }
069                    }
070            }
071    
072    }