Search in sources :

Example 46 with Context

use of com.google.cloud.dialogflow.v2.Context in project webtools.servertools by eclipse.

the class TomcatVersionHelper method loadContextFile.

private static Context loadContextFile(File contextFile) {
    FileInputStream fis = null;
    Context context = null;
    if (contextFile != null && contextFile.exists()) {
        try {
            Factory factory = new Factory();
            factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
            fis = new FileInputStream(contextFile);
            context = (Context) factory.loadDocument(fis);
            if (context != null) {
                String path = context.getPath();
                // If path attribute is not set, derive from file name
                if (path == null) {
                    String fileName = contextFile.getName();
                    path = fileName.substring(0, fileName.length() - ".xml".length());
                    if ("ROOT".equals(path))
                        path = "";
                    // Assuming this use for "#" since Tomcat has "reserved" this use of "#" since 5.5.
                    path = path.replace('#', '/');
                    context.setPath("/" + path);
                }
            }
        } catch (Exception e) {
            // may be a spurious xml file in the host dir?
            Trace.trace(Trace.FINER, "Unable to read context " + contextFile.getAbsolutePath());
        } finally {
            try {
                fis.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return context;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 47 with Context

use of com.google.cloud.dialogflow.v2.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 48 with Context

use of com.google.cloud.dialogflow.v2.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 49 with Context

use of com.google.cloud.dialogflow.v2.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 50 with Context

use of com.google.cloud.dialogflow.v2.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)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)39 CoreException (org.eclipse.core.runtime.CoreException)34 Context (org.osate.aadl2.Context)31 BoolExpr (com.microsoft.z3.BoolExpr)25 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)18 Test (org.junit.Test)18 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 List (java.util.List)16 Map (java.util.Map)15 Solver (com.microsoft.z3.Solver)13 File (java.io.File)13 IOException (java.io.IOException)11 IPath (org.eclipse.core.runtime.IPath)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 Feature (org.osate.aadl2.Feature)11 FileNotFoundException (java.io.FileNotFoundException)10