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
030 public abstract class BaseAutoDeployListener implements AutoDeployListener {
031
032 public boolean isExtPlugin(File file) {
033 String fileName = file.getName();
034
035 if (fileName.contains("-ext")) {
036 return true;
037 }
038
039 return false;
040 }
041
042 public boolean isHookPlugin(File file) throws AutoDeployException {
043 String fileName = file.getName();
044
045 if (isMatchingFile(file, "WEB-INF/liferay-hook.xml") &&
046 !isMatchingFile(file, "WEB-INF/liferay-portlet.xml") &&
047 !fileName.contains("-theme") && !fileName.contains("-web")) {
048
049 return true;
050 }
051
052 return false;
053 }
054
055 public boolean isLiferayPackage(File file) {
056 String fileName = file.getName();
057
058 if (fileName.endsWith(".lpkg")) {
059 return true;
060 }
061
062 return false;
063 }
064
065 public boolean isMatchingFile(File file, String checkXmlFile)
066 throws AutoDeployException {
067
068 if (!isMatchingFileExtension(file)) {
069 return false;
070 }
071
072 ZipFile zipFile = null;
073
074 try {
075 zipFile = new ZipFile(file);
076
077 if (zipFile.getEntry(checkXmlFile) == null) {
078 if (_log.isDebugEnabled()) {
079 _log.debug(
080 file.getPath() + " does not have " + checkXmlFile);
081 }
082
083 return false;
084 }
085 else {
086 return true;
087 }
088 }
089 catch (IOException ioe) {
090 throw new AutoDeployException(ioe);
091 }
092 finally {
093 if (zipFile != null) {
094 try {
095 zipFile.close();
096 }
097 catch (IOException ioe) {
098 }
099 }
100 }
101 }
102
103 public boolean isMatchingFileExtension(File file) {
104 String fileName = file.getName();
105
106 fileName = fileName.toLowerCase();
107
108 if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
109 if (_log.isDebugEnabled()) {
110 _log.debug(file.getPath() + " has a matching extension");
111 }
112
113 return true;
114 }
115 else {
116 if (_log.isDebugEnabled()) {
117 _log.debug(
118 file.getPath() + " does not have a matching extension");
119 }
120
121 return false;
122 }
123 }
124
125 public boolean isThemePlugin(File file) throws AutoDeployException {
126 if (isMatchingFile(file, "WEB-INF/liferay-look-and-feel.xml")) {
127 return true;
128 }
129
130 String fileName = file.getName();
131
132 if (isMatchingFile(file, "WEB-INF/liferay-plugin-package.properties") &&
133 fileName.contains("-theme")) {
134
135 return true;
136 }
137
138 return false;
139 }
140
141 public boolean isWebPlugin(File file) throws AutoDeployException {
142 String fileName = file.getName();
143
144 if (isMatchingFile(file, "WEB-INF/liferay-plugin-package.properties") &&
145 fileName.contains("-web")) {
146
147 return true;
148 }
149
150 return false;
151 }
152
153 private static Log _log = LogFactoryUtil.getLog(
154 BaseAutoDeployListener.class);
155
156 }