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.zip;
16  
17  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
18  import com.liferay.portal.kernel.zip.ZipReader;
19  import com.liferay.portal.kernel.zip.ZipReaderFactory;
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.io.InputStream;
24  
25  /**
26   * <a href="ZipReaderFactoryImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Raymond Augé
29   */
30  public class ZipReaderFactoryImpl implements ZipReaderFactory {
31  
32      public ZipReader getZipReader(File file) {
33          ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
34  
35          Thread currentThread = Thread.currentThread();
36  
37          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
38  
39          try {
40              if (contextClassLoader != portalClassLoader) {
41                  currentThread.setContextClassLoader(portalClassLoader);
42              }
43  
44              return new ZipReaderImpl(file);
45          }
46          finally {
47              if (contextClassLoader != portalClassLoader) {
48                  currentThread.setContextClassLoader(contextClassLoader);
49              }
50          }
51      }
52  
53      public ZipReader getZipReader(InputStream inputStream) throws IOException {
54          ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
55  
56          Thread currentThread = Thread.currentThread();
57  
58          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
59  
60          try {
61              if (contextClassLoader != portalClassLoader) {
62                  currentThread.setContextClassLoader(portalClassLoader);
63              }
64  
65              return new ZipReaderImpl(inputStream);
66          }
67          finally {
68              if (contextClassLoader != portalClassLoader) {
69                  currentThread.setContextClassLoader(contextClassLoader);
70              }
71          }
72      }
73  
74  }