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.kernel.deploy.auto;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  
20  import java.io.File;
21  import java.io.IOException;
22  
23  import java.util.zip.ZipFile;
24  
25  /**
26   * <a href="BaseAutoDeployListener.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Ivica Cardic
29   * @author Brian Wing Shun Chan
30   */
31  public abstract class BaseAutoDeployListener implements AutoDeployListener {
32  
33      public boolean isExtPlugin(File file) {
34          if (file.getName().contains("-ext")) {
35              return true;
36          }
37  
38          return false;
39      }
40  
41      public boolean isHookPlugin(File file) throws AutoDeployException {
42          if ((isMatchingFile(
43                  file, "WEB-INF/liferay-plugin-package.properties")) &&
44              (file.getName().contains("-hook")) &&
45              (!file.getName().contains("-portlet"))) {
46  
47              return true;
48          }
49  
50          return false;
51      }
52  
53      public boolean isMatchingFile(File file, String checkXmlFile)
54          throws AutoDeployException {
55  
56          if (!isMatchingFileExtension(file)) {
57              return false;
58          }
59  
60          ZipFile zipFile = null;
61  
62          try {
63              zipFile = new ZipFile(file);
64  
65              if (zipFile.getEntry(checkXmlFile) == null) {
66                  if (_log.isDebugEnabled()) {
67                      _log.debug(
68                          file.getPath() + " does not have " + checkXmlFile);
69                  }
70  
71                  return false;
72              }
73              else {
74                  return true;
75              }
76          }
77          catch (IOException ioe) {
78              throw new AutoDeployException(ioe);
79          }
80          finally {
81              if (zipFile != null) {
82                  try {
83                      zipFile.close();
84                  }
85                  catch (IOException ioe) {
86                  }
87              }
88          }
89      }
90  
91      public boolean isMatchingFileExtension(File file) {
92          String fileName = file.getName().toLowerCase();
93  
94          if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
95              if (_log.isDebugEnabled()) {
96                  _log.debug(file.getPath() + " has a matching extension");
97              }
98  
99              return true;
100         }
101         else {
102             if (_log.isDebugEnabled()) {
103                 _log.debug(
104                     file.getPath() + " does not have a matching extension");
105             }
106 
107             return false;
108         }
109     }
110 
111     public boolean isThemePlugin(File file) throws AutoDeployException {
112         if (isMatchingFile(file, "WEB-INF/liferay-look-and-feel.xml")) {
113             return true;
114         }
115 
116         if ((isMatchingFile(
117                 file, "WEB-INF/liferay-plugin-package.properties")) &&
118             (file.getName().contains("-theme"))) {
119 
120             return true;
121         }
122 
123         return false;
124     }
125 
126     public boolean isWebPlugin(File file) throws AutoDeployException {
127         if ((isMatchingFile(
128                 file, "WEB-INF/liferay-plugin-package.properties")) &&
129             (file.getName().contains("-web"))) {
130 
131             return true;
132         }
133 
134         return false;
135     }
136 
137     private static Log _log = LogFactoryUtil.getLog(
138         BaseAutoDeployListener.class);
139 
140 }