1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.deploy.auto;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  
28  import java.io.File;
29  import java.io.IOException;
30  
31  import java.util.zip.ZipFile;
32  
33  /**
34   * <a href="BaseAutoDeployListener.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Ivica Cardic
37   * @author Brian Wing Shun Chan
38   */
39  public abstract class BaseAutoDeployListener implements AutoDeployListener {
40  
41      public boolean isExtPlugin(File file) {
42          if (file.getName().contains("-ext")) {
43              return true;
44          }
45  
46          return false;
47      }
48  
49      public boolean isHookPlugin(File file) throws AutoDeployException {
50          if ((isMatchingFile(
51                  file, "WEB-INF/liferay-plugin-package.properties")) &&
52              (file.getName().contains("-hook")) &&
53              (!file.getName().contains("-portlet"))) {
54  
55              return true;
56          }
57  
58          return false;
59      }
60  
61      public boolean isMatchingFile(File file, String checkXmlFile)
62          throws AutoDeployException {
63  
64          if (!isMatchingFileExtension(file)) {
65              return false;
66          }
67  
68          ZipFile zipFile = null;
69  
70          try {
71              zipFile = new ZipFile(file);
72  
73              if (zipFile.getEntry(checkXmlFile) == null) {
74                  if (_log.isDebugEnabled()) {
75                      _log.debug(
76                          file.getPath() + " does not have " + checkXmlFile);
77                  }
78  
79                  return false;
80              }
81              else {
82                  return true;
83              }
84          }
85          catch (IOException ioe) {
86              throw new AutoDeployException(ioe);
87          }
88          finally {
89              if (zipFile != null) {
90                  try {
91                      zipFile.close();
92                  }
93                  catch (IOException ioe) {
94                  }
95              }
96          }
97      }
98  
99      public boolean isMatchingFileExtension(File file) {
100         String fileName = file.getName().toLowerCase();
101 
102         if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
103             if (_log.isDebugEnabled()) {
104                 _log.debug(file.getPath() + " has a matching extension");
105             }
106 
107             return true;
108         }
109         else {
110             if (_log.isDebugEnabled()) {
111                 _log.debug(
112                     file.getPath() + " does not have a matching extension");
113             }
114 
115             return false;
116         }
117     }
118 
119     public boolean isThemePlugin(File file) throws AutoDeployException {
120         if (isMatchingFile(file, "WEB-INF/liferay-look-and-feel.xml")) {
121             return true;
122         }
123 
124         if ((isMatchingFile(
125                 file, "WEB-INF/liferay-plugin-package.properties")) &&
126             (file.getName().contains("-theme"))) {
127 
128             return true;
129         }
130 
131         return false;
132     }
133 
134     public boolean isWebPlugin(File file) throws AutoDeployException {
135         if ((isMatchingFile(
136                 file, "WEB-INF/liferay-plugin-package.properties")) &&
137             (file.getName().contains("-web"))) {
138 
139             return true;
140         }
141 
142         return false;
143     }
144 
145     private static Log _log =
146         LogFactoryUtil.getLog(BaseAutoDeployListener.class);
147 
148 }