001
014
015 package com.liferay.portal.kernel.deploy.auto;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import java.io.File;
021 import java.io.IOException;
022
023 import java.util.zip.ZipFile;
024
025
029 public abstract class BaseAutoDeployListener implements AutoDeployListener {
030
031 public boolean isExtPlugin(File file) {
032 if (file.getName().contains("-ext")) {
033 return true;
034 }
035
036 return false;
037 }
038
039 public boolean isHookPlugin(File file) throws AutoDeployException {
040 if ((isMatchingFile(
041 file, "WEB-INF/liferay-plugin-package.properties")) &&
042 (file.getName().contains("-hook")) &&
043 (!file.getName().contains("-portlet"))) {
044
045 return true;
046 }
047
048 return false;
049 }
050
051 public boolean isMatchingFile(File file, String checkXmlFile)
052 throws AutoDeployException {
053
054 if (!isMatchingFileExtension(file)) {
055 return false;
056 }
057
058 ZipFile zipFile = null;
059
060 try {
061 zipFile = new ZipFile(file);
062
063 if (zipFile.getEntry(checkXmlFile) == null) {
064 if (_log.isDebugEnabled()) {
065 _log.debug(
066 file.getPath() + " does not have " + checkXmlFile);
067 }
068
069 return false;
070 }
071 else {
072 return true;
073 }
074 }
075 catch (IOException ioe) {
076 throw new AutoDeployException(ioe);
077 }
078 finally {
079 if (zipFile != null) {
080 try {
081 zipFile.close();
082 }
083 catch (IOException ioe) {
084 }
085 }
086 }
087 }
088
089 public boolean isMatchingFileExtension(File file) {
090 String fileName = file.getName().toLowerCase();
091
092 if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
093 if (_log.isDebugEnabled()) {
094 _log.debug(file.getPath() + " has a matching extension");
095 }
096
097 return true;
098 }
099 else {
100 if (_log.isDebugEnabled()) {
101 _log.debug(
102 file.getPath() + " does not have a matching extension");
103 }
104
105 return false;
106 }
107 }
108
109 public boolean isThemePlugin(File file) throws AutoDeployException {
110 if (isMatchingFile(file, "WEB-INF/liferay-look-and-feel.xml")) {
111 return true;
112 }
113
114 if ((isMatchingFile(
115 file, "WEB-INF/liferay-plugin-package.properties")) &&
116 (file.getName().contains("-theme"))) {
117
118 return true;
119 }
120
121 return false;
122 }
123
124 public boolean isWebPlugin(File file) throws AutoDeployException {
125 if ((isMatchingFile(
126 file, "WEB-INF/liferay-plugin-package.properties")) &&
127 (file.getName().contains("-web"))) {
128
129 return true;
130 }
131
132 return false;
133 }
134
135 private static Log _log = LogFactoryUtil.getLog(
136 BaseAutoDeployListener.class);
137
138 }