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 (file.getName().indexOf("-portlet") == -1)) {
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().indexOf("-theme") != -1)) {
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().indexOf("-web") != -1)) {
130
131 return true;
132 }
133
134 return false;
135 }
136
137 private static Log _log =
138 LogFactoryUtil.getLog(BaseAutoDeployListener.class);
139
140 }