Save This Page
Home » tiles-2.0.6-src » org.apache.tiles.jsp » context » [javadoc | source]
    1   /*
    2    * $Id: JspTilesRequestContext.java 603723 2007-12-12 20:07:37Z apetrelli $
    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.jsp.context;
   22   
   23   import org.apache.tiles.context.TilesRequestContext;
   24   import org.apache.tiles.servlet.context.ServletTilesRequestContext;
   25   
   26   import javax.servlet.ServletContext;
   27   import javax.servlet.ServletException;
   28   import javax.servlet.http.HttpServletRequest;
   29   import javax.servlet.http.HttpServletResponse;
   30   import javax.servlet.jsp.PageContext;
   31   import java.io.IOException;
   32   
   33   /**
   34    * Context implementation used for executing tiles within a
   35    * jsp tag library.
   36    *
   37    * @version $Rev: 603723 $ $Date: 2007-12-12 21:07:37 +0100 (Wed, 12 Dec 2007) $
   38    */
   39   public class JspTilesRequestContext extends ServletTilesRequestContext
   40       implements TilesRequestContext {
   41   
   42       /**
   43        * The current page context.
   44        */
   45       private PageContext pageContext;
   46   
   47       /**
   48        * The writer response to use.
   49        */
   50       private JspWriterResponse response;
   51   
   52       /**
   53        * Constructor.
   54        *
   55        * @param context The servlet context to use.
   56        * @param pageContext The page context to use.
   57        */
   58       public JspTilesRequestContext(ServletContext context, PageContext pageContext) {
   59           super(context,
   60               (HttpServletRequest) pageContext.getRequest(),
   61               (HttpServletResponse) pageContext.getResponse());
   62           this.pageContext = pageContext;
   63       }
   64   
   65       /**
   66        * Dispatches a path. In fact it "includes" it!
   67        *
   68        * @param path The path to dispatch to.
   69        * @throws IOException If something goes wrong during dispatching.
   70        * @see org.apache.tiles.servlet.context.ServletTilesRequestContext#dispatch(java.lang.String)
   71        */
   72       public void dispatch(String path) throws IOException {
   73           include(path);
   74       }
   75   
   76       /** {@inheritDoc} */
   77       public void include(String path) throws IOException {
   78           JspUtil.setForceInclude(pageContext, true);
   79           try {
   80               pageContext.include(path, false);
   81           } catch (ServletException e) {
   82               throw wrapServletException(e, "JSPException including path '"
   83                       + path + "'.");
   84           }
   85       }
   86   
   87       /** {@inheritDoc} */
   88       public HttpServletResponse getResponse() {
   89           if (response == null) {
   90               response = new JspWriterResponse(pageContext);
   91           }
   92           return response;
   93       }
   94   
   95   }

Save This Page
Home » tiles-2.0.6-src » org.apache.tiles.jsp » context » [javadoc | source]