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 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 private static Log _log = LogFactory.getLog(BaseAutoDeployListener.class);
119
120 }