Package org.apache.tiles.definition

Examples of org.apache.tiles.definition.ComponentDefinition


     * Tests the inheritance properties of ComponentDefinition objects.
     */
    public void testResolveInheritances() {
        Map defs = new HashMap();
       
        ComponentDefinition def = new ComponentDefinition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        ComponentAttribute attr = new ComponentAttribute();
        attr.setName("attr1");
        attr.setValue("value1");
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        def = new ComponentDefinition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new ComponentAttribute();
        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) {
View Full Code Here


    /**
     * Tests the inheritance with localized definitions.
     */
    public void testLocalizedResolveInheritances() {
        Map defs = new HashMap();
        ComponentDefinition def = new ComponentDefinition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        ComponentAttribute attr = new ComponentAttribute();
        attr.setName("attr1");
        attr.setValue("value1");
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        def = new ComponentDefinition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new ComponentAttribute();
        attr.setName("attr1");
        attr.setValue("New value");
        def.addAttribute(attr);
        defs.put(def.getName(), def);

        Map localDefs = new HashMap();
        def = new ComponentDefinition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new ComponentAttribute();
        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);
View Full Code Here

     * Tests the reset method.
     */
    public void testReset() {
        Map defs = new HashMap();
       
        ComponentDefinition def = new ComponentDefinition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        ComponentAttribute attr = new ComponentAttribute();
        attr.setName("attr1");
        attr.setValue("value1");
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        def = new ComponentDefinition();
        def.setName("child.def1");
        def.setExtends("parent.def1");
        attr = new ComponentAttribute();
        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) {
View Full Code Here

     * executed and attribute dependencies are calculated.
     */
    public void testResolveAttributeDependencies() {
        Map defs = new HashMap();
       
        ComponentDefinition def = new ComponentDefinition();
        def.setName("parent.def1");
        def.setTemplate("/test1.jsp");
        ComponentAttribute attr = new ComponentAttribute();
        attr.setName("attr1");
        attr.setValue("tiles.def2");
        attr.setType("definition");
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        def = new ComponentDefinition();
        def.setName("parent.notype.def1");
        def.setTemplate("/test1.jsp");
        attr = new ComponentAttribute();
        attr.setName("attr1");
        attr.setValue("tiles.def2");
        // Don't set the type
        def.addAttribute(attr);
        defs.put(def.getName(), def);
       
        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);
       
        assertEquals("Incorrect dependent attribute name.", "tiles.def2",
                newAttr);
    }
View Full Code Here

     * Verifies the put Attribute functionality.
     *
     * Attributes are added or replaced in the component definition.
     */
    public void testPutAttribute() {
        ComponentDefinition def = new ComponentDefinition();
        def.setName("test1");
        def.setTemplate("/page1.jsp");
        def.put("attr1", new ComponentDefinition(), "definition", null);
       
        Object attr1 = def.getAttribute("attr1");
        assertNotNull("Null attribute.", attr1);
        assertTrue("Wrong attribute type", attr1 instanceof ComponentDefinition);
    }
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("Render request recieved for definition '" + definitionName + "'");
        }

        ComponentDefinition definition = getDefinition(definitionName, request);

        if (definition == null) {
            if (LOG.isWarnEnabled()) {
                String message = "Unable to find the definition '" + definitionName + "'";
                LOG.warn(message);
            }
            throw new NoSuchDefinitionException(definitionName);
        }

        if (!isPermitted(request, definition.getRole())) {
            LOG.info("Access to definition '" + definitionName +
                "' denied.  User not in role '" + definition.getRole());
            return;
        }

        ComponentContext originalContext = getComponentContext(request);
        BasicComponentContext subContext = new BasicComponentContext(originalContext);
        subContext.addMissing(definition.getAttributes());
        BasicComponentContext.pushContext(subContext, request);

        try {
            if (definition.getPreparer() != null) {
                prepare(request, definition.getPreparer(), true);
            }

            String dispatchPath = definition.getTemplate();

            if (LOG.isDebugEnabled()) {
                LOG.debug("Dispatching to definition path '" +
                    definition.getTemplate() + " '");
            }
            request.dispatch(dispatchPath);

            // tiles exception so that it doesn't need to be rethrown.
        } catch (TilesException e) {
View Full Code Here

        }
        return type;
    }

    protected ComponentDefinition getDefinition(String definitionName, TilesRequestContext request) throws DefinitionsFactoryException {
        ComponentDefinition definition =
            definitionsFactory.getDefinition(definitionName, request);
        return definition;
    }
View Full Code Here

        return isValidDefinition(getRequestContext(pageContext), definitionName);
    }

    private boolean isValidDefinition(TilesRequestContext context, String definitionName) {
        try {
            ComponentDefinition definition = getDefinition(definitionName, context);
            return definition != null;
        }
        catch (NoSuchDefinitionException nsde) {
            return false;
        } catch (DefinitionsFactoryException e) {
View Full Code Here

    }

    @Override
    protected ComponentDefinition getDefinition(String definitionName,
            TilesRequestContext request) throws DefinitionsFactoryException {
        ComponentDefinition retValue = null;
        String key = getDefinitionsFactoryKey(request);
        if (key != null) {
            DefinitionsFactory definitionsFactory =
                key2definitionsFactory.get(key);
            if (definitionsFactory != null) {
View Full Code Here

            this.resolveInheritance(definition);
        }

        for(ComponentAttribute attr : definition.getAttributes().values()) {
            if(isDefinition(attr)) {
                ComponentDefinition d = getDefinition(attr.getValue().toString(), null);
                attr.setAttributes(d.getAttributes());
            }
        }

        definitions.put(definition.getName(), definition);
    }
View Full Code Here

TOP

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

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.