use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class Tomcat32Configuration method load.
/**
* @see TomcatConfiguration#load(IPath, IProgressMonitor)
*/
public void load(IPath path, IProgressMonitor monitor) throws CoreException {
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.loadingTask, 5);
// check for tomcat.policy to verify that this is a v3.2 config
InputStream in = new FileInputStream(path.append("tomcat.policy").toFile());
in.read();
in.close();
monitor.worked(1);
// create server.xml
serverFactory = new Factory();
serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server32");
server = (Server) serverFactory.loadDocument(new FileInputStream(path.append("server.xml").toFile()));
serverInstance = new ServerInstance(server);
monitor.worked(1);
webAppDocument = new WebAppDocument(path.append("web.xml"));
monitor.worked(1);
tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(path.append("tomcat-users.xml").toFile())));
monitor.worked(1);
// load policy file
policyFile = TomcatVersionHelper.getFileContents(new FileInputStream(path.append("tomcat.policy").toFile()));
monitor.worked(1);
if (monitor.isCanceled())
return;
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Could not load Tomcat v3.2 configuration from " + path.toOSString() + ": " + e.getMessage());
throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, path.toOSString()), e));
}
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class Tomcat32Configuration method cleanupServer.
protected IStatus cleanupServer(IPath confDir, IPath installDir, IProgressMonitor monitor) {
MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, Messages.cleanupServerTask, null);
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.cleanupServerTask, 200);
try {
monitor.subTask(Messages.detectingRemovedProjects);
// Try to read old server configuration
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server32");
File serverFile = confDir.append("conf").append("server.xml").toFile();
if (serverFile.exists()) {
Server oldServer = (Server) factory.loadDocument(new FileInputStream(serverFile));
ServerInstance oldInstance = new ServerInstance(oldServer);
// Collect paths of old web modules managed by WTP
Set<String> oldPaths = new HashSet<String>();
Context[] contexts = oldInstance.getContexts();
if (contexts != null) {
for (int i = 0; i < contexts.length; i++) {
String source = contexts[i].getSource();
if (source != null && source.length() > 0) {
oldPaths.add(contexts[i].getPath());
}
}
}
// Remove paths for web modules that are staying around
List modules = getWebModules();
int size = modules.size();
for (int i = 0; i < size; i++) {
WebModule module = (WebModule) modules.get(i);
oldPaths.remove(module.getPath());
}
monitor.worked(100);
// Delete work directories for managed web modules that have gone away
if (oldPaths.size() > 0) {
IProgressMonitor subMonitor = ProgressUtil.getSubMonitorFor(monitor, 100);
subMonitor.beginTask(Messages.deletingContextFilesTask, oldPaths.size() * 100);
Iterator iter = oldPaths.iterator();
while (iter.hasNext()) {
String oldPath = (String) iter.next();
// Delete work directory associated with the removed context if it is within confDir.
// If it is outside of confDir, assume user is going to manage it.
Context ctx = oldInstance.getContext(oldPath);
IPath ctxWorkPath = oldInstance.getContextWorkDirectory(confDir, ctx);
if (confDir.isPrefixOf(ctxWorkPath)) {
File ctxWorkDir = ctxWorkPath.toFile();
if (ctxWorkDir.exists() && ctxWorkDir.isDirectory()) {
IStatus[] results = PublishHelper.deleteDirectory(ctxWorkDir, ProgressUtil.getSubMonitorFor(monitor, 100));
if (results.length > 0) {
Trace.trace(Trace.SEVERE, "Could not delete work directory " + ctxWorkDir.getPath() + " for removed context " + oldPath);
for (int i = 0; i < results.length; i++) {
ms.add(results[i]);
}
}
} else
monitor.worked(100);
} else
monitor.worked(100);
}
subMonitor.done();
} else {
monitor.worked(100);
}
} else // Else no server.xml. Assume first publish to new temp directory
{
monitor.worked(200);
}
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Server cleaned");
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Could not cleanup server at " + confDir.toOSString() + ": " + e.getMessage());
ms.add(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCleanupServer, new String[] { e.getLocalizedMessage() }), e));
}
monitor.done();
return ms;
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class Tomcat40Configuration method load.
/**
* @see TomcatConfiguration#load(IPath, IProgressMonitor)
*/
public void load(IPath path, IProgressMonitor monitor) throws CoreException {
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.loadingTask, 5);
// check for catalina.policy to verify that this is a v4.0 config
InputStream in = new FileInputStream(path.append("catalina.policy").toFile());
in.read();
in.close();
monitor.worked(1);
serverFactory = new Factory();
serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
server = (Server) serverFactory.loadDocument(new FileInputStream(path.append("server.xml").toFile()));
serverInstance = new ServerInstance(server, null, null);
monitor.worked(1);
webAppDocument = new WebAppDocument(path.append("web.xml"));
monitor.worked(1);
tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(path.append("tomcat-users.xml").toFile())));
monitor.worked(1);
// load policy file
policyFile = TomcatVersionHelper.getFileContents(new FileInputStream(path.append("catalina.policy").toFile()));
monitor.worked(1);
if (monitor.isCanceled())
return;
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not load Tomcat v4.0 configuration from " + path.toOSString() + ": " + e.getMessage());
throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, path.toOSString()), e));
}
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class Tomcat41Configuration method load.
/**
* @see TomcatConfiguration#load(IFolder, IProgressMonitor)
*/
public void load(IFolder folder, IProgressMonitor monitor) throws CoreException {
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.loadingTask, 800);
// check for catalina.policy to verify that this is a v4.0 config
IFile file = folder.getFile("catalina.policy");
if (!file.exists())
throw new CoreException(new Status(IStatus.WARNING, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, folder.getFullPath().toOSString()), null));
// load server.xml
file = folder.getFile("server.xml");
InputStream in = file.getContents();
serverFactory = new Factory();
serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
server = (Server) serverFactory.loadDocument(in);
serverInstance = new ServerInstance(server, null, null);
monitor.worked(200);
// load web.xml
file = folder.getFile("web.xml");
webAppDocument = new WebAppDocument(file);
monitor.worked(200);
// load tomcat-users.xml
file = folder.getFile("tomcat-users.xml");
in = file.getContents();
tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
monitor.worked(200);
// load catalina.policy
file = folder.getFile("catalina.policy");
in = file.getContents();
policyFile = TomcatVersionHelper.getFileContents(in);
monitor.worked(200);
if (monitor.isCanceled())
throw new Exception("Cancelled");
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not reload Tomcat v4.1 configuration from: " + folder.getFullPath() + ": " + e.getMessage());
throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, folder.getFullPath().toOSString()), e));
}
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class Tomcat41Configuration method load.
/**
* @see TomcatConfiguration#load(IPath, IProgressMonitor)
*/
public void load(IPath path, IProgressMonitor monitor) throws CoreException {
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.loadingTask, 5);
// check for catalina.policy to verify that this is a v4.0 config
InputStream in = new FileInputStream(path.append("catalina.policy").toFile());
in.read();
in.close();
monitor.worked(1);
serverFactory = new Factory();
serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
server = (Server) serverFactory.loadDocument(new FileInputStream(path.append("server.xml").toFile()));
serverInstance = new ServerInstance(server, null, null);
monitor.worked(1);
webAppDocument = new WebAppDocument(path.append("web.xml"));
monitor.worked(1);
tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(path.append("tomcat-users.xml").toFile())));
monitor.worked(1);
// load policy file
policyFile = TomcatVersionHelper.getFileContents(new FileInputStream(path.append("catalina.policy").toFile()));
monitor.worked(1);
if (monitor.isCanceled())
return;
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not load Tomcat v4.0 configuration from " + path.toOSString() + ": " + e.getMessage());
throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, path.toOSString()), e));
}
}
Aggregations