Package com.alibaba.citrus.util.templatelite.Template

Examples of com.alibaba.citrus.util.templatelite.Template.InputSource


                new BufferedInputStream(new ByteArrayInputStream(content.getBytes("ISO-8859-1"))), "default");
    }

    @Test
    public void getRelative_File() throws Exception {
        InputSource parentSource = new InputSource(new File("/aa/bb/cc.txt"));

        assertNull(parentSource.getRelative(null));
        assertNull(parentSource.getRelative("  "));

        inputSource = parentSource.getRelative(" b.txt ");
        assertEquals(new File("/aa/bb/b.txt").toURI().toURL().toExternalForm(), inputSource.systemId);

        inputSource = parentSource.getRelative(" /b.txt ");
        assertEquals(new File("/aa/bb/b.txt").toURI().toURL().toExternalForm(), inputSource.systemId);

        inputSource = parentSource.getRelative(" ../b.txt ");
        assertEquals(new File("/aa/b.txt").toURI().normalize().toURL().toExternalForm(), inputSource.systemId);

        inputSource = parentSource.getRelative(" ../../b.txt ");
        assertEquals(new File("/b.txt").toURI().normalize().toURL().toExternalForm(), inputSource.systemId);

        try {
            inputSource = parentSource.getRelative(" ../../../b.txt ");
            fail();
        } catch (IllegalPathException e) {
            assertThat(e, exception("../../../b.txt"));
        }
    }
View Full Code Here


        }
    }

    @Test
    public void getRelative_URL() throws Exception {
        InputSource parentSource = new InputSource(new URL("http://localhost:8080/aa/bb/cc.txt"));

        assertNull(parentSource.getRelative(null));
        assertNull(parentSource.getRelative("  "));

        inputSource = parentSource.getRelative("b.txt ");
        assertEquals("http://localhost:8080/aa/bb/b.txt", inputSource.systemId);

        inputSource = parentSource.getRelative("/b.txt ");
        assertEquals("http://localhost:8080/aa/bb/b.txt", inputSource.systemId);

        inputSource = parentSource.getRelative(" ../b.txt ");
        assertEquals("http://localhost:8080/aa/b.txt", inputSource.systemId);

        inputSource = parentSource.getRelative(" ../../b.txt ");
        assertEquals("http://localhost:8080/b.txt", inputSource.systemId);

        try {
            inputSource = parentSource.getRelative(" ../../../b.txt ");
            fail();
        } catch (IllegalPathException e) {
            assertThat(e, exception("../../../b.txt"));
        }
    }
View Full Code Here

    }

    @Test
    public void getRelative_Stream() throws Exception {
        FileInputStream f = new FileInputStream(new File(srcdir, "test05_param_gbk.txt"));
        InputSource parentSource = new InputSource(f, "test.txt");

        assertNull(parentSource.getRelative(null));
        assertNull(parentSource.getRelative("  "));

        assertNull(parentSource.getRelative("b.txt "));

        f.close();
    }
View Full Code Here

    @Test
    public void getReader() throws IOException {
        File f = new File(srcdir, "test05_param_gbk.txt");

        // file as input source
        inputSource = new InputSource(f);
        assertReader("GBK", f, f.toURI().toString());

        inputSource = new InputSource(new File(srcdir, "../templates/test05_param_gbk.txt"));
        assertReader("GBK", f, f.toURI().toString());

        // file: url as input source
        inputSource = new InputSource(f.toURI().toURL());
        assertReader("GBK", f, f.toURI().toURL().toExternalForm());

        // url as input source
        URL jarurl = copyFilesToJar("test.jar", "test05_param_gbk.txt", "gbk.txt");
        URL url = new URL("jar:" + jarurl.toExternalForm() + "!/gbk.txt");
        inputSource = new InputSource(url);
        assertReader("GBK", url, url.toExternalForm());

        // stream as input source
        inputSource = new InputSource(new ByteArrayInputStream("#@charset UTF-8\n\nhello".getBytes("UTF-8")),
                                      "utf8.txt");
        assertReader("UTF-8", null, "utf8.txt");

        // reader as input source
        inputSource = new InputSource(new StringReader("#@charset UTF-8\n\nhello"), "utf8.txt");
        assertReader(null, null, "utf8.txt");
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.util.templatelite.Template.InputSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.