| BaseAutoDeployListener.java |
1 /**
2 * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions 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.deploy.auto;
24
25 import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
26 import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
27
28 import java.io.File;
29 import java.io.IOException;
30
31 import java.util.zip.ZipFile;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 /**
37 * <a href="BaseAutoDeployListener.java.html"><b><i>View Source</i></b></a>
38 *
39 * @author Ivica Cardic
40 * @author Brian Wing Shun Chan
41 *
42 */
43 public abstract class BaseAutoDeployListener implements AutoDeployListener {
44
45 public boolean isMatchingFile(File file, String checkXmlFile)
46 throws AutoDeployException {
47
48 if (!isMatchingFileExtension(file)) {
49 return false;
50 }
51
52 ZipFile zipFile = null;
53
54 try {
55 zipFile = new ZipFile(file);
56
57 if (zipFile.getEntry(checkXmlFile) == null) {
58 if (_log.isDebugEnabled()) {
59 _log.debug(
60 file.getPath() + " does not have " + checkXmlFile);
61 }
62
63 return false;
64 }
65 else {
66 return true;
67 }
68 }
69 catch (IOException ioe) {
70 throw new AutoDeployException(ioe);
71 }
72 finally {
73 if (zipFile != null) {
74 try {
75 zipFile.close();
76 }
77 catch (IOException ioe) {
78 }
79 }
80 }
81 }
82
83 public boolean isMatchingFileExtension(File file) {
84 String fileName = file.getName().toLowerCase();
85
86 if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
87 if (_log.isDebugEnabled()) {
88 _log.debug(file.getPath() + " has a matching extension");
89 }
90
91 return true;
92 }
93 else {
94 if (_log.isDebugEnabled()) {
95 _log.debug(
96 file.getPath() + " does not have a matching extension");
97 }
98
99 return false;
100 }
101 }
102
103 public boolean isThemePlugin(File file) throws AutoDeployException {
104 if (isMatchingFile(file, "WEB-INF/liferay-look-and-feel.xml")) {
105 return true;
106 }
107
108 if ((isMatchingFile(
109 file, "WEB-INF/liferay-plugin-package.properties")) &&
110 (file.getName().indexOf("-theme") != -1)) {
111
112 return true;
113 }
114
115 return false;
116 }
117
118 public boolean isWebPlugin(File file) throws AutoDeployException {
119 if ((isMatchingFile(
120 file, "WEB-INF/liferay-plugin-package.properties")) &&
121 (file.getName().indexOf("-web") != -1)) {
122
123 return true;
124 }
125
126 return false;
127 }
128
129 private static Log _log = LogFactory.getLog(BaseAutoDeployListener.class);
130
131 }