Search in sources :

Example 21 with Context

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

the class TomcatVersionHelper method addCatalinaContextConfig.

/**
 * If the specified Context is linked to a project, try to
 * update it with any configuration from a META-INF/context.xml found
 * relative to the specified web applications directory and context docBase.
 *
 * @param webappsDir Path to server's web applications directory.
 * @param context Context object to receive context.xml contents.
 * @param ms MultiStatus object to receive error status.
 * @return Returns true if context is modified.
 */
private static boolean addCatalinaContextConfig(IPath webappsDir, Context context, MultiStatus ms) {
    boolean modified = false;
    String source = context.getSource();
    if (source != null && source.length() > 0) {
        File docBase = new File(context.getDocBase());
        if (!docBase.isAbsolute())
            docBase = new File(webappsDir.toOSString(), docBase.getPath());
        try {
            Context contextConfig = loadCatalinaContextConfig(docBase);
            if (null != contextConfig) {
                if (context.hasChildNodes())
                    context.removeChildren();
                contextConfig.copyChildrenTo(context);
                Map attrs = contextConfig.getAttributes();
                Iterator iter = attrs.keySet().iterator();
                while (iter.hasNext()) {
                    String name = (String) iter.next();
                    if (!name.equalsIgnoreCase("path") && !name.equalsIgnoreCase("docBase") && !name.equalsIgnoreCase("source")) {
                        String value = (String) attrs.get(name);
                        context.setAttributeValue(name, value);
                    }
                }
                modified = true;
            }
        } catch (Exception e) {
            String contextPath = context.getPath();
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
            Trace.trace(Trace.SEVERE, "Error reading context.xml file for " + contextPath, e);
            IStatus s = new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadContextXml, contextPath), e);
            ms.add(s);
        }
    }
    return modified;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Iterator(java.util.Iterator) JarFile(java.util.jar.JarFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 22 with Context

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

the class TomcatVersionHelper method loadSeparateContextFiles.

private static void loadSeparateContextFiles(File contextDir, Factory factory, Map<File, Context> projectContexts) {
    File[] contextFiles = contextDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".xml");
        }
    });
    for (int j = 0; j < contextFiles.length; j++) {
        File ctx = contextFiles[j];
        Context context = loadContextFile(ctx);
        if (context != null) {
            // TODO Handle non-project contexts when their removal can be addressed
            String memento = context.getSource();
            if (memento != null) {
                projectContexts.put(ctx, context);
            }
        }
    }
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) FilenameFilter(java.io.FilenameFilter) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 23 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context 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;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Iterator(java.util.Iterator) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) Collection(java.util.Collection) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) JarFile(java.util.jar.JarFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 24 with Context

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

the class Tomcat50Configuration method modifyWebModule.

/**
 * Change a web module.
 * @param index int
 * @param docBase java.lang.String
 * @param path java.lang.String
 * @param reloadable boolean
 */
public void modifyWebModule(int index, String docBase, String path, boolean reloadable) {
    try {
        Context context = serverInstance.getContext(index);
        if (context != null) {
            context.setPath(path);
            context.setDocBase(docBase);
            context.setReloadable(reloadable ? "true" : "false");
            isServerDirty = true;
            WebModule module = new WebModule(path, docBase, null, reloadable);
            firePropertyChangeEvent(MODIFY_WEB_MODULE_PROPERTY, new Integer(index), module);
        }
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error modifying web module " + index, e);
    }
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) CoreException(org.eclipse.core.runtime.CoreException)

Example 25 with Context

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

the class Tomcat55Configuration method modifyWebModule.

/**
 * Change a web module.
 * @param index int
 * @param docBase java.lang.String
 * @param path java.lang.String
 * @param reloadable boolean
 */
public void modifyWebModule(int index, String docBase, String path, boolean reloadable) {
    try {
        Context context = serverInstance.getContext(index);
        if (context != null) {
            context.setPath(path);
            context.setDocBase(docBase);
            context.setReloadable(reloadable ? "true" : "false");
            isServerDirty = true;
            WebModule module = new WebModule(path, docBase, null, reloadable);
            firePropertyChangeEvent(MODIFY_WEB_MODULE_PROPERTY, new Integer(index), module);
        }
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error modifying web module " + index, e);
    }
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)35 Test (org.junit.Test)24 BoolExpr (com.microsoft.z3.BoolExpr)23 List (java.util.List)20 IOException (java.io.IOException)18 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)18 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 HashMap (java.util.HashMap)16 File (java.io.File)14 Map (java.util.Map)14 ArrayList (java.util.ArrayList)13 Solver (com.microsoft.z3.Solver)12 Status (com.microsoft.z3.Status)12 IPath (org.eclipse.core.runtime.IPath)12 IStatus (org.eclipse.core.runtime.IStatus)12 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 Z3Exception (com.microsoft.z3.Z3Exception)9