Search in sources :

Example 11 with Factory

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(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 v8.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);
        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 v8.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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException)

Example 12 with Factory

use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.

the class Tomcat90Configuration 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 v9.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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) CoreException(org.eclipse.core.runtime.CoreException)

Example 13 with Factory

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(IFolder, IProgressMonitor)
 */
public void load(IFolder folder, IProgressMonitor monitor) throws CoreException {
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.loadingTask, 800);
        // check for tomcat.policy to verify that this is a v3.2 config
        IFile file = folder.getFile("tomcat.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.server32");
        server = (Server) serverFactory.loadDocument(in);
        serverInstance = new ServerInstance(server);
        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 tomcat.policy
        file = folder.getFile("tomcat.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.SEVERE, "Could not load Tomcat v3.2 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));
    }
}
Also used : InputSource(org.xml.sax.InputSource) IFile(org.eclipse.core.resources.IFile) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory)

Example 14 with Factory

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(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.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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) CoreException(org.eclipse.core.runtime.CoreException)

Example 15 with Factory

use of org.eclipse.jst.server.tomcat.core.internal.xml.Factory in project webtools.servertools by eclipse.

the class Tomcat85Configuration 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 v8.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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)34 FileInputStream (java.io.FileInputStream)25 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)24 IStatus (org.eclipse.core.runtime.IStatus)23 Status (org.eclipse.core.runtime.Status)23 InputStream (java.io.InputStream)22 CoreException (org.eclipse.core.runtime.CoreException)21 InputSource (org.xml.sax.InputSource)20 ByteArrayInputStream (java.io.ByteArrayInputStream)18 IFile (org.eclipse.core.resources.IFile)18 File (java.io.File)11 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)11 Server (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server)8 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 IPath (org.eclipse.core.runtime.IPath)6 MultiStatus (org.eclipse.core.runtime.MultiStatus)5 SAXException (org.xml.sax.SAXException)5 JarFile (java.util.jar.JarFile)3 HashMap (java.util.HashMap)2