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