1
22
23 package com.liferay.portal.deploy.auto.exploded.tomcat;
24
25 import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
26 import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
27 import com.liferay.portal.kernel.log.Log;
28 import com.liferay.portal.kernel.log.LogFactoryUtil;
29 import com.liferay.portal.kernel.util.FileUtil;
30 import com.liferay.portal.kernel.util.Validator;
31 import com.liferay.portal.kernel.xml.Document;
32 import com.liferay.portal.kernel.xml.Element;
33 import com.liferay.portal.kernel.xml.SAXReaderUtil;
34 import com.liferay.portal.util.PrefsPropsUtil;
35 import com.liferay.portal.util.PropsKeys;
36 import com.liferay.portal.util.PropsValues;
37
38 import java.io.File;
39
40
47 public abstract class BaseExplodedTomcatListener implements AutoDeployListener {
48
49 public void copyContextFile(File file) throws AutoDeployException {
50 try {
51 String tomcatConfDir = PrefsPropsUtil.getString(
52 PropsKeys.AUTO_DEPLOY_TOMCAT_CONF_DIR,
53 PropsValues.AUTO_DEPLOY_TOMCAT_CONF_DIR);
54
55 if (_log.isInfoEnabled()) {
56 _log.info(
57 "Copying file " + file.getPath() + " to " + tomcatConfDir);
58 }
59
60 FileUtil.copyFile(
61 file, new File(tomcatConfDir + "/" + file.getName()));
62 }
63 catch (Exception e) {
64 throw new AutoDeployException(e.getMessage());
65 }
66 }
67
68 public File getDocBaseDir(File file, String checkXmlFile)
69 throws AutoDeployException {
70
71 if (!isMatchingFileExtension(file)) {
72 return null;
73 }
74
75 String docBase = null;
76
77 try {
78 String content = FileUtil.read(file);
79
80 Document doc = SAXReaderUtil.read(content);
81
82 Element root = doc.getRootElement();
83
84 docBase = root.attributeValue("docBase");
85 }
86 catch (Exception e) {
87 throw new AutoDeployException(e);
88 }
89
90 if (Validator.isNull(docBase)) {
91 if (_log.isDebugEnabled()) {
92 _log.debug(
93 file.getPath() + " does not have a docBase defined");
94 }
95
96 return null;
97 }
98
99 File docBaseDir = new File(docBase);
100
101 if (!docBaseDir.exists()) {
102 if (_log.isDebugEnabled()) {
103 _log.debug(docBase + " does not exist");
104 }
105
106 return null;
107 }
108
109 if (!docBaseDir.isDirectory()) {
110 if (_log.isDebugEnabled()) {
111 _log.debug(docBase + " is not a directory");
112 }
113
114 return null;
115 }
116
117 if (!FileUtil.exists(docBase + "/" + checkXmlFile)) {
118 if (_log.isDebugEnabled()) {
119 _log.debug(docBase + " does not have " + checkXmlFile);
120 }
121
122 return null;
123 }
124
125 return docBaseDir;
126 }
127
128 public boolean isMatchingFileExtension(File file) {
129 if (file.getName().endsWith(".xml")) {
130 if (_log.isDebugEnabled()) {
131 _log.debug(file.getPath() + " has a matching extension");
132 }
133
134 return true;
135 }
136 else {
137 if (_log.isDebugEnabled()) {
138 _log.debug(
139 file.getPath() + " does not have a matching extension");
140 }
141
142 return false;
143 }
144 }
145
146 private static Log _log =
147 LogFactoryUtil.getLog(BaseExplodedTomcatListener.class);
148
149 }