sandygao 2002/07/22 11:08:02 Modified: java/src/org/apache/xml/serialize XMLSerializer.java SerializerFactoryImpl.java BaseMarkupSerializer.java Log: Update some of the serialization code to use the new DOM/Serializer message property files, instead of hardcoded Strings, to make localization possible. Revision Changes Path 1.37 +26 -13 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.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- XMLSerializer.java 15 Jul 2002 21:22:37 -0000 1.36 +++ XMLSerializer.java 22 Jul 2002 18:08:02 -0000 1.37 @@ -90,6 +90,7 @@ import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.NamespaceSupport; +import org.apache.xerces.dom.DOMMessageFormatter; /** * Implements an XML serializer supporting both DOM and SAX pretty @@ -251,8 +252,10 @@ } try { - if (_printer == null) - throw new IllegalStateException( "SER002 No writer supplied for serializer" ); + if (_printer == null) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null); + throw new IllegalStateException(msg); + } state = getElementState(); if (isDocumentState()) { @@ -290,8 +293,10 @@ // Do not change the current element state yet. // This only happens in endElement(). if (rawName == null || rawName.length() == 0) { - if (localName == null) - throw new SAXException( "No rawName and localName is null" ); + if (localName == null) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoName", null); + throw new SAXException(msg); + } if (namespaceURI != null && ! namespaceURI.equals( "" )) { String prefix; prefix = getPrefix( namespaceURI ); @@ -462,8 +467,10 @@ } try { - if (_printer == null) - throw new IllegalStateException( "SER002 No writer supplied for serializer" ); + if (_printer == null) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null); + throw new IllegalStateException(msg); + } state = getElementState(); if (isDocumentState()) { @@ -843,7 +850,8 @@ if (colon != colon2) { //not a QName: report an error if (fDOMErrorHandler != null) { - modifyDOMError("Element's name is not a QName: "+tagName, DOMError.SEVERITY_ERROR); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "ElementQName", new Object[]{tagName}); + modifyDOMError(msg, DOMError.SEVERITY_ERROR); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); // REVISIT: should we terminate upon request? } @@ -852,7 +860,8 @@ // if we got here no namespace processing was performed // report warnings if (fDOMErrorHandler != null) { - modifyDOMError("Element <"+tagName+"> does not belong to any namespace: prefix could be undeclared or bound to some namespace", DOMError.SEVERITY_WARNING); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "ElementPrefix", new Object[]{tagName}); + modifyDOMError(msg, DOMError.SEVERITY_WARNING); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); } } @@ -1034,7 +1043,8 @@ if (prefix.length() == 0) { // report an error - invalid namespace declaration if (fDOMErrorHandler != null) { - modifyDOMError("Namespace declaration syntax is incorrect "+name, DOMError.SEVERITY_ERROR); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "InvalidNSDecl", new Object[]{name}); + modifyDOMError(msg, DOMError.SEVERITY_ERROR); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); } // REVISIT: skip invalid declaration? @@ -1044,7 +1054,8 @@ } else if (value.length() == 0) { if (fDOMErrorHandler != null) { - modifyDOMError("Namespace declaration syntax is incorrect "+name, DOMError.SEVERITY_ERROR); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "InvalidNSDecl", new Object[]{name}); + modifyDOMError(msg, DOMError.SEVERITY_ERROR); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); } // REVISIT: skip invalid declaration? @@ -1077,7 +1088,8 @@ if (colon != colon2) { //not a QName: report an error if (fDOMErrorHandler != null) { - modifyDOMError("Attribute's name is not a QName: "+name, DOMError.SEVERITY_ERROR); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "AttributeQName", new Object[]{name}); + modifyDOMError(msg, DOMError.SEVERITY_ERROR); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); } @@ -1086,7 +1098,8 @@ // if we got here no namespace processing was performed // report warnings if (fDOMErrorHandler != null) { - modifyDOMError("Attribute '"+name+"' does not belong to any namespace: prefix could be undeclared or bound to some namespace", DOMError.SEVERITY_WARNING); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "AttributePrefix", new Object[]{name}); + modifyDOMError(msg, DOMError.SEVERITY_WARNING); boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); } } 1.7 +8 -5 xml-xerces/java/src/org/apache/xml/serialize/SerializerFactoryImpl.java Index: SerializerFactoryImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/SerializerFactoryImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SerializerFactoryImpl.java 29 Jan 2002 01:15:20 -0000 1.6 +++ SerializerFactoryImpl.java 22 Jul 2002 18:08:02 -0000 1.7 @@ -62,7 +62,7 @@ import java.io.OutputStream; import java.io.Writer; import java.io.UnsupportedEncodingException; - +import org.apache.xerces.dom.DOMMessageFormatter; /** * Default serializer factory can construct serializers for the three @@ -87,8 +87,10 @@ if ( ! _method.equals( Method.XML ) && ! _method.equals( Method.HTML ) && ! _method.equals( Method.XHTML ) && - ! _method.equals( Method.TEXT ) ) - throw new IllegalArgumentException( "SER004 The method '" + method + "' is not supported by this factory\n" + method); + ! _method.equals( Method.TEXT ) ) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{method}); + throw new IllegalArgumentException(msg); + } } @@ -137,7 +139,8 @@ } else if ( _method.equals( Method.TEXT ) ) { return new TextSerializer(); } else { - throw new IllegalStateException( "SER005 The method '" + _method + "' is not supported by this factory\n" + _method); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method}); + throw new IllegalStateException(msg); } } 1.38 +39 -21 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.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- BaseMarkupSerializer.java 19 Jul 2002 19:18:38 -0000 1.37 +++ BaseMarkupSerializer.java 22 Jul 2002 18:08:02 -0000 1.38 @@ -109,6 +109,7 @@ import org.w3c.dom.DOMLocator; import org.apache.xerces.dom.DOMErrorImpl; import org.apache.xerces.dom.DOMLocatorImpl; +import org.apache.xerces.dom.DOMMessageFormatter; import org.apache.xerces.impl.Constants; import org.w3c.dom.ls.DOMWriterFilter; @@ -333,8 +334,11 @@ public void setOutputByteStream( OutputStream output ) { - if ( output == null ) - throw new NullPointerException( "SER001 Argument 'output' is null." ); + if ( output == null ) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, + "ArgumentIsNull", new Object[]{"output"}); + throw new NullPointerException(msg); + } _output = output; _writer = null; reset(); @@ -343,8 +347,11 @@ public void setOutputCharStream( Writer writer ) { - if ( writer == null ) - throw new NullPointerException( "SER001 Argument 'writer' is null." ); + if ( writer == null ) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, + "ArgumentIsNull", new Object[]{"writer"}); + throw new NullPointerException(msg); + } _writer = writer; _output = null; reset(); @@ -353,8 +360,11 @@ public void setOutputFormat( OutputFormat format ) { - if ( format == null ) - throw new NullPointerException( "SER001 Argument 'format' is null." ); + if ( format == null ) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, + "ArgumentIsNull", new Object[]{"format"}); + throw new NullPointerException(msg); + } _format = format; reset(); } @@ -362,8 +372,11 @@ public boolean reset() { - if ( _elementStateCount > 1 ) - throw new IllegalStateException( "Serializer reset in the middle of serialization" ); + if ( _elementStateCount > 1 ) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, + "ResetInMiddle", null); + throw new IllegalStateException(msg); + } _prepared = false; fCurrentNode = null; fStrBuffer.setLength(0); @@ -377,8 +390,11 @@ if ( _prepared ) return; - if ( _writer == null && _output == null ) - throw new IOException( "SER002 No writer supplied for serializer" ); + if ( _writer == null && _output == null ) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, + "NoWriterSupplied", null); + throw new IOException(msg); + } // If the output stream has been set, use it to construct // the writer. It is possible that the serializer has been // reused with the same output stream and different encoding. @@ -1363,17 +1379,17 @@ if (fFeatures != null && fDOMErrorHandler != null) { if (!getFeature(Constants.DOM_SPLIT_CDATA)) { // issue fatal error - modifyDOMError("The character sequence \"]]>\" must not appear in content"+ - " unless used to mark the end of a CDATA section.", DOMError.SEVERITY_FATAL_ERROR); - boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); - if (!continueProcess) { - throw new IOException(); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "EndingCDATA", null); + modifyDOMError(msg, DOMError.SEVERITY_FATAL_ERROR); + boolean continueProcess = fDOMErrorHandler.handleError(fDOMError); + if (!continueProcess) { + throw new IOException(); } } else { // issue warning - modifyDOMError("Spliting a CDATA section containing the CDATA section termination marker ']]>' ", - DOMError.SEVERITY_WARNING); - fDOMErrorHandler.handleError(fDOMError); + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "SplittingCDATA", null); + modifyDOMError(msg, DOMError.SEVERITY_WARNING); + fDOMErrorHandler.handleError(fDOMError); } } } @@ -1710,8 +1726,10 @@ //_prefixes = _elementStates[ _elementStateCount ].prefixes; -- _elementStateCount; return _elementStates[ _elementStateCount ]; - } else - throw new IllegalStateException( "Internal error: element state is zero" ); + } else { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "Internal", null); + throw new IllegalStateException(msg); + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]