View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.el;
20  
21  import javax.el.ELContext;
22  import javax.faces.context.FacesContext;
23  
24  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
25  import org.apache.myfaces.shared.util.WebConfigParamUtils;
26  
27  public class ContextAwareUtils
28  {
29      /**
30       * Wrap exception caused by calls to EL expressions, so information like
31       * the location, expression string and tag name can be retrieved by
32       * the ExceptionHandler implementation and used to output meaningful information about itself.
33       * 
34       * <p>Note in some cases this will wrap the original javax.el.ELException, so the
35       * information will not be on the stack trace unless ExceptionHandler
36       * retrieve checking if the exception implements ContextAware interface and calling getWrapped() method.
37       * </p>
38       * 
39       */
40      @JSFWebConfigParam(since="2.0.9, 2.1.3" , defaultValue="true", expectedValues="true, false")
41      public static final String INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE
42              = "org.apache.myfaces.WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE";
43      
44      public static boolean isWrapTagExceptionsAsContextAware(ELContext context)
45      {
46          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
47          facesContext = facesContext == null ? FacesContext.getCurrentInstance() : facesContext;
48          if (facesContext != null)
49          {
50              return WebConfigParamUtils.getBooleanInitParameter(facesContext.getExternalContext(),
51                      INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE, true);
52          }
53          else
54          {
55              //No facesContext, return false
56              return false;
57          }
58      }
59  }