View Javadoc

1   package org.apache.velocity.tools.view.jsp.jspimpl;
2   
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  import java.io.IOException;
23  import java.io.Writer;
24  
25  import javax.servlet.jsp.JspContext;
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.PageContext;
28  import javax.servlet.jsp.tagext.JspFragment;
29  
30  import org.apache.velocity.context.InternalContextAdapter;
31  import org.apache.velocity.runtime.parser.node.ASTBlock;
32  
33  /**
34   * Exposes a directive body block as a {@link JspFragment}, i.e. the body of SimpleTag.
35   *
36   */
37  public class VelocityJspFragment extends JspFragment
38  {
39  
40      /**
41       * The JSP page context.
42       */
43      private PageContext pageContext;
44  
45      /**
46       * The block to wrap.
47       */
48      private ASTBlock block;
49  
50      /**
51       * The directive context.
52       */
53      private InternalContextAdapter context;
54  
55      /**
56       * Constructor.
57       *
58       * @param pageContext The page context to use.
59       * @param block The block to wrap.
60       * @param context The directive context.
61       */
62      public VelocityJspFragment(PageContext pageContext, ASTBlock block,
63              InternalContextAdapter context)
64      {
65          this.pageContext = pageContext;
66          this.block = block;
67          this.context = context;
68      }
69  
70      @Override
71      public void invoke(Writer out) throws JspException, IOException
72      {
73          block.render(context, out);
74      }
75  
76      @Override
77      public JspContext getJspContext()
78      {
79          return pageContext;
80      }
81  
82  }