1 /*
2 * $Id: JspModelBody.java 1305546 2012-03-26 20:34:37Z 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 package org.apache.tiles.request.jsp.autotag;
22
23 import java.io.IOException;
24 import java.io.Writer;
25
26 import javax.servlet.jsp.JspContext;
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.tagext.JspFragment;
29
30 import org.apache.tiles.autotag.core.runtime.AbstractModelBody;
31
32 /**
33 * The body abstraction in a JSP tag.
34 *
35 * @version $Rev: 1305546 $ $Date: 2012-03-27 07:34:37 +1100 (Tue, 27 Mar 2012) $
36 */
37 public class JspModelBody extends AbstractModelBody {
38
39 /**
40 * The real body.
41 */
42 private JspFragment jspFragment;
43
44 /**
45 * Constructor.
46 *
47 * @param jspFragment The real body.
48 * @param jspContext The page context.
49 */
50 public JspModelBody(JspFragment jspFragment, JspContext jspContext) {
51 super(jspContext.getOut());
52 this.jspFragment = jspFragment;
53 }
54
55 @Override
56 public void evaluate(Writer writer) throws IOException {
57 if (jspFragment == null) {
58 return;
59 }
60
61 try {
62 jspFragment.invoke(writer);
63 } catch (JspException e) {
64 throw new IOException("JspException when evaluating the body", e);
65 }
66 }
67
68 }