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