1 /* 2 * $Id: AddListAttributeModel.java 1305937 2012-03-27 18:15:15Z nlebas $ 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 package org.apache.tiles.template; 23 24 import java.io.IOException; 25 import java.util.Deque; 26 27 import org.apache.tiles.ListAttribute; 28 import org.apache.tiles.autotag.core.runtime.ModelBody; 29 import org.apache.tiles.request.Request; 30 31 /** 32 * <p> 33 * <strong>Declare a list that will be pass as an attribute. </strong> 34 * </p> 35 * <p> 36 * Declare a list that will be pass as an attribute . List elements are added 37 * using the tag 'addAttribute' or 'addListAttribute'. This tag can only be used 38 * inside 'insertTemplate', 'insertDefinition' or 'definition' tag. 39 * </p> 40 * 41 * @version $Rev: 1305937 $ $Date: 2012-03-28 05:15:15 +1100 (Wed, 28 Mar 2012) $ 42 * @since 2.2.0 43 */ 44 public class AddListAttributeModel { 45 46 /** 47 * Executes the model. 48 * 49 * @param role The comma-separated list of roles that can use the list attribute. 50 * @param request The request. 51 * @param modelBody The body. 52 * @throws IOException If the body cannot be evaluated. 53 */ 54 public void execute(String role, Request request, ModelBody modelBody) throws IOException { 55 Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request); 56 ListAttribute listAttribute = new ListAttribute(); 57 listAttribute.setRole(role); 58 composeStack.push(listAttribute); 59 modelBody.evaluateWithoutWriting(); 60 listAttribute = (ListAttribute) composeStack.pop(); 61 ListAttribute parent = (ListAttribute) composeStack.peek(); 62 parent.add(listAttribute); 63 } 64 }