Package org.apache.tiles

Examples of org.apache.tiles.Definition


     */
    protected void register(Definition definition,
            TilesRequestContext request) throws DefinitionsFactoryException {
        DefinitionManager mgr = getProperDefinitionManager(
                getDefinitionsFactoryKey(request));
        Definition def = new Definition(definition);
        mgr.addDefinition(def, request);
    }
View Full Code Here


     * @throws DefinitionsFactoryException If something goes wrong during adding
     * a definition, such as missing parent definitions.
     */
    protected void register(Definition definition,
            TilesRequestContext request) throws DefinitionsFactoryException {
        Definition def = new Definition(definition);
        mgr.addDefinition(def, request);
    }
View Full Code Here

     * Tests the inheritance properties of Definition objects.
     */
    public void testResolveInheritances() {
        Map<String, Definition> defs = new HashMap<String, Definition>();

        Definition def = new Definition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        Attribute attr = new Attribute();
        attr.setValue("value1");
        def.putAttribute("attr1", attr);
        attr = new Attribute();
        attr.setValue("tiles.def1");
        // No type set
        def.putAttribute("attr2", attr);
        defs.put(def.getName(), def);
        attr = new Attribute();
        attr.setValue("tiles.def1");
        attr.setType(AttributeType.STRING);
        def.putAttribute("attr3", attr);
        defs.put(def.getName(), def);

        def = new Definition();
        def.setName("tiles.def1");
        def.setTemplate("/test2.jsp");
        defs.put(def.getName(), def);

        def = new Definition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new Attribute();
        attr.setValue("New value");
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        Definitions definitions = new DefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }

        def = definitions.getDefinition("parent.def1");

        assertNotNull("Couldn't get parent.", def);
        assertEquals("Incorrect template value.", "/test1.jsp", def
                .getTemplate());
        assertEquals("Incorrect attr1 value", "value1", def
                .getAttribute("attr1").getValue());

        attr = def.getAttributes().get("attr1");
        assertNotNull("Dependent attribute not found.", attr);
        attr = def.getAttributes().get("attr2");
        assertNotNull("Dependent attribute not found.", attr);
        attr = def.getAttributes().get("attr3");
        assertNotNull("Dependent attribute not found.", attr);
        assertTrue("The attribute 'attr3' should be of type STRING", attr
                .getType() == AttributeType.STRING);

        def = definitions.getDefinition("child.def1");

        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").getValue());

        attr = def.getAttributes().get("attr1");
        assertNotNull("Dependent attribute not found.", attr);
        attr = def.getAttributes().get("attr2");
        assertNotNull("Dependent attribute not found.", attr);
        attr = def.getAttributes().get("attr3");
        assertNotNull("Dependent attribute not found.", attr);
        assertTrue("The attribute 'attr3' should be of type STRING", attr
                .getType() == AttributeType.STRING);
    }
View Full Code Here

    /**
     * Tests the inheritance with localized definitions.
     */
    public void testLocalizedResolveInheritances() {
        Map<String, Definition> defs = new HashMap<String, Definition>();
        Definition def = new Definition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        Attribute attr = new Attribute();
        attr.setValue("value1");
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        def = new Definition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new Attribute();
        attr.setValue("New value");
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        Map<String, Definition> localDefs = new HashMap<String, Definition>();
        def = new Definition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new Attribute();
        attr.setValue("US Value");
        def.putAttribute("attr1", attr);
        localDefs.put(def.getName(), def);

        Definitions definitions = new DefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
            definitions.addDefinitions(localDefs, Locale.US);
View Full Code Here

     * Tests the reset method.
     */
    public void testReset() {
        Map<String, Definition> defs = new HashMap<String, Definition>();

        Definition def = new Definition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        Attribute attr = new Attribute();
        attr.setValue("value1");
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        def = new Definition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new Attribute();
        attr.setValue("New value");
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        Definitions definitions = new DefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
        } catch (NoSuchDefinitionException e) {
View Full Code Here

     * executed and attribute dependencies are calculated.
     */
    public void testResolveAttributeDependencies() {
        Map<String, Definition> defs = new HashMap<String, Definition>();

        Definition def = new Definition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        Attribute attr = new Attribute();
        attr.setValue("tiles.def2");
        attr.setType(AttributeType.DEFINITION);
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        def = new Definition();
        def.setName("parent.notype.def1");
        def.setTemplate("/test1.jsp");
        attr = new Attribute();
        attr.setValue("tiles.def2");
        // Don't set the type
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);

        def = new Definition();
        def.setName("tiles.def2");
        defs.put(def.getName(), def);

        Definitions definitions = new DefinitionsImpl();
        try {
            definitions.addDefinitions(defs);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }

        defs = new HashMap<String, Definition>(defs);
        def = new Definition();
        def.setName("parent.def2");
        def.setTemplate("/test1.jsp");
        attr = new Attribute();
        attr.setValue("tiles.def3");
        def.putAttribute("attr1", attr);
        defs.put(def.getName(), def);
        def = new Definition();
        def.setName("tiles.def3");
        defs.put(def.getName(), def);

        try {
            definitions.addDefinitions(defs, Locale.ITALIAN);
        } catch (NoSuchDefinitionException e) {
            fail("Test failure: " + e);
        }

        Definition newDef = definitions.getDefinition("parent.def1");
        assertNotNull("Parent definition not found.", newDef);

        Object newAttr = newDef.getAttribute("attr1").getValue();
        assertNotNull("Dependent attribute not found.", newAttr);

        newDef = definitions.getDefinition("parent.notype.def1");
        assertNotNull("Parent definition not found.", newDef);

        newAttr = newDef.getAttribute("attr1").getValue();
        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").getValue();
        assertNotNull("Dependent attribute not found.", newAttr);

        newDef = definitions.getDefinition("parent.notype.def1",
                Locale.ITALIAN);
        assertNotNull("Parent definition not found.", newDef);

        newAttr = newDef.getAttribute("attr1").getValue();
        assertNotNull("Dependent attribute not found.", newAttr);

        assertEquals("Incorrect dependent attribute name.", "tiles.def2",
                newAttr);

        newDef = definitions.getDefinition("parent.def2", Locale.ITALIAN);
        assertNotNull("Parent definition not found.", newDef);

        attr = newDef.getAttributes().get("attr1");
        assertNotNull("Dependent attribute not found.", attr);
    }
View Full Code Here

        definition = null;
    }

    /** {@inheritDoc} */
    public int doStartTag() throws TilesJspException {
        definition = new Definition();
        definition.setName(name);
        definition.setTemplate(template);
        definition.setExtends(extend);
        definition.setRole(role);
        definition.setPreparer(preparer);
View Full Code Here

        EasyMock.expect(context.getSessionScope()).andReturn(
                new HashMap<String, Object>()).anyTimes();
        EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
        EasyMock.replay(context);

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

        RefreshMonitor reloadable = (RefreshMonitor) definitionDao;
        assertEquals("Factory should be fresh.", false, reloadable
                .refreshRequired());
View Full Code Here

        EasyMock.replay(applicationContext);
        ((TilesApplicationContextAware) definitionDao)
                .setApplicationContext(applicationContext);
        definitionDao.setReader(new DigesterDefinitionsReader());

        Definition definition = definitionDao.getDefinition("test.defName.subLayered", null);
        assertEquals("The template is not correct", "/testName.jsp", definition.getTemplate());
        assertEquals("The header attribute is not correct",
                "/common/headerLayered.jsp", definition.getAttribute("header")
                        .getValue());
        definition = definitionDao.getDefinition("test.def3", null);
        assertNotNull("The simple definition is null", definition);
    }
View Full Code Here

        EasyMock.expect(context.getSessionScope()).andReturn(
                new HashMap<String, Object>()).anyTimes();
        EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
        EasyMock.replay(context);

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

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

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

        // 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());
        reloadable.refresh();
        definition = factory.getDefinition("rewrite.test", context);
        assertNotNull("rewrite.test definition not found.", definition);
        assertEquals("Incorrect initial template value", "/newtest.jsp",
                definition.getTemplate());
    }
View Full Code Here

TOP

Related Classes of org.apache.tiles.Definition

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.