Package org.apache.tiles

Examples of org.apache.tiles.ListAttribute


        Map<String, Definition> name2defs = reader.read(source);
        source.close();
        Definition root = name2defs.get("root");
        Attribute attribute = root.getAttribute("body");
        Definition child = name2defs.get(attribute.getValue());
        ListAttribute listAttribute = (ListAttribute) child.getAttribute("list");
        List<Attribute> list = listAttribute.getValue();
        assertEquals((list.get(0)).getValue(), "This is a value");
    }
View Full Code Here


        definitionDao.setReader(new DigesterDefinitionsReader());
        replay(applicationContext);

        Definition definition = definitionDao.getDefinition(
                "test.inherit.list", Locale.ITALIAN);
        ListAttribute listAttribute = (ListAttribute) definition
                .getAttribute("list");
        List<Attribute> attributes = listAttribute.getValue();
        // It is right not to resolve inheritance in this DAO.
        assertEquals(1, attributes.size());
        verify(applicationContext);
    }
View Full Code Here

    @Test
    public void testExecute() throws IOException {
        Request request = createMock(Request.class);
        ModelBody modelBody = createMock(ModelBody.class);
        Deque<Object> composeStack = new ArrayDeque<Object>();
        ListAttribute listAttribute = new ListAttribute();
        Attribute attribute;
        composeStack.push(listAttribute);
        Map<String, Object> requestScope = new HashMap<String, Object>();
        requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);

        expect(request.getContext("request")).andReturn(requestScope).times(2);
        expect(modelBody.evaluateAsString()).andReturn(null);
        expect(modelBody.evaluateAsString()).andReturn("myBody");

        replay(request, modelBody);
        model.execute("myValue", "myExpression", "myRole", "myType",
                request, modelBody);
        List<Attribute> attributes = listAttribute.getValue();
        assertEquals(1, attributes.size());
        attribute = attributes.iterator().next();
        assertEquals("myValue", attribute.getValue());
        assertEquals("myExpression", attribute.getExpressionObject().getExpression());
        assertEquals("myRole", attribute.getRole());
        assertEquals("myType", attribute.getRenderer());

        composeStack.clear();
        listAttribute = new ListAttribute();
        attribute = new Attribute();
        composeStack.push(listAttribute);
        composeStack.push(attribute);

        model.execute(null, "myExpression", "myRole", "myType", request,
                modelBody);
        attributes = listAttribute.getValue();
        assertEquals(1, attributes.size());
        attribute = attributes.iterator().next();
        assertEquals("myBody", attribute.getValue());
        assertEquals("myExpression", attribute.getExpressionObject()
                .getExpression());
View Full Code Here

        ApplicationContext applicationContext = createMock(ApplicationContext.class);
        definitionDao.setReader(new DigesterDefinitionsReader());
        replay(applicationContext);

        Definition definition = definitionDao.getDefinition("test.inherit.list", Locale.ITALIAN);
        ListAttribute listAttribute = (ListAttribute) definition.getAttribute("list");
        List<Attribute> attributes = listAttribute.getValue();
        assertEquals(2, attributes.size());
        verify(applicationContext);
    }
View Full Code Here

     * {@link PatternUtil#replacePlaceholders(Definition, String, Object[])}.
     */
    @Test
    public void testReplacePlaceholdersListAttribute() {
        Map<String, Attribute> attributes = new HashMap<String, Attribute>();
        ListAttribute listAttribute = new ListAttribute();
        ListAttribute internalListAttribute = new ListAttribute();
        listAttribute.setInherit(true);
        attributes.put("myList", listAttribute);
        listAttribute.add(new Attribute("value{2}"));
        listAttribute.add(new Attribute("value{2}{3}"));
        listAttribute.add(internalListAttribute);
        internalListAttribute.add(new Attribute("secondvalue{2}"));
        internalListAttribute.add(new Attribute("secondvalue{2}{3}"));
        Definition definition = new Definition("definitionName", new Attribute(
                "template{1}"), attributes);
        Definition nudef = PatternUtil.replacePlaceholders(definition, "nudef",
                "value0", "value1", "value2", "value3");
        assertEquals("nudef", nudef.getName());
        Attribute attribute = nudef.getTemplateAttribute();
        assertEquals("templatevalue1", attribute.getValue());
        ListAttribute nuListAttribute = (ListAttribute) nudef.getAttribute("myList");
        assertTrue(nuListAttribute.isInherit());
        List<Attribute> list = nuListAttribute.getValue();
        assertEquals(LIST_ATTRIBUTE_SIZE, list.size());
        attribute = list.get(0);
        assertEquals("valuevalue2", attribute.getValue());
        attribute = list.get(1);
        assertEquals("valuevalue2value3", attribute.getValue());
        ListAttribute evaluatedListAttribute = (ListAttribute) list.get(2);
        assertFalse(evaluatedListAttribute.isInherit());
        list = evaluatedListAttribute.getValue();
        assertEquals(2, list.size());
        attribute = list.get(0);
        assertEquals("secondvaluevalue2", attribute.getValue());
        attribute = list.get(1);
        assertEquals("secondvaluevalue2value3", attribute.getValue());
View Full Code Here

     * replaced with variables' values.
     */
    private static Attribute replaceVarsInListAttribute(ListAttribute listAttr,
            Object... vars) {
        Attribute nuattr;
        ListAttribute nuListAttr = new ListAttribute();
        nuListAttr.setInherit(listAttr.isInherit());
        List<Attribute> nuItems = nuListAttr.getValue();
        for (Object item : listAttr.getValue()) {
            Attribute child = (Attribute) item;
            child = replaceVarsInAttribute(child, vars);
            nuItems.add(child);
        }
View Full Code Here

        Matcher matcher =  OPTIONS_PATTERN.matcher((String) path);

        if (null != matcher && matcher.find()) {
            boolean done = false;
            String match = matcher.group(1);
            ListAttribute fallbacks = (ListAttribute) TilesAccess
                    .getCurrentContainer(request)
                    .getAttributeContext(request)
                    .getAttribute(match);

            if (null == fallbacks) {
                throw new IllegalStateException("A matching list-attribute name=\"" + match + "\" must be defined.");
            } else if (fallbacks.getValue().isEmpty()) {
                throw new IllegalStateException(
                        "list-attribute name=\"" + match + "\" must have minimum one attribute");
            }

            for (Attribute option : (List<Attribute>) fallbacks.getValue()) {
                String template = path.replaceFirst(Pattern.quote(matcher.group()), (String) option.getValue());
                done = renderAttempt(template, request);
                if (done) { break; }
            }
            if (!done) {
View Full Code Here

TOP

Related Classes of org.apache.tiles.ListAttribute

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.