Package org.apache.tiles

Examples of org.apache.tiles.Definition


     * @return <code>true</code> if <code>definitionName</code> is a valid
     * definition name.
     */
    private boolean isValidDefinition(TilesRequestContext context, String definitionName) {
        try {
            Definition definition = getDefinition(definitionName, context);
            return definition != null;
        } catch (NoSuchDefinitionException nsde) {
            return false;
        } catch (DefinitionsFactoryException e) {
            // TODO, is this the right thing to do?
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

                "doc.mainLayout").getAttribute("title").getValue());
        assertEquals("Incorrect Find title attribute.",
                "Tiles Library Documentation", definitions.get(
                        "doc.mainLayout").getAttribute("title").getValue());

        Definition def = definitions.get("doc.role.test");
        assertNotNull("Couldn't find doc.role.test tile.", def);
        Attribute attribute = def.getAttribute("title");
        assertNotNull("Couldn't Find title attribute.", attribute
                .getValue());
        assertEquals("Role 'myrole' expected", attribute.getRole(),
                "myrole");

        def = definitions.get("doc.listattribute.test");
        assertNotNull("Couldn't find doc.listattribute.test tile.", def);
        attribute = def.getAttribute("items");
        assertNotNull("Couldn't Find items attribute.", attribute);
        assertTrue("The class of the attribute is not right",
                attribute instanceof ListAttribute);
        assertTrue("The class of value of the attribute is not right",
                attribute.getValue() instanceof List);
View Full Code Here

        InputStream source = configFile.openStream();
        Map<String, Definition> definitions = reader.read(source);

        assertNotNull("Definitions not returned.", definitions);
        Definition def = definitions.get("doc.cascaded.test");

        assertNotNull("Couldn't find doc.role.test tile.", def);
        Attribute attribute = def.getLocalAttribute("title");
        assertNotNull("Couldn't Find title local attribute.", attribute);
        attribute = def.getCascadedAttribute("title2");
        assertNotNull("Couldn't Find title2 cascaded attribute.", attribute);
        attribute = def.getLocalAttribute("items1");
        assertNotNull("Couldn't Find items1 local attribute.", attribute);
        attribute = def.getCascadedAttribute("items2");
        assertNotNull("Couldn't Find items2 cascaded attribute.", attribute);

        def = definitions.get("test.nesting.definitions");
        assertNotNull("Couldn't find test.nesting.definitions tile.", def);
        attribute = def.getAttribute("body");
        assertNotNull("Couldn't Find body attribute.", attribute);
        assertEquals("Attribute not of 'definition' type", "definition",
                attribute.getRenderer());
        assertNotNull("Attribute value null", attribute.getValue());
        String defName = attribute.getValue().toString();
        def = definitions.get(defName);
        assertNotNull("Couldn't find " + defName + " tile.", def);

        def = definitions.get("test.nesting.list.definitions");
        assertNotNull("Couldn't find test.nesting.list.definitions tile.",
                def);
        attribute = def.getAttribute("list");
        assertNotNull("Couldn't Find list attribute.", attribute);
        assertTrue("Attribute not of valid type",
                attribute instanceof ListAttribute);
        ListAttribute listAttribute = (ListAttribute) attribute;
        List<Attribute> list = (List<Attribute>) listAttribute.getValue();
        assertEquals("The list is not of correct size", 1, list.size());
        attribute = list.get(0);
        assertNotNull("Couldn't Find element attribute.", attribute);
        assertEquals("Attribute not of 'definition' type", "definition",
                attribute.getRenderer());
        assertNotNull("Attribute value null", attribute.getValue());
        defName = attribute.getValue().toString();
        def = definitions.get(defName);
        assertNotNull("Couldn't find " + defName + " tile.", def);

        defName = "test.inherit.list.base";
        def = definitions.get(defName);
        assertNotNull("Couldn't find " + defName + " tile.", def);
        defName = "test.inherit.list";
        def = definitions.get(defName);
        assertNotNull("Couldn't find " + defName + " tile.", def);
        listAttribute = (ListAttribute) def.getAttribute("list");
        assertEquals("This definition does not inherit its list attribute",
                true, listAttribute.isInherit());
        defName = "test.noinherit.list";
        def = definitions.get(defName);
        listAttribute = (ListAttribute) def.getAttribute("list");
        assertEquals("This definition inherits its list attribute",
                false, listAttribute.isInherit());
    }
View Full Code Here

            InputStream source = configFile.openStream();
            Map<String, Definition> definitions = reader.read(source);

            assertNotNull("Definitions not returned.", definitions);
            Definition def = definitions.get("doc.cascaded.test");

            assertNotNull("Couldn't find doc.role.test tile.", def);
            Attribute attribute = def.getLocalAttribute("title");
            assertNotNull("Couldn't Find title local attribute.", attribute);
            attribute = def.getCascadedAttribute("title2");
            assertNotNull("Couldn't Find title2 cascaded attribute.", attribute);
            attribute = def.getLocalAttribute("items1");
            assertNotNull("Couldn't Find items1 local attribute.", attribute);
            attribute = def.getCascadedAttribute("items2");
            assertNotNull("Couldn't Find items2 cascaded attribute.", attribute);
        } catch (Exception e) {
            fail("Exception reading configuration." + e);
        }
    }
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

     * @return <code>true</code> if <code>definitionName</code> is a valid
     * definition name.
     */
    private boolean isValidDefinition(TilesRequestContext context, String definitionName) {
        try {
            Definition definition = getDefinition(definitionName, context);
            return definition != null;
        } catch (NoSuchDefinitionException nsde) {
            return false;
        } catch (DefinitionsFactoryException e) {
            // TODO, is this the right thing to do?
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.getTemplateAttribute().getValue());

        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.getTemplateAttribute().getValue());
    }
View Full Code Here

        checkRefresh = "true".equals(param);
    }

    /** {@inheritDoc} */
    public Definition getDefinition(String name, Locale customizationKey) {
        Definition retValue = null;
        if (customizationKey == null) {
            customizationKey = LocaleUtil.NULL_LOCALE;
        }
        Map<String, Definition> definitions = getDefinitions(customizationKey);
        if (definitions != null) {
View Full Code Here

     * @since 2.1.0
     */
    protected Definition resolveWildcardDefinition(
            List<WildcardMapping> paths, String name) {
        Map<Integer, String> vars = new HashMap<Integer, String>();
        Definition d = null;

        for (WildcardMapping wm : paths) {
            if (wildcardHelper.match(vars, name, wm.getPattern())) {
                d = replaceDefinition(wm.getDefinition(), name, vars);
                break;
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.