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