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