mrglavas 2004/05/14 12:37:54 Modified: java/src/org/apache/xml/serialize XML11Serializer.java BaseMarkupSerializer.java XMLSerializer.java DOMSerializerImpl.java Log: Fixing Jira Bug #961:
http://nagoya.apache.org/jira/browse/XERCESJ-961 When 'split-cdata-sections' is false, unrepresentable characters in a CDATAsection should be reported as "wf-invalid-character" errors if the parameter "well-formed" is set to true. The error is not recoverable. We were not reporting the correct error type nor was the serializer being unconditionally halted. It was not throwing the expected LSException. This is fixed thanks to the patch by Jonathan Au. Revision Changes Path 1.10 +3 -3 xml-xerces/java/src/org/apache/xml/serialize/XML11Serializer.java Index: XML11Serializer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/XML11Serializer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XML11Serializer.java 24 Feb 2004 23:34:03 -0000 1.9 +++ XML11Serializer.java 14 May 2004 19:37:53 -0000 1.10 @@ -311,7 +311,7 @@ modifyDOMError( msg, DOMError.SEVERITY_FATAL_ERROR, - fCurrentNode); + null, fCurrentNode); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); if (!continueProcess) { @@ -327,7 +327,7 @@ modifyDOMError( msg, DOMError.SEVERITY_WARNING, - fCurrentNode); + null, fCurrentNode); fDOMErrorHandler.handleError(fDOMError); } } 1.54 +24 -20 xml-xerces/java/src/org/apache/xml/serialize/BaseMarkupSerializer.java Index: BaseMarkupSerializer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/BaseMarkupSerializer.java,v retrieving revision 1.53 retrieving revision 1.54 diff -u -r1.53 -r1.54 --- BaseMarkupSerializer.java 29 Mar 2004 19:19:31 -0000 1.53 +++ BaseMarkupSerializer.java 14 May 2004 19:37:53 -0000 1.54 @@ -64,6 +64,7 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Notation; +import org.w3c.dom.ls.LSException; import org.w3c.dom.ls.LSSerializerFilter; import org.w3c.dom.traversal.NodeFilter; import org.xml.sax.ContentHandler; @@ -1412,23 +1413,24 @@ if (fDOMErrorHandler != null) { // REVISIT: this means that if DOM Error handler is not registered we don't report any // fatal errors and might serialize not wellformed document - if ((features & DOMSerializerImpl.SPLITCDATA) == 0 - && (features & DOMSerializerImpl.WELLFORMED) == 0) { - // issue fatal error - String msg = - DOMMessageFormatter.formatMessage( - DOMMessageFormatter.SERIALIZER_DOMAIN, - "EndingCDATA", - null); - modifyDOMError( - msg, - DOMError.SEVERITY_FATAL_ERROR, - fCurrentNode); - boolean continueProcess = + if ((features & DOMSerializerImpl.SPLITCDATA) == 0) { + String msg = DOMMessageFormatter.formatMessage( + DOMMessageFormatter.SERIALIZER_DOMAIN, + "EndingCDATA", + null); + if ((features & DOMSerializerImpl.WELLFORMED) != 0) { + // issue fatal error + modifyDOMError(msg, DOMError.SEVERITY_FATAL_ERROR, "wf-invalid-character", fCurrentNode); fDOMErrorHandler.handleError(fDOMError); - if (!continueProcess) { - throw new IOException(); - } + throw new LSException(LSException.SERIALIZE_ERR, msg); + } + else { + // issue error + modifyDOMError(msg, DOMError.SEVERITY_ERROR, "cdata-section-not-splitted", fCurrentNode); + if (!fDOMErrorHandler.handleError(fDOMError)) { + throw new LSException(LSException.SERIALIZE_ERR, msg); + } + } } else { // issue warning String msg = @@ -1439,7 +1441,7 @@ modifyDOMError( msg, DOMError.SEVERITY_WARNING, - fCurrentNode); + null, fCurrentNode); fDOMErrorHandler.handleError(fDOMError); } } @@ -1811,11 +1813,13 @@ * * @param message * @param severity + * @param type * @return a DOMError */ - protected DOMError modifyDOMError(String message, short severity, Node node){ + protected DOMError modifyDOMError(String message, short severity, String type, Node node){ fDOMError.reset(); fDOMError.fMessage = message; + fDOMError.fType = type; fDOMError.fSeverity = severity; fDOMError.fLocator = new DOMLocatorImpl(-1, -1, -1, node, null); return fDOMError; @@ -1825,7 +1829,7 @@ protected void fatalError(String message) throws IOException{ if (fDOMErrorHandler != null) { - modifyDOMError(message, DOMError.SEVERITY_FATAL_ERROR, fCurrentNode); + modifyDOMError(message, DOMError.SEVERITY_FATAL_ERROR, null, fCurrentNode); fDOMErrorHandler.handleError(fDOMError); } else { 1.62 +4 -4 xml-xerces/java/src/org/apache/xml/serialize/XMLSerializer.java Index: XMLSerializer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/XMLSerializer.java,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- XMLSerializer.java 7 May 2004 21:35:35 -0000 1.61 +++ XMLSerializer.java 14 May 2004 19:37:53 -0000 1.62 @@ -742,7 +742,7 @@ if (fDOMErrorHandler != null) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.XML_DOMAIN,"CantBindXMLNS",null ); - modifyDOMError(msg, DOMError.SEVERITY_ERROR, attr); + modifyDOMError(msg, DOMError.SEVERITY_ERROR, null, attr); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); if (!continueProcess) { // stop the namespace fixup and validation @@ -859,7 +859,7 @@ String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", new Object[]{elem.getNodeName()}); - modifyDOMError(msg,DOMError.SEVERITY_ERROR, elem); + modifyDOMError(msg,DOMError.SEVERITY_ERROR, null, elem); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); // REVISIT: should we terminate upon request? if (!continueProcess) { @@ -1032,7 +1032,7 @@ String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "NullLocalAttrName", new Object[]{attr.getNodeName()}); - modifyDOMError(msg, DOMError.SEVERITY_ERROR, attr); + modifyDOMError(msg, DOMError.SEVERITY_ERROR, null, attr); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); if (!continueProcess) { // stop the namespace fixup and validation 1.23 +3 -1 xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java Index: DOMSerializerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- DOMSerializerImpl.java 7 May 2004 21:35:35 -0000 1.22 +++ DOMSerializerImpl.java 14 May 2004 19:37:53 -0000 1.23 @@ -499,6 +499,8 @@ ser.serialize((Element)wnode); else return null; + } catch (LSException lse){ + throw lse; } catch (RuntimeException e) { if (e == DOMNormalizer.abort){ // stopped at user request --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]