1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }