org.apache.cocoon.selection
Class ExceptionSelector

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.selection.AbstractSwitchSelector
          extended byorg.apache.cocoon.selection.ExceptionSelector
All Implemented Interfaces:
Configurable, org.apache.cocoon.selection.Selector, org.apache.cocoon.selection.SwitchSelector, ThreadSafe
Direct Known Subclasses:
XPathExceptionSelector

public class ExceptionSelector
extends org.apache.cocoon.selection.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:
    $Id: ExceptionSelector.html 1304280 2012-03-23 11:18:01Z ilgrosso $

    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)
               
     
    Methods inherited from class org.apache.cocoon.selection.AbstractSwitchSelector
    select
     
    Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
    getLogger, setLogger
     
    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 org.apache.cocoon.selection.SwitchSelector
    See Also:
    ObjectModelHelper.getThrowable(java.util.Map)

    select

    public boolean select(String expression,
                          Object selectorContext)
    Specified by:
    select in interface org.apache.cocoon.selection.SwitchSelector


    Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.