Java Code Examples for org.apache.catalina.core.StandardContext#getParent()

The following examples show how to use org.apache.catalina.core.StandardContext#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreContextAppender.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Print Context Values. <ul><li> Special handling to default workDir.
 * </li><li> Don't save path at external context.xml </li><li> Don't
 * generate docBase for host.appBase webapps <LI></ul>
 *
 * @see org.apache.catalina.storeconfig.StoreAppender#isPrintValue(java.lang.Object,
 *      java.lang.Object, java.lang.String,
 *      org.apache.catalina.storeconfig.StoreDescription)
 */
@Override
public boolean isPrintValue(Object bean, Object bean2, String attrName,
        StoreDescription desc) {
    boolean isPrint = super.isPrintValue(bean, bean2, attrName, desc);
    if (isPrint) {
        StandardContext context = ((StandardContext) bean);
        if ("workDir".equals(attrName)) {
            String defaultWorkDir = getDefaultWorkDir(context);
            isPrint = !defaultWorkDir.equals(context.getWorkDir());
        } else if ("path".equals(attrName)) {
            isPrint = desc.isStoreSeparate()
                        && desc.isExternalAllowed()
                        && context.getConfigFile() == null;
        } else if ("docBase".equals(attrName)) {
            Container host = context.getParent();
            if (host instanceof StandardHost) {
                File appBase = getAppBase(((StandardHost) host));
                File docBase = getDocBase(context,appBase);
                isPrint = !appBase.equals(docBase.getParentFile());
            }
        }
    }
    return isPrint;
}
 
Example 2
Source File: StoreContextAppender.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Make default Work Dir.
 *
 * @param context The context
 * @return The default working directory for the context.
 */
protected String getDefaultWorkDir(StandardContext context) {
    String defaultWorkDir = null;
    String contextWorkDir = context.getName();
    if (contextWorkDir.length() == 0)
        contextWorkDir = "_";
    if (contextWorkDir.startsWith("/"))
        contextWorkDir = contextWorkDir.substring(1);

    Container host = context.getParent();
    if (host instanceof StandardHost) {
        String hostWorkDir = ((StandardHost) host).getWorkDir();
        if (hostWorkDir != null) {
            defaultWorkDir = hostWorkDir + File.separator + contextWorkDir;
        } else {
            String engineName = context.getParent().getParent().getName();
            String hostName = context.getParent().getName();
            defaultWorkDir = "work" + File.separator + engineName
                    + File.separator + hostName + File.separator
                    + contextWorkDir;
        }
    }
    return defaultWorkDir;
}
 
Example 3
Source File: HugeGraphStudio.java    From hugegraph-studio with Apache License 2.0 6 votes vote down vote up
private static StandardContext configureWarFile(Tomcat tomcat,
                                                final String warFile,
                                                final String appBase)
        throws ServletException, IOException {

    if (warFile != null && warFile.length() > 0) {
        StandardContext context = (StandardContext) tomcat.addWebapp(appBase,
                                  new File(warFile).getAbsolutePath());
        Host host = (Host) context.getParent();
        File appBaseDirectory = host.getAppBaseFile();
        if (!appBaseDirectory.exists()) {
            appBaseDirectory.mkdirs();
        }
        context.setUnpackWAR(true);
        if (context.getJarScanner() instanceof StandardJarScanner) {
            ((StandardJarScanner) context.getJarScanner())
                    .setScanAllDirectories(true);
        }
        return context;
    }

    return null;
}
 
Example 4
Source File: Contexts.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static String getHostname(final StandardContext ctx) {
    String hostName = null;
    final Container parentHost = ctx.getParent();
    if (parentHost != null) {
        hostName = parentHost.getName();
    }
    if ((hostName == null) || (hostName.length() < 1)) {
        hostName = "_";
    }
    return hostName;
}
 
Example 5
Source File: StandardContextSF.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Store the specified context element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aContext Context to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext,
        StoreDescription parentDesc) throws Exception {
    if (aContext instanceof StandardContext) {
        StandardContext context = (StandardContext) aContext;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = context.findLifecycleListeners();
        ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
        for (LifecycleListener listener : listeners) {
            if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
                listenersArray.add(listener);
            }
        }
        storeElementArray(aWriter, indent, listenersArray.toArray());

        // Store nested <Valve> elements
        Valve valves[] = context.getPipeline().getValves();
        storeElementArray(aWriter, indent, valves);

        // Store nested <Loader> elements
        Loader loader = context.getLoader();
        storeElement(aWriter, indent, loader);

        // Store nested <Manager> elements
        if (context.getCluster() == null || !context.getDistributable()) {
            Manager manager = context.getManager();
            storeElement(aWriter, indent, manager);
        }

        // Store nested <Realm> element
        Realm realm = context.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            // @TODO is this case possible?
            if (context.getParent() != null) {
                parentRealm = context.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested resources
        WebResourceRoot resources = context.getResources();
        storeElement(aWriter, indent, resources);

        // Store nested <WrapperListener> elements
        String wLifecycles[] = context.findWrapperLifecycles();
        getStoreAppender().printTagArray(aWriter, "WrapperListener",
                indent + 2, wLifecycles);
        // Store nested <WrapperLifecycle> elements
        String wListeners[] = context.findWrapperListeners();
        getStoreAppender().printTagArray(aWriter, "WrapperLifecycle",
                indent + 2, wListeners);

        // Store nested <Parameter> elements
        ApplicationParameter[] appParams = context
                .findApplicationParameters();
        storeElementArray(aWriter, indent, appParams);

        // Store nested naming resources elements (EJB,Resource,...)
        NamingResourcesImpl nresources = context.getNamingResources();
        storeElement(aWriter, indent, nresources);

        // Store nested watched resources <WatchedResource>
        String[] wresources = context.findWatchedResources();
        wresources = filterWatchedResources(context, wresources);
        getStoreAppender().printTagArray(aWriter, "WatchedResource",
                indent + 2, wresources);

        // Store nested <JarScanner> elements
        JarScanner jarScanner = context.getJarScanner();
        storeElement(aWriter, indent, jarScanner);

        // Store nested <CookieProcessor> elements
        CookieProcessor cookieProcessor = context.getCookieProcessor();
        storeElement(aWriter, indent, cookieProcessor);
    }
}