1/*2 * $Id: InsertDefinitionModel.java 880940 2009-11-16 20:11:22Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122package org.apache.tiles.template;
2324import org.apache.tiles.Attribute;
25import org.apache.tiles.AttributeContext;
26import org.apache.tiles.TilesContainer;
2728/***29 * <p>30 * <strong>Insert a definition.</strong>31 * </p>32 * <p>33 * Insert a definition with the possibility to override and specify parameters34 * (called attributes). A definition can be seen as a (partially or totally)35 * filled template that can override or complete attribute values.36 * <code><tiles:insertDefinition></code> allows to define these attributes37 * and pass them to the inserted jsp page, called template. Attributes are38 * defined using nested tag <code><tiles:putAttribute></code> or39 * <code><tiles:putListAttribute></code>.40 * </p>41 * <p>42 * You must specify <code>name</code> tag attribute, for inserting a definition43 * from definitions factory.44 * </p>45 * <p>46 * <strong>Example : </strong>47 * </p>48 *49 * <pre>50 * <code>51 * <tiles:insertDefinition name=".my.tiles.defininition flush="true">52 * <tiles:putAttribute name="title" value="My first page" />53 * <tiles:putAttribute name="header" value="/common/header.jsp" />54 * <tiles:putAttribute name="footer" value="/common/footer.jsp" />55 * <tiles:putAttribute name="menu" value="/basic/menu.jsp" />56 * <tiles:putAttribute name="body" value="/basic/helloBody.jsp" />57 * </tiles:insertDefinition>58 * </code>59 * </pre>60 *61 * @version $Rev: 880940 $ $Date: 2009-11-16 21:11:22 +0100 (lun, 16 nov 2009) $62 * @since 2.2.063 */64publicclassInsertDefinitionModel {
6566/***67 * Starts the operation.68 *69 * @param container The Tiles container.70 * @param requestItems The request objects.71 * @since 2.2.072 */73publicvoid start(TilesContainer container, Object... requestItems) {
74 container.startContext(requestItems);
75 }
7677/***78 * Ends the operation.79 *80 * @param container The Tiles container.81 * @param definitionName The name of the definition to render.82 * @param template If specified, this template will be used instead of the83 * one used by the definition.84 * @param templateType The type of the template attribute.85 * @param templateExpression The expression to evaluate to get the value of the template.86 * @param role A comma-separated list of roles. If present, the definition87 * will be rendered only if the current user belongs to one of the roles.88 * @param preparer The preparer to use to invoke before the definition is89 * rendered. If specified, it overrides the preparer specified in the90 * definition itself.91 * @param requestItems The request objects.92 * @since 2.2.093 */94publicvoid end(TilesContainer container, String definitionName,
95 String template, String templateType, String templateExpression,
96 String role, String preparer, Object... requestItems) {
97try {
98 AttributeContext attributeContext = container
99 .getAttributeContext(requestItems);
100 Attribute templateAttribute = Attribute.createTemplateAttribute(template,
101 templateExpression, templateType, role);
102 attributeContext.setPreparer(preparer);
103 attributeContext.setTemplateAttribute(templateAttribute);
104 container.render(definitionName, requestItems);
105 } finally {
106 container.endContext(requestItems);
107 }
108 }
109110/***111 * Executes the operation.112 *113 * @param container The Tiles container.114 * @param definitionName The name of the definition to render.115 * @param template If specified, this template will be used instead of the116 * one used by the definition.117 * @param templateType The type of the template attribute.118 * @param templateExpression The expression to evaluate to get the value of the template.119 * @param role A comma-separated list of roles. If present, the definition120 * will be rendered only if the current user belongs to one of the roles.121 * @param preparer The preparer to use to invoke before the definition is122 * rendered. If specified, it overrides the preparer specified in the123 * definition itself.124 * @param requestItems The request objects.125 * @since 2.2.0126 */127publicvoid execute(TilesContainer container, String definitionName,
128 String template, String templateType, String templateExpression,
129 String role, String preparer, Object... requestItems) {
130 start(container, requestItems);
131 end(container, definitionName, template, templateType, templateExpression, role, preparer, requestItems);
132 }
133 }