Package org.apache.tiles.definition

Examples of org.apache.tiles.definition.UrlDefinitionsFactory$CompatibilityDefinitionsImpl


     * @since 2.1.1
     */
    protected LocaleDefinitionsFactory instantiateDefinitionsFactory(TilesApplicationContext applicationContext,
            TilesRequestContextFactory contextFactory,
            LocaleResolver resolver) {
        return new UrlDefinitionsFactory();
    }
View Full Code Here


     * @since 2.1.1
     */
    protected LocaleDefinitionsFactory instantiateDefinitionsFactory(TilesApplicationContext applicationContext,
            TilesRequestContextFactory contextFactory,
            LocaleResolver resolver) {
        return new UrlDefinitionsFactory();
    }
View Full Code Here

    /**
     * Tests reloading definitions impl.
     */
    public void testReloadableDefinitionsFactory() throws Exception {
        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/temp-defs.xml");

        URI uri = null;
        String urlPath = null;

        // The following madness is necessary b/c of the way Windows hanndles URLs.
        // We must add a slash to the protocol if Windows does not.  But we cannot
        // add a slash to Unix paths b/c they already have one.
        if (url.getPath().startsWith("/")) {
            urlPath = "file:" + url.getPath();
        } else {
            urlPath = "file:/" + url.getPath();
        }

        // The following second madness is necessary b/c sometimes spaces
        // are encoded as '%20', sometimes they are not. For example in
        // Windows 2000 under Eclipse they are encoded, under the prompt of
        // Windows 2000 they are not.
        // It seems to be in the different behaviour of
        // sun.misc.Launcher$AppClassLoader (called under Eclipse) and
        // java.net.URLClassLoader (under maven).
        // And an URL accepts spaces while URIs need '%20'.
        try {
            uri = new URI(urlPath);
        } catch (URISyntaxException e) {
            uri = new URI(urlPath.replaceAll(" ", "%20"));
        }

        String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
                "<!DOCTYPE tiles-definitions PUBLIC " +
                "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" " +
                "\"http://tiles.apache.org/dtds/tiles-config_2_0.dtd\">\n\n" +
                "<tiles-definitions>" +
                "<definition name=\"rewrite.test\" template=\"/test.jsp\">" +
                "<put-attribute name=\"testparm\" value=\"testval\"/>" +
                "</definition>" +
                "</tiles-definitions>";

        File file = new File(uri);
        FileOutputStream fileOut = new FileOutputStream(file);
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(fileOut));
        writer.write(xml);
        writer.close();

        factory.init(new HashMap());
        factory.addSource(url);

        // Parse files.
        ComponentDefinitions definitions = factory.readDefinitions();

        assertNotNull("rewrite.test definition not found.",
                definitions.getDefinition("rewrite.test"));
        assertEquals("Incorrect initial template value", "/test.jsp",
                definitions.getDefinition("rewrite.test").getTemplate());

        ReloadableDefinitionsFactory reloadable = (ReloadableDefinitionsFactory) factory;
        assertEquals("Factory should be fresh.", false,
                reloadable.refreshRequired());

        // Make sure the system actually updates the timestamp.
        Thread.sleep(30000);

        // Set up multiple data sources.
        xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
                "<!DOCTYPE tiles-definitions PUBLIC " +
                "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" " +
                "\"http://tiles.apache.org/dtds/tiles-config_2_0.dtd\">\n\n" +
                "<tiles-definitions>" +
                "<definition name=\"rewrite.test\" template=\"/newtest.jsp\">" +
                "<put-attribute name=\"testparm\" value=\"testval\"/>" +
                "</definition>" +
                "</tiles-definitions>";

        file = new File(uri);
        fileOut = new FileOutputStream(file);
        writer = new BufferedWriter(new OutputStreamWriter(fileOut));
        writer.write(xml);
        writer.close();


        assertEquals("Factory should be stale.", true,
                reloadable.refreshRequired());
        definitions = factory.readDefinitions();
        assertNotNull("rewrite.test definition not found.",
                definitions.getDefinition("rewrite.test"));
        assertEquals("Incorrect initial template value", "/newtest.jsp",
                definitions.getDefinition("rewrite.test").getTemplate());
    }
View Full Code Here

    /**
     * Tests the readDefinitions method under normal conditions.
     */
    public void testReadDefinitions() throws Exception {
        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url1 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs1.xml");
        assertNotNull("Could not load defs1 file.", url1);
        URL url2 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs2.xml");
        assertNotNull("Could not load defs2 file.", url2);
        URL url3 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs3.xml");
        assertNotNull("Could not load defs3 file.", url3);

        factory.init(Collections.EMPTY_MAP);
        factory.addSource(url1);
        factory.addSource(url2);
        factory.addSource(url3);

        // Parse files.
        ComponentDefinitions definitions = factory.readDefinitions();

        assertNotNull("test.def1 definition not found.", definitions.getDefinition("test.def1"));
        assertNotNull("test.def2 definition not found.", definitions.getDefinition("test.def2"));
        assertNotNull("test.def3 definition not found.", definitions.getDefinition("test.def3"));
    }
View Full Code Here

    /**
     * Tests the getDefinition method.
     */
    public void testGetDefinition() throws Exception {
        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url1 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs1.xml");
        assertNotNull("Could not load defs1 file.", url1);
        URL url2 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs2.xml");
        assertNotNull("Could not load defs2 file.", url2);
        URL url3 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs3.xml");
        assertNotNull("Could not load defs3 file.", url3);

        factory.init(Collections.EMPTY_MAP);
        factory.addSource(url1);
        factory.addSource(url2);
        factory.addSource(url3);

        // Parse files.
        factory.readDefinitions();
       
        TilesRequestContext emptyContext = new MockOnlyLocaleTilesContext(null);
        TilesRequestContext usContext = new MockOnlyLocaleTilesContext(Locale.US);
        TilesRequestContext frenchContext = new MockOnlyLocaleTilesContext(Locale.FRENCH);
        TilesRequestContext chinaContext = new MockOnlyLocaleTilesContext(Locale.CHINA);
        TilesRequestContext canadaFrenchContext = new MockOnlyLocaleTilesContext(Locale.CANADA_FRENCH);

        assertNotNull("test.def1 definition not found.", factory.getDefinition("test.def1", emptyContext));
        assertNotNull("test.def2 definition not found.", factory.getDefinition("test.def2", emptyContext));
        assertNotNull("test.def3 definition not found.", factory.getDefinition("test.def3", emptyContext));
        assertNotNull("test.common definition not found.", factory.getDefinition("test.common", emptyContext));
        assertNotNull("test.common definition in US locale not found.", factory.getDefinition("test.common", usContext));
        assertNotNull("test.common definition in FRENCH locale not found.", factory.getDefinition("test.common", frenchContext));
        assertNotNull("test.common definition in CHINA locale not found.", factory.getDefinition("test.common", chinaContext));
        assertNotNull("test.common.french definition in FRENCH locale not found.", factory.getDefinition("test.common.french", frenchContext));
        assertNotNull("test.common.french definition in CANADA_FRENCH locale not found.", factory.getDefinition("test.common.french", canadaFrenchContext));
        assertNotNull("test.def.toextend definition not found.", factory.getDefinition("test.def.toextend", emptyContext));
        assertNotNull("test.def.overridden definition not found.", factory.getDefinition("test.def.overridden", emptyContext));
        assertNotNull("test.def.overridden definition in FRENCH locale not found.", factory.getDefinition("test.def.overridden", frenchContext));

        assertEquals("Incorrect default country value", "default",
                factory.getDefinition("test.def1", emptyContext).getAttribute("country"));
        assertEquals("Incorrect US country value", "US",
                factory.getDefinition("test.def1", usContext).getAttribute("country"));
        assertEquals("Incorrect France country value", "France",
                factory.getDefinition("test.def1", frenchContext).getAttribute("country"));
        assertEquals("Incorrect Chinese country value (should be default)", "default",
                factory.getDefinition("test.def1", chinaContext).getAttribute("country"));
        assertEquals("Incorrect default country value", "default",
                factory.getDefinition("test.def.overridden", emptyContext).getAttribute("country"));
        assertEquals("Incorrect default title value", "Definition to be overridden",
                factory.getDefinition("test.def.overridden", emptyContext).getAttribute("title"));
        assertEquals("Incorrect France country value", "France",
                factory.getDefinition("test.def.overridden", frenchContext).getAttribute("country"));
        assertEquals("Incorrect France title value", "Definition to be extended",
                factory.getDefinition("test.def.overridden", frenchContext).getAttribute("title"));
    }
View Full Code Here

    /**
     * Tests addSource with a bad source object type.
     */
    public void testBadSourceType() throws Exception {
        try {
            DefinitionsFactory factory = new UrlDefinitionsFactory();

            factory.init(Collections.EMPTY_MAP);
            factory.addSource("Bad object.");

            fail("Should've thrown exception.");
        } catch (DefinitionsFactoryException e) {
            // success.
        }
View Full Code Here

        params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
                "org.apache.tiles.definition.MockDefinitionsReader");

        int instanceCount = MockDefinitionsReader.getInstanceCount();

        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url1 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs1.xml");
        assertNotNull("Could not load defs1 file.", url1);

        factory.init(params);
        factory.addSource(url1);

        assertEquals("MockDefinitionsReader not used.",
                instanceCount + 1,
                MockDefinitionsReader.getInstanceCount());
    }
View Full Code Here

    /**
     * Tests the concatPostfix method.
     */
    public void testConcatPostfix() {
      UrlDefinitionsFactory factory = new UrlDefinitionsFactory();
        String postfix = "_en_US";
        assertEquals("a_en_US", factory.concatPostfix("a", postfix));
        assertEquals("a_en_US.jsp", factory.concatPostfix("a.jsp", postfix));
        assertEquals("file_en_US.jsp", factory.concatPostfix("file.jsp", postfix));
        assertEquals("./path/file_en_US.jsp", factory.concatPostfix("./path/file.jsp", postfix));
    }
View Full Code Here

     * @since 2.1.1
     */
    protected LocaleDefinitionsFactory instantiateDefinitionsFactory(TilesApplicationContext applicationContext,
            TilesRequestContextFactory contextFactory,
            LocaleResolver resolver) {
        return new UrlDefinitionsFactory();
    }
View Full Code Here

     * @since 2.1.0
     */
    protected LocaleDefinitionsFactory instantiateDefinitionsFactory(Object context,
            TilesApplicationContext applicationContext,
            TilesContextFactory contextFactory, LocaleResolver resolver) {
        return new UrlDefinitionsFactory();
    }
View Full Code Here

TOP

Related Classes of org.apache.tiles.definition.UrlDefinitionsFactory$CompatibilityDefinitionsImpl

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.