mmidy 01/08/09 11:29:05
Modified: java/src/org/apache/xalan/transformer ResultTreeHandler.java
TransformerImpl.java
Log:
Implement ErrorHandler in ResultTreeHandler so that fatal errors can get
passed in to the SAXHandler. Also change the code in TransformerImpl to call
fatalError in case of an error instead of endDocument. (overlaps with URI
handling fix...)
Revision Changes Path
1.45 +100 -1
xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java
Index: ResultTreeHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- ResultTreeHandler.java 2001/08/06 21:10:31 1.44
+++ ResultTreeHandler.java 2001/08/09 18:29:05 1.45
@@ -78,6 +78,9 @@
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.SAXException;
+import org.xml.sax.ErrorHandler;
import org.xml.sax.helpers.NamespaceSupport;
import org.apache.xml.utils.NamespaceSupport2;
@@ -98,7 +101,8 @@
*/
public class ResultTreeHandler extends QueuedEvents
implements ContentHandler, LexicalHandler, TransformState,
- org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler
+ org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler,
+ ErrorHandler
{
/** Indicate whether running in Debug mode */
@@ -1668,6 +1672,101 @@
public Transformer getTransformer()
{
return m_transformer;
+ }
+
+
+ // Implement ErrorHandler
+
+ /**
+ * Receive notification of a warning.
+ *
+ * <p>SAX parsers will use this method to report conditions that
+ * are not errors or fatal errors as defined by the XML 1.0
+ * recommendation. The default behaviour is to take no action.</p>
+ *
+ * <p>The SAX parser must continue to provide normal parsing events
+ * after invoking this method: it should still be possible for the
+ * application to process the document through to the end.</p>
+ *
+ * <p>Filters may use this method to report other, non-XML warnings
+ * as well.</p>
+ *
+ * @param exception The warning information encapsulated in a
+ * SAX parse exception.
+ * @exception org.xml.sax.SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @see org.xml.sax.SAXParseException
+ */
+ public void warning (SAXParseException exception)
+ throws SAXException
+ {
+ if (m_contentHandler instanceof ErrorHandler)
+ ((ErrorHandler)m_contentHandler).warning(exception);
+ }
+
+
+ /**
+ * Receive notification of a recoverable error.
+ *
+ * <p>This corresponds to the definition of "error" in section 1.2
+ * of the W3C XML 1.0 Recommendation. For example, a validating
+ * parser would use this callback to report the violation of a
+ * validity constraint. The default behaviour is to take no
+ * action.</p>
+ *
+ * <p>The SAX parser must continue to provide normal parsing events
+ * after invoking this method: it should still be possible for the
+ * application to process the document through to the end. If the
+ * application cannot do so, then the parser should report a fatal
+ * error even if the XML 1.0 recommendation does not require it to
+ * do so.</p>
+ *
+ * <p>Filters may use this method to report other, non-XML errors
+ * as well.</p>
+ *
+ * @param exception The error information encapsulated in a
+ * SAX parse exception.
+ * @exception org.xml.sax.SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @see org.xml.sax.SAXParseException
+ */
+ public void error (SAXParseException exception)
+ throws SAXException
+ {
+ if (m_contentHandler instanceof ErrorHandler)
+ ((ErrorHandler)m_contentHandler).error(exception);
+ }
+
+
+ /**
+ * Receive notification of a non-recoverable error.
+ *
+ * <p>This corresponds to the definition of "fatal error" in
+ * section 1.2 of the W3C XML 1.0 Recommendation. For example, a
+ * parser would use this callback to report the violation of a
+ * well-formedness constraint.</p>
+ *
+ * <p>The application must assume that the document is unusable
+ * after the parser has invoked this method, and should continue
+ * (if at all) only for the sake of collecting addition error
+ * messages: in fact, SAX parsers are free to stop reporting any
+ * other events once this method has been invoked.</p>
+ *
+ * @param exception The error information encapsulated in a
+ * SAX parse exception.
+ * @exception org.xml.sax.SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @see org.xml.sax.SAXParseException
+ */
+ public void fatalError (SAXParseException exception)
+ throws SAXException
+ {
+ m_elemIsPending = false;
+ m_docEnded = true;
+ m_docPending = false;
+
+ if (m_contentHandler instanceof ErrorHandler)
+ ((ErrorHandler)m_contentHandler).fatalError(exception);
}
boolean m_isTransformClient = false;
1.114 +16 -9
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -r1.113 -r1.114
--- TransformerImpl.java 2001/08/07 21:50:47 1.113
+++ TransformerImpl.java 2001/08/09 18:29:05 1.114
@@ -1017,7 +1017,10 @@
if (fileURL.startsWith("file:///"))
{
- fileURL = fileURL.substring(8);
+ if (fileURL.substring(8).indexOf(":") >0)
+ fileURL = fileURL.substring(8);
+ else
+ fileURL = fileURL.substring(7);
}
m_outputStream = new java.io.FileOutputStream(fileURL);
@@ -1187,14 +1190,6 @@
// If an exception was thrown, we need to make sure that any waiting
// handlers can terminate, which I guess is best done by sending
// an endDocument.
- if (null != m_resultTreeHandler)
- {
- try
- {
- m_resultTreeHandler.endDocument();
- }
- catch (Exception e){}
- }
// SAXSourceLocator
while(se instanceof org.apache.xml.utils.WrappedRuntimeException)
@@ -1203,6 +1198,18 @@
if(null != e)
se = e;
}
+
+ if (null != m_resultTreeHandler)
+ {
+ try
+ {
+ if(se instanceof org.xml.sax.SAXParseException)
+
m_resultTreeHandler.fatalError((org.xml.sax.SAXParseException)se);
+ else
+ m_resultTreeHandler.fatalError(new
org.xml.sax.SAXParseException(se.getMessage(), new SAXSourceLocator(), se));
+ }
+ catch (Exception e){}
+ }
if(se instanceof TransformerException)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]