Package org.apache.tiles

Examples of org.apache.tiles.ListAttribute


        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


        expect(request.getWriter()).andReturn(writer);
        replay(request);

        container
                .getAttributeContext(request)
                .putAttribute("test-fallback", new ListAttribute(){{
                    add(new Attribute("Result"));
                }});

        OptionsRenderer renderer = new OptionsRenderer(context, new StringRenderer());
        renderer.render("{options[test-fallback]}", request);
View Full Code Here

     * @param modelBody The body.
     * @throws IOException If the body cannot be evaluated.
     */
    public void execute(String role, Request request, ModelBody modelBody) throws IOException {
        Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request);
        ListAttribute listAttribute = new ListAttribute();
        listAttribute.setRole(role);
        composeStack.push(listAttribute);
        modelBody.evaluateWithoutWriting();
        listAttribute = (ListAttribute) composeStack.pop();
        ListAttribute parent = (ListAttribute) composeStack.peek();
        parent.add(listAttribute);
    }
View Full Code Here

     */
    public void execute(@Parameter(required = true) String name, String role,
            boolean inherit, boolean cascade, Request request,
            ModelBody modelBody) throws IOException {
        Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request);
        ListAttribute listAttribute = new ListAttribute();
        listAttribute.setRole(role);
        listAttribute.setInherit(inherit);
        composeStack.push(listAttribute);
        modelBody.evaluateWithoutWriting();
        TilesContainer container = TilesAccess.getCurrentContainer(request);
        listAttribute = (ListAttribute) composeStack.pop();
        AttributeContext attributeContext = null;
View Full Code Here

        modelBody.evaluateWithoutWriting();
        requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
        expect(request.getContext("request")).andReturn(requestScope);

        replay(request, modelBody);
        ListAttribute parent = new ListAttribute();
        composeStack.push(parent);
        model.execute("myRole", request, modelBody);
        assertEquals(1, composeStack.size());
        assertEquals(parent, composeStack.pop());
        assertEquals(1, parent.getValue().size());
        ListAttribute listAttribute = (ListAttribute) parent.getValue().get(0);
        assertEquals("myRole", listAttribute.getRole());
        verify(request, modelBody);
    }
View Full Code Here

     * @since 2.2.0
     */
    private void addAttributeToList(Attribute attribute,
            Deque<Object> composeStack, Object value, String expression,
            String body, String role, String type) {
        ListAttribute listAttribute = (ListAttribute) ComposeStackUtil
                .findAncestorWithClass(composeStack, ListAttribute.class);

        if (listAttribute == null) {
            throw new NullPointerException("There is no ListAttribute in the stack");
        }
        if (value != null) {
            attribute.setValue(value);
        } else if (attribute.getValue() == null && body != null) {
            attribute.setValue(body);
        }
        if (expression != null) {
            attribute.setExpressionObject(Expression
                    .createExpressionFromDescribedExpression(expression));
        }
        if (role != null) {
            attribute.setRole(role);
        }
        if (type != null) {
            attribute.setRenderer(type);
        }
        listAttribute.add(attribute);
    }
View Full Code Here

        TilesContainer container = createMock(TilesContainer.class);
        Request request = createMock(Request.class);
        ModelBody modelBody = createMock(ModelBody.class);
        AttributeContext attributeContext = createMock(AttributeContext.class);
        Deque<Object> composeStack = new ArrayDeque<Object>();
        ListAttribute listAttribute = new ListAttribute();
        composeStack.push(listAttribute);
        Map<String, Object> requestScope = new HashMap<String, Object>();
        requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
        requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
        ApplicationContext applicationContext = createMock(ApplicationContext.class);
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

     * {@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

                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 = 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());

        defName = "test.new.attributes";
        def = definitions.get(defName);
        assertNotNull("Couldn't find " + defName + " tile.", def);
        Attribute templateAttribute = def.getTemplateAttribute();
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.