Project Tiles has retired. For details please refer to its Attic page.
JspExpressionFactoryFactory xref
View Javadoc

1   /*
2    * $Id: JspExpressionFactoryFactory.java 1229087 2012-01-09 10:35:14Z mck $
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.el;
23  
24  import javax.el.ExpressionFactory;
25  import javax.servlet.ServletContext;
26  import javax.servlet.jsp.JspFactory;
27  
28  import org.apache.tiles.request.ApplicationContext;
29  import org.apache.tiles.request.ApplicationContextAware;
30  
31  /**
32   * Uses the JSP 2.1 {@link ExpressionFactory} to be used in Tiles.
33   *
34   * @version $Rev: 1229087 $ $Date: 2012-01-09 21:35:14 +1100 (Mon, 09 Jan 2012) $
35   * @since 2.2.1
36   */
37  public class JspExpressionFactoryFactory implements ExpressionFactoryFactory,
38          ApplicationContextAware {
39  
40      /**
41       * The servlet context.
42       *
43       * @since 2.2.1
44       */
45      protected ServletContext servletContext;
46  
47      /** {@inheritDoc} */
48      public void setApplicationContext(ApplicationContext applicationContext) {
49          Object context = applicationContext.getContext();
50          if (context instanceof ServletContext) {
51              this.servletContext = (ServletContext) context;
52          } else {
53              throw new IllegalArgumentException(
54                      "The application context does not hold an instance of "
55                      + "ServletContext, consider using JuelExpressionFactoryFactory");
56          }
57      }
58  
59      /** {@inheritDoc} */
60      public ExpressionFactory getExpressionFactory() {
61          return JspFactory.getDefaultFactory().getJspApplicationContext(
62                  servletContext).getExpressionFactory();
63      }
64  }