use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class TomcatVersionHelper method getCatalinaServerInstance.
/**
* Gets a ServerInstance for the specified server.xml, Service name,
* and Host name. Returns null if server.xml does not exist
* or an error occurs.
*
* @param serverXml path to previously published server.xml
* @param serviceName name of Service to be used by this instance or null
* @param hostName name of Host to be used by this instance or null
* @return ServerInstance for specified server.xml using specified
* Service and Host names. null if server.xml does not exist.
* @throws FileNotFoundException should not occur since existence is tested
* @throws IOException if there is an error reading server.xml
* @throws SAXException if there is a syntax error in server.xml
*/
public static ServerInstance getCatalinaServerInstance(IPath serverXml, String serviceName, String hostName) throws FileNotFoundException, IOException, SAXException {
ServerInstance serverInstance = null;
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
File serverFile = serverXml.toFile();
if (serverFile.exists()) {
Server server = (Server) factory.loadDocument(new FileInputStream(serverFile));
serverInstance = new ServerInstance(server, serviceName, hostName);
IPath contextPath = serverInstance.getContextXmlDirectory(serverXml.removeLastSegments(1));
File contextDir = contextPath.toFile();
if (contextDir.exists()) {
Map<File, Context> projectContexts = new HashMap<File, Context>();
loadSeparateContextFiles(contextPath.toFile(), factory, projectContexts);
// add any separately saved contexts
Host host = serverInstance.getHost();
Collection contexts = projectContexts.values();
Iterator iter = contexts.iterator();
while (iter.hasNext()) {
Context context = (Context) iter.next();
host.importNode(context.getElementNode(), true);
}
// TODO Add handling for non-project contexts when there removal can be addressed
}
}
return serverInstance;
}
use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.
the class Tomcat55Configuration 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, 7);
// check for catalina.policy to verify that this is a v5.5 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);
// load context.xml file
File file = path.append("context.xml").toFile();
if (file.exists())
contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(file)));
else
contextDocument = null;
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);
// load properties file
file = path.append("catalina.properties").toFile();
if (file.exists())
propertiesFile = TomcatVersionHelper.getFileContents(new FileInputStream(file));
else
propertiesFile = null;
monitor.worked(1);
if (monitor.isCanceled())
return;
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not load Tomcat v5.5 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 Tomcat55Configuration 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, 1200);
// 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 context.xml
file = folder.getFile("context.xml");
if (file.exists()) {
in = file.getContents();
contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
} else
contextDocument = null;
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);
// load catalina.properties
file = folder.getFile("catalina.properties");
if (file.exists()) {
in = file.getContents();
propertiesFile = TomcatVersionHelper.getFileContents(in);
} else
propertiesFile = null;
monitor.worked(200);
if (monitor.isCanceled())
throw new Exception("Cancelled");
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not reload Tomcat v5.5 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 Tomcat70Configuration 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, 7);
// check for catalina.policy to verify that this is a v5.5 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);
File file = path.append("context.xml").toFile();
if (file.exists())
contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(file)));
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);
// load properties file
file = path.append("catalina.properties").toFile();
if (file.exists())
propertiesFile = TomcatVersionHelper.getFileContents(new FileInputStream(file));
else
propertiesFile = null;
monitor.worked(1);
if (monitor.isCanceled())
return;
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not load Tomcat v7.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 Tomcat80Configuration 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, 1200);
// 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 context.xml
file = folder.getFile("context.xml");
if (file.exists()) {
in = file.getContents();
contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
} else
contextDocument = null;
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);
// load catalina.properties
file = folder.getFile("catalina.properties");
if (file.exists()) {
in = file.getContents();
propertiesFile = TomcatVersionHelper.getFileContents(in);
} else
propertiesFile = null;
monitor.worked(200);
if (monitor.isCanceled())
throw new Exception("Cancelled");
monitor.done();
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not reload Tomcat v8.0 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));
}
}
Aggregations