Home » tiles-2.2.1-src » org.apache.tiles.jsp » context » [javadoc | source]

    1   /*
    2    * $Id: JspTilesRequestContextFactory.java 711885 2008-11-06 16:06:38Z 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   
   22   package org.apache.tiles.jsp.context;
   23   
   24   import org.apache.tiles.TilesApplicationContext;
   25   import org.apache.tiles.awareness.TilesRequestContextFactoryAware;
   26   import org.apache.tiles.context.TilesRequestContext;
   27   import org.apache.tiles.context.TilesRequestContextFactory;
   28   import org.apache.tiles.servlet.context.ServletTilesRequestContext;
   29   
   30   import javax.servlet.ServletRequest;
   31   import javax.servlet.ServletResponse;
   32   import javax.servlet.http.HttpServletRequest;
   33   import javax.servlet.http.HttpServletResponse;
   34   import javax.servlet.jsp.PageContext;
   35   import java.util.Map;
   36   
   37   /**
   38    * Creates an instance of the appropriate {@link TilesRequestContext}
   39    * implementation under a JSP environment.
   40    *
   41    * @version $Rev: 711885 $ $Date: 2008-11-06 17:06:38 +0100 (gio, 06 nov 2008) $
   42    * @since 2.1.1
   43    */
   44   public class JspTilesRequestContextFactory implements TilesRequestContextFactory,
   45           TilesRequestContextFactoryAware {
   46   
   47       /**
   48        * Parent Tiles context factory.
   49        */
   50       private TilesRequestContextFactory parent;
   51   
   52       /** {@inheritDoc} */
   53       public void init(Map<String, String> configParameters) {
   54       }
   55   
   56       /** {@inheritDoc} */
   57       public void setRequestContextFactory(
   58               TilesRequestContextFactory contextFactory) {
   59           parent = contextFactory;
   60       }
   61   
   62       /** {@inheritDoc} */
   63       public TilesRequestContext createRequestContext(
   64               TilesApplicationContext context, Object... requestItems) {
   65           if (requestItems.length == 1 && requestItems[0] instanceof PageContext) {
   66               PageContext pageContext = (PageContext) requestItems[0];
   67               ServletRequest request = pageContext.getRequest();
   68               ServletResponse response = pageContext.getResponse();
   69               TilesRequestContext enclosedRequest;
   70               if (parent != null) {
   71                   enclosedRequest = parent.createRequestContext(context, request,
   72                           response);
   73               } else {
   74                   enclosedRequest = new ServletTilesRequestContext(context,
   75                           (HttpServletRequest) request,
   76                           (HttpServletResponse) response);
   77               }
   78               return new JspTilesRequestContext(enclosedRequest, pageContext);
   79           }
   80   
   81           return null;
   82       }
   83   }

Home » tiles-2.2.1-src » org.apache.tiles.jsp » context » [javadoc | source]