  | |  RE: (BUG?) org.apache.xpath.compiler.XPathParser.initXPath() goin
g in to inf | RE: (BUG?) org.apache.xpath.compiler.XPathParser.initXPath() goin
g in to inf 2003-03-13 - By Tim Cronin
by making my errorlistener.fatalerror() throw the transformerException when done processing it the infinite loop goes away. when validating using org.apache.xalan.xsltc.trax.TransformerFactoryImpl to create the transformer I did not have to rethrow the exception. -----Original Message----- From: Tim Cronin [mailto:tim@(protected)] Sent: Thursday, March 13, 2003 12:20 PM To: xalan-j-users@(protected) Subject: RE: (BUG?) org.apache.xpath.compiler.XPathParser.initXPath() goin g in to infinite loop
this comment was right above the code... // Patch for Christine's gripe. She wants her errorHandler to return from // a fatal error and continue trying to parse, rather than throwing an exception. // Without the patch, that put us into an endless loop. // // %REVIEW% Is there a better way of doing this? // %REVIEW% Are there any other cases which need the safety net? // (and if so do we care right now, or should we rewrite the XPath // grammar engine and can fix it at that time?)
with org.apache.xalan.xsltc.trax.TransformerFactoryImpl you catch all the errors but it still throws the exception.
-----Original Message----- From: Tim Cronin [mailto:tim@(protected)] Sent: Thursday, March 13, 2003 12:13 PM To: xalan-j-users@(protected) Subject: (BUG?) org.apache.xpath.compiler.XPathParser.initXPath() going in to infinite loop
I'm running a transformation against an xsl stylesheet I've I get Stack overflow exception and it spins through the following org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:191) I believe this section of code is the culprit (note the comment...) catch (org.apache.xpath.XPathProcessorException e) { if(CONTINUE_AFTER_FATAL_ERROR.equals(e.getMessage())) { // What I _want_ to do is null out this XPath. // I doubt this has the desired effect, but I'm not sure what else to do. // %REVIEW%!!! initXPath(compiler, "/..", namespaceContext); } else throw e; } heres the stylesheet (it's invalid I'm trying to catch the errors <xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform> "> <xsl:template match="/"> <div> <xsl:value-of select="/Properties/Group[@(protected)=Table Heading']/Datum[@(protected)='Title']"/> hello world... </div> </xsl:template> </xsl:stylesheet> here's my calling code (ValidationHandler implements javax.xml.transform.ErrorListener) public static ValidationHandler validate(String xsl) { ValidationHandler vh = new ValidationHandler(); try { // NOTE: strong tie to org.apache.xalan.processor.TransformerFactoryImpl // if xsl processors change then Need to force this to be able to set line number attribs... TransformerFactory tf = (TransformerFactory) new org.apache.xalan.processor.TransformerFactoryImpl(); tf.setAttribute(org.apache.xalan.processor.TransformerFactoryImpl.FEATURE_SO URCE_LOCATION, Boolean.TRUE); tf.setErrorListener(vh); tf.setURIResolver(new Resolver()); XMLReader xr = XMLReaderFactory.createXMLReader(); xr.setEntityResolver(new Resolver()); Transformer transformer = tf.newTransformer(new SAXSource(xr, new InputSource(new StringReader(xsl)))); } catch (SAXException e) { DOMException de = new DOMException(DOMException.SYNTAX_ERR, "cannot validate Stylesheet"); de.initCause(e); throw de; } catch (TransformerException e) { vh.error(e); } return vh; }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE>RE: small program on converting html/xhtml to xsl:fo needed</TITLE>
<META content="MSHTML 6.00.2800.1141" name=GENERATOR></HEAD> <BODY> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2>by making my errorlistener.fatalerror()</FONT></SPAN></DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2>throw the transformerException when done processing it</FONT></SPAN></DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2>the infinite loop goes away.</FONT></SPAN></DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2>when validating using org.apache.xalan.xsltc.trax.TransformerFactoryImpl</FONT></SPAN></DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2>to create the transformer I did not have to rethrow the exception.</FONT></SPAN></DIV> <DIV><SPAN class=523403618-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=523403618-13032003></SPAN><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Tim Cronin [mailto:tim@(protected)]<BR><B>Sent:</B> Thursday, March 13, 2003 12:20 PM<BR><B>To:</B> xalan-j-users@(protected)<BR><B>Subject:</B> RE: (BUG?) org.apache.xpath.compiler.XPathParser.initXPath() goin g in to infinite loop<BR><BR></DIV></FONT> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=767182218-13032003 >this comment was right above the code...</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=767182218-13032003></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=767182218-13032003> // Patch for Christine's gripe. She wants her errorHandler to return from<BR> // a fatal error and continue trying to parse, rather than throwing an exception.<BR> // Without the patch, that put us into an endless loop.<BR> //<BR> // %REVIEW% Is there a better way of doing this?<BR> // %REVIEW% Are there any other cases which need the safety net?<BR> // (and if so do we care right now, or should we rewrite the XPath<BR> // grammar engine and can fix it at that time?)<BR></SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=767182218-13032003>with</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=767182218-13032003>org.apache.xalan.xsltc.trax.TransformerFactoryImpl< /SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=767182218-13032003>you catch all the errors but it still throws the exception.</SPAN></FONT></DIV> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Tim Cronin [mailto:tim@(protected)]<BR><B>Sent:</B> Thursday, March 13, 2003 12:13 PM<BR><B>To:</B> xalan-j-users@(protected)<BR><B>Subject:</B> (BUG?) org.apache.xpath.compiler.XPathParser.initXPath() going in to infinite loop<BR><BR></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=657010818-13032003>I'm running a transformation against an xsl stylesheet</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=657010818-13032003></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=657010818-13032003>I've</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=657010818-13032003></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=657010818-13032003>I</SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN class=657010818-13032003> get Stack overflow exception and it spins through the following</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2>org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:191 )</FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2>I believe this section of code is the culprit (note the comment...)</FONT></SPAN></DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2> catch (org.apache.xpath.XPathProcessorException e)<BR> {<BR> if(CONTINUE_AFTER_FATAL_ERROR.equals(e.getMessage()))<BR> {<BR> // What I _want_ to do is null out this XPath.<BR> // I doubt this has the desired effect, but I'm not sure what else to do.<BR> // %REVIEW%!!!<BR> initXPath(compiler, "/..", namespaceContext);<BR> }<BR> else<BR> throw e;<BR> }</FONT></SPAN></DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2>heres the stylesheet (it's invalid I'm trying to catch the errors</FONT></SPAN></DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2><xsl:stylesheet version="1.0" xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL /Transform</A>"><BR> <xsl:template match="/"><BR> <div><BR> <xsl:value-of select="/Properties/Group[@(protected)=Table Heading']/Datum[@(protected)='Title']"/><BR>hello world...<BR>   ; </div><BR> </xsl:template><BR></xsl:stylesheet></FONT></SPAN></DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2>here's my calling code (ValidationHandler implements javax.xml.transform.ErrorListener)</FONT></SPAN></DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2> public static ValidationHandler validate(String xsl)<BR>  ; {<BR> ValidationHandler vh = new ValidationHandler();</FONT></SPAN></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2> try<BR> {<BR> // NOTE: strong tie to org.apache.xalan.processor.TransformerFactoryImpl<BR> // if xsl processors change then Need to force this to be able to set line number attribs...<BR> TransformerFactory tf = (TransformerFactory) new org.apache.xalan.processor.TransformerFactoryImpl();</FONT></SPAN></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2> tf.setAttribute(org.apache.xalan.processor.TransformerFactoryImpl.FEATURE _SOURCE_LOCATION, Boolean.TRUE);<BR> tf.setErrorListener(vh);<BR> tf.setURIResolver(new Resolver());</FONT></SPAN></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2> XMLReader xr = XMLReaderFactory.createXMLReader();<BR> xr.setEntityResolver(new Resolver());</FONT></SPAN></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=657010818-13032003><FONT face=Arial color=#0000ff size=2> Transformer transformer = tf.newTransformer(new SAXSource(xr, new InputSource(new StringReader(xsl))));<BR> }<BR> catch (SAXException e)<BR> {<BR> DOMException de = new DOMException(DOMException.SYNTAX_ERR,<BR> "cannot validate Stylesheet");<BR> de.initCause(e);<BR> throw de;<BR> }<BR> catch (TransformerException e)<BR> {<BR> vh.error(e);<BR> }<BR> return vh;<BR> }<BR></FONT></SPAN></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
|
|
 |