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