Package org.apache.tiles.definition

Examples of org.apache.tiles.definition.ComponentDefinitions


        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


        attr.setName("attr1");
        attr.setValue("New value");
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        ComponentDefinitions definitions = new ComponentDefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }
       
        assertNotNull("Couldn't get parent.",
                definitions.getDefinition("parent.def1"));
        assertEquals("Incorrect template value." , "/test1.jsp",
                definitions.getDefinition("parent.def1").getTemplate());
        assertEquals("Incorrect attr1 value", "value1",
                definitions.getDefinition("parent.def1").getAttribute("attr1"));
       
        assertNotNull("Couldn't get child.",
                definitions.getDefinition("child.def1"));
        assertEquals("Incorrect template value." , "/test1.jsp",
                definitions.getDefinition("child.def1").getTemplate());
        assertEquals("Incorrect attr1 value", "New value",
                definitions.getDefinition("child.def1").getAttribute("attr1"));
    }
View Full Code Here

        attr.setName("attr1");
        attr.setValue("US Value");
        def.addAttribute(attr);
        localDefs.put(def.getName(), def);

        ComponentDefinitions definitions = new ComponentDefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
            definitions.addDefinitions(localDefs, Locale.US);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }
       
        assertNotNull("Couldn't get parent.",
                definitions.getDefinition("parent.def1"));
        assertEquals("Incorrect template value." , "/test1.jsp",
                definitions.getDefinition("parent.def1").getTemplate());
        assertEquals("Incorrect attr1 value", "value1",
                definitions.getDefinition("parent.def1").getAttribute("attr1"));
       
        assertNotNull("Couldn't get child.",
                definitions.getDefinition("child.def1"));
        assertEquals("Incorrect template value." , "/test1.jsp",
                definitions.getDefinition("child.def1").getTemplate());
        assertEquals("Incorrect attr1 value", "New value",
                definitions.getDefinition("child.def1").getAttribute("attr1"));
       
        assertNotNull("Couldn't get parent.",
                definitions.getDefinition("parent.def1", Locale.US));
        assertEquals("Incorrect template value." , "/test1.jsp",
                definitions.getDefinition("parent.def1", Locale.US).getTemplate());
        assertEquals("Incorrect attr1 value", "value1",
                definitions.getDefinition("parent.def1", Locale.US).getAttribute("attr1"));
       
        assertNotNull("Couldn't get child.",
                definitions.getDefinition("child.def1", Locale.US));
        assertEquals("Incorrect template value." , "/test1.jsp",
                definitions.getDefinition("child.def1", Locale.US).getTemplate());
        assertEquals("Incorrect attr1 value", "US Value",
                definitions.getDefinition("child.def1", Locale.US).getAttribute("attr1"));
    }
View Full Code Here

        attr.setName("attr1");
        attr.setValue("New value");
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        ComponentDefinitions definitions = new ComponentDefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }
       
        assertNotNull("Couldn't get parent.",
                definitions.getDefinition("parent.def1"));
       
        definitions.reset();
        assertNull("Definitions should be null.",
                definitions.getDefinition("parent.def1"));
    }
View Full Code Here

       
        def = new ComponentDefinition();
        def.setName("tiles.def2");
        defs.put(def.getName(), def);
       
        ComponentDefinitions definitions = new ComponentDefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
            definitions.addDefinitions(defs, Locale.ITALIAN);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }
       
        ComponentDefinition newDef = definitions.getDefinition("parent.def1");
        assertNotNull("Parent definition not found.", newDef);
       
        Object newAttr = newDef.getAttribute("attr1");
        assertNotNull("Dependent attribute not found.", newAttr);
       
        newDef = definitions.getDefinition("parent.notype.def1");
        assertNotNull("Parent definition not found.", newDef);
       
        newAttr = newDef.getAttribute("attr1");
        assertNotNull("Dependent attribute not found.", newAttr);
       
        assertEquals("Incorrect dependent attribute name.", "tiles.def2",
                newAttr);
       
        // Part of the test for locale-specific definitions.
        newDef = definitions.getDefinition("parent.def1", Locale.ITALIAN);
        assertNotNull("Parent definition not found.", newDef);
       
        newAttr = newDef.getAttribute("attr1");
        assertNotNull("Dependent attribute not found.", newAttr);
       
        newDef = definitions.getDefinition("parent.notype.def1",
            Locale.ITALIAN);
        assertNotNull("Parent definition not found.", newDef);
       
        newAttr = newDef.getAttribute("attr1");
        assertNotNull("Dependent attribute not found.", newAttr);
View Full Code Here

        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

        factory.addSource(url1);
        factory.addSource(url2);
        factory.addSource(url3);

        // Parse files.
        ComponentDefinitions definitions = factory.readDefinitions();
        factory.addDefinitions(definitions,
                new MockOnlyLocaleTilesContext(Locale.US));
        factory.addDefinitions(definitions,
                new MockOnlyLocaleTilesContext(Locale.FRENCH));

        assertNotNull("test.def1 definition not found.", definitions.getDefinition("test.def1"));
        assertNotNull("test.def1 US definition not found.", definitions.getDefinition("test.def1", Locale.US));
        assertNotNull("test.def1 France definition not found.", definitions.getDefinition("test.def1", Locale.FRENCH));
        assertNotNull("test.def1 China should return default.", definitions.getDefinition("test.def1", Locale.CHINA));

        assertEquals("Incorrect default country value", "default",
                definitions.getDefinition("test.def1").getAttribute("country"));
        assertEquals("Incorrect US country value", "US",
                definitions.getDefinition("test.def1", Locale.US).getAttribute("country"));
        assertEquals("Incorrect France country value", "France",
                definitions.getDefinition("test.def1", Locale.FRENCH).getAttribute("country"));
        assertEquals("Incorrect Chinese country value (should default)", "default",
                definitions.getDefinition("test.def1", Locale.CHINA).getAttribute("country"));
    }
View Full Code Here

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

        // Parse files.
        ComponentDefinitions definitions = factory.readDefinitions();
        TilesRequestContext tilesContext =
                new MockOnlyLocaleTilesContext(Locale.US);
        assertFalse("Locale should not be processed.",
                factory.isContextProcessed(tilesContext));
View Full Code Here

TOP

Related Classes of org.apache.tiles.definition.ComponentDefinitions

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.