org.apache.cocoon.selection
Class ExceptionSelector

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.selection.AbstractSwitchSelector
          extended by org.apache.cocoon.selection.ExceptionSelector
All Implemented Interfaces:
Component, Configurable, LogEnabled, ThreadSafe, Selector, SwitchSelector
Direct Known Subclasses:
XPathExceptionSelector

public class ExceptionSelector
extends AbstractSwitchSelector
implements Configurable

In a <map:handle-errors>, selects depending on the exception that caused the error. The configuration of this selector allows to map exception class names to symbolic names that are used in the <map:when> alternatives.

Example configuration :

   <map:selector type="error" src="....ExceptionSelector">
     <exception class="org.xml.sax.SAXException" name="sax" unroll="true"/>
     <exception name="not-found" class="org.apache.cocoon.ResourceNotFoundException"/>
     <exception class="org.apache.cocoon.ProcessingException" unroll="true"/>
     <exception name="denied" class="java.security.SecurityException"/>
     <exception name="denied" class="my.comp.auth.AuthenticationFailure"/>
   </map:selector>
 
This example shows several features :
  • the "class" is the class name of the exception (which can be any Throwable),
  • an exception can be given a name, which is used in the <map:when> tests,
  • an exception can be unrolled, meaning we try to get its cause and then consider this cause for the exception name
  • Note that both "name" and "unroll" can be specified. In that case, we first try to unroll the exception, and if none of the causes has a name, then the "name" attribute is considered.

    Since:
    2.1
    Version:
    CVS $Id: ExceptionSelector.html 1304258 2012-03-23 10:09:27Z ilgrosso $
    Author:
    Jürgen Seitz, Björn Lütkemeier, Sylvain Wallez

    Field Summary
     
    Fields inherited from interface org.apache.cocoon.selection.SwitchSelector
    ROLE
     
    Constructor Summary
    ExceptionSelector()
               
     
    Method Summary
     void configure(Configuration conf)
               
     Object getSelectorContext(Map objectModel, Parameters parameters)
              Compute the exception type, given the configuration and the exception stored in the object model.
     boolean select(String expression, Object selectorContext)
              Switch Selectors test patterns against a context object and signal success with the returned boolean value
     
    Methods inherited from class org.apache.cocoon.selection.AbstractSwitchSelector
    select
     
    Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
    enableLogging, getLogger, setupLogger, setupLogger, setupLogger
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    ExceptionSelector

    public ExceptionSelector()
    Method Detail

    configure

    public void configure(Configuration conf)
                   throws ConfigurationException
    Specified by:
    configure in interface Configurable
    Throws:
    ConfigurationException

    getSelectorContext

    public Object getSelectorContext(Map objectModel,
                                     Parameters parameters)
    Compute the exception type, given the configuration and the exception stored in the object model.

    Specified by:
    getSelectorContext in interface SwitchSelector
    Parameters:
    objectModel - The Map containing object of the calling environment which may be used to select values to test the expression.
    parameters - The sitemap parameters, as specified by <parameter/> tags.
    Returns:
    Selector context
    See Also:
    ObjectModelHelper.getThrowable(java.util.Map)

    select

    public boolean select(String expression,
                          Object selectorContext)
    Description copied from interface: SwitchSelector
    Switch Selectors test patterns against a context object and signal success with the returned boolean value

    Specified by:
    select in interface SwitchSelector
    Parameters:
    expression - The expression to test.
    selectorContext - The context this test should be performed in.
    Returns:
    true if the test was successful.


    Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.