1/*2 * $Id: BlockDirective.java 901355 2010-01-20 19:58:12Z 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.velocity.template;
2324import java.io.IOException;
25import java.io.Writer;
26import java.util.Map;
2728import javax.servlet.ServletContext;
29import javax.servlet.http.HttpServletRequest;
30import javax.servlet.http.HttpServletResponse;
3132import org.apache.tiles.velocity.context.VelocityUtil;
33import org.apache.velocity.context.InternalContextAdapter;
34import org.apache.velocity.runtime.directive.Directive;
35import org.apache.velocity.runtime.parser.node.Node;
36import org.apache.velocity.tools.view.ViewContext;
3738/***39 * Base abstract directive for those models who need to evaluate, but not use, a40 * body.41 *42 * @version $Rev: 901355 $ $Date: 2010-01-20 20:58:12 +0100 (mer, 20 gen 2010) $43 * @since 2.2.244 */45publicabstractclassBlockDirectiveextends Directive {
4647/*** {@inheritDoc} */4849 @Override
50publicint getType() {
51return BLOCK;
52 }
5354/*** {@inheritDoc} */5556 @Override
57publicboolean render(InternalContextAdapter context, Writer writer,
58 Node node) throws IOException {
59 ViewContext viewContext = (ViewContext) context
60 .getInternalUserContext();
61 Map<String, Object> params = VelocityUtil.getParameters(context, node);
62 HttpServletRequest request = viewContext.getRequest();
63 HttpServletResponse response = viewContext.getResponse();
64 ServletContext servletContext = viewContext.getServletContext();
65 start(context, writer, params, request, response, servletContext);
66 VelocityUtil.evaluateBody(context, writer, node);
67 end(context, writer, params, request, response, servletContext);
68returntrue;
69 }
7071/***72 * Starts the directive, before evaluating the body.73 *74 * @param context The Velocity context.75 * @param writer The writer user to write the result.76 * @param params The parameters got from the first node of the directive.77 * @param request The HTTP request.78 * @param response The HTTP response.79 * @param servletContext The servlet context.80 * @since 2.2.281 */82protectedabstractvoid start(InternalContextAdapter context, Writer writer,
83 Map<String, Object> params, HttpServletRequest request,
84 HttpServletResponse response, ServletContext servletContext);
8586/***87 * Ends the directive, after evaluating the body.88 *89 * @param context The Velocity context.90 * @param writer The writer user to write the result.91 * @param params The parameters got from the first node of the directive.92 * @param request The HTTP request.93 * @param response The HTTP response.94 * @param servletContext The servlet context.95 * @throws IOException If something goes wrong when finishing this directive.96 * @since 2.2.297 */98protectedabstractvoid end(InternalContextAdapter context, Writer writer,
99 Map<String, Object> params, HttpServletRequest request,
100 HttpServletResponse response, ServletContext servletContext)
101 throws IOException;
102 }