cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nigel Whitaker <nigel.whita...@deltaxml.com>
Subject XSP Error handling with SAX line & column numbers
Date Tue, 15 Jun 2004 14:00:10 GMT
Hello,

I'm a new cocoon user trying to develop an XSP which accepts XML input
from the user.  Longer term I will add browser-upload capability, but
for the moment I'm just trying to handle XML entered into a HTML textarea.

When the XML is invalid the XSP generates an
org.apache.cocoon.ProcessingException with an
org.xml.sax.SAXParseException nested 2 levels down.  Inside the
SAXParseException is information about systemId, line and column
number that I want to present to the user.

I've read the concept docs on error handling
(http://cocoon.apache.org/2.1/userdocs/concepts/errorhandling.html)
and have managed to unroll my exceptions down to the
SAXParseException:

  <map:components>
    <map:selectors default="browser">
      <map:selector name="exception" 
src="org.apache.cocoon.selection.XPathExceptionSelector">
        <exception class="org.apache.cocoon.ProcessingException" 
unroll="true"/>
        <exception name="DXPE" 
class="com.deltaxml.api.DeltaXMLProcessingException" unroll="true"/>
        <exception name="ParseProblem" 
class="org.xml.sax.SAXParseException"/>
      </map:selector>
    </map:selectors>
  </map:components>

And then configure a specific error handler for "ParseProblem" s:

  <map:handle-errors>
    <map:select type="exception">
      <map:when test="ParseProblem">
        <map:generate type="notifying"/>
        <map:transform src="saxerror.xslt">
          <map:parameter name="contextPath" value="{request:contextPath}"/>
        </map:transform>        
        <map:serialize/>
      </map:when>
      <map:otherwise>
        <map:generate type="notifying"/>
        <map:transform src="defaulterror.xslt">
          <map:parameter name="contextPath" value="{request:contextPath}"/>
        </map:transform>        
        <map:serialize/>
      </map:otherwise>
    </map:select>
  </map:handle-errors>

My problem is that I cannot get at the line/column number details in
saxerror.xslt because the notifier generator at this point has
converted everything to CDATA (I added a logging transformer after the
notifying generator), so that the SAXParseException is just CDATA
within <error:extra.../>

I've seen the Wiki entry on ErrorHandling and in particular entry no 7
about getting the exception object, but this is done in the context of
an XSP, which is a different type of generator to the notifying one.
As I'd like to stay close to the standard error handling mechansism
I'd like to avoid mixing the generators for the different types of errors
because then I'd have 2 types of generators, and possibilities for look
and feel and other types of inconsistencies.

What I'd like to do,  I suppose, is get hold of the exception
as per the XSP example but then generate events as per the notifier
style.  Is the notifying generator easily configurable/extendable
to do this?  Or perhaps, should I convert all the error handling over
to XSPs where I have access to the raw exception Objects?

Any suggestions welcome or are there alternative approaches to
handling SAXParseExceptions which I've missed? 

Using:  Cocoon-2.1.5 (standard set of blocks)
        Solaris 9 08/03 on Sparc (with latest recommended patch cluster)
        Tomcat 5.0.19
        Apache 1.3.28
        mod_jk2/2.0.2

I think cocoon generally has an excellent architecture for what I'm
trying to do and would like to resolve this final hurdle.

Thanks,

Nigel

-- 
Nigel Whitaker,  DeltaXML.com: "Change control for XML, in XML",
nigel.whitaker@deltaxml.com    http://www.deltaxml.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message