Java Code Examples for org.apache.catalina.WebResource#isVirtual()

The following examples show how to use org.apache.catalina.WebResource#isVirtual() . 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: AbstractTestResourceSet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public final void testWriteDirA() {
    WebResource d1 = resourceRoot.getResource(getMount() + "/d1");
    InputStream is = new ByteArrayInputStream("test".getBytes());
    if (d1.exists()) {
        Assert.assertFalse(resourceRoot.write(getMount() + "/d1", is, false));
    } else if (d1.isVirtual()) {
        Assert.assertTrue(resourceRoot.write(
                getMount() + "/d1", is, false));
        File file = new File(getBaseDir(), "d1");
        Assert.assertTrue(file.exists());
        Assert.assertTrue(file.delete());
    } else {
        Assert.fail("Unhandled condition in unit test");
    }
}
 
Example 2
Source File: StandardRoot.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected final WebResource getResourceInternal(String path,
        boolean useClassLoaderResources) {
    WebResource result = null;
    WebResource virtual = null;
    WebResource mainEmpty = null;
    for (List<WebResourceSet> list : allResources) {
        for (WebResourceSet webResourceSet : list) {
            if (!useClassLoaderResources &&  !webResourceSet.getClassLoaderOnly() ||
                    useClassLoaderResources && !webResourceSet.getStaticOnly()) {
                result = webResourceSet.getResource(path);
                if (result.exists()) {
                    return result;
                }
                if (virtual == null) {
                    if (result.isVirtual()) {
                        virtual = result;
                    } else if (main.equals(webResourceSet)) {
                        mainEmpty = result;
                    }
                }
            }
        }
    }

    // Use the first virtual result if no real result was found
    if (virtual != null) {
        return virtual;
    }

    // Default is empty resource in main resources
    return mainEmpty;
}
 
Example 3
Source File: AbstractTestResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public final void testMkdirDirA() {
    WebResource d1 = resourceRoot.getResource(getMount() + "/d1");
    if (d1.exists()) {
        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1"));
    } else if (d1.isVirtual()) {
        Assert.assertTrue(resourceRoot.mkdir(getMount() + "/d1"));
        File file = new File(getBaseDir(), "d1");
        Assert.assertTrue(file.isDirectory());
        Assert.assertTrue(file.delete());
    } else {
        Assert.fail("Unhandled condition in unit test");
    }
}
 
Example 4
Source File: AbstractTestResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public final void testMkdirDirB() {
    WebResource d1 = resourceRoot.getResource(getMount() + "/d1/");
    if (d1.exists()) {
        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1/"));
    } else if (d1.isVirtual()) {
        Assert.assertTrue(resourceRoot.mkdir(getMount() + "/d1/"));
        File file = new File(getBaseDir(), "d1");
        Assert.assertTrue(file.isDirectory());
        Assert.assertTrue(file.delete());
    } else {
        Assert.fail("Unhandled condition in unit test");
    }
}
 
Example 5
Source File: AbstractTestResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public final void testWriteDirB() {
    WebResource d1 = resourceRoot.getResource(getMount() + "/d1/");
    InputStream is = new ByteArrayInputStream("test".getBytes());
    if (d1.exists() || d1.isVirtual()) {
        Assert.assertFalse(resourceRoot.write(getMount() + "/d1/", is, false));
    } else {
        Assert.fail("Unhandled condition in unit test");
    }
}