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