# HG changeset patch # User andrew # Date 1317225197 -3600 # Node ID c20bbcc510fff60996e6c363d52530d2460b6245 # Parent 47ef99bcbcb0b6e799abfe7bb0a21eebf2024242 6923146: Upgrade to JAXP 1.4.3 diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/dom/NodeCounter.java --- a/sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/dom/NodeCounter.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/dom/NodeCounter.java Wed Sep 28 16:53:17 2011 +0100 @@ -29,7 +29,6 @@ import com.sun.org.apache.xalan.internal.xsltc.Translet; import com.sun.org.apache.xml.internal.dtm.DTM; import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; -import com.sun.org.apache.xml.internal.dtm.Axis; /** * @author Jacek Ambroziak @@ -69,7 +68,7 @@ private final static String[] Ones = {"", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"}; - private StringBuffer _tempBuffer = new StringBuffer(); + private StringBuilder _tempBuffer = new StringBuilder(); /** * Indicates if this instance of xsl:number has a from pattern. @@ -114,16 +113,70 @@ _lang = lang; _groupSep = groupSep; _letterValue = letterValue; - - try { - _groupSize = Integer.parseInt(groupSize); - } - catch (NumberFormatException e) { - _groupSize = 0; - } + _groupSize = parseStringToAnInt(groupSize); setTokens(format); } + + /** + * Effectively does the same thing as Integer.parseInt(String s) except + * instead of throwing a NumberFormatException, it returns 0. This method + * is used instead of Integer.parseInt() since it does not incur the + * overhead of throwing an Exception which is expensive. + * + * @param s A String to be parsed into an int. + * @return Either an int represented by the incoming String s, or 0 if + * the parsing is not successful. + */ + private int parseStringToAnInt(String s) { + if (s == null) + return 0; + + int result = 0; + boolean negative = false; + int radix = 10, i = 0, max = s.length(); + int limit, multmin, digit; + + if (max > 0) { + if (s.charAt(0) == '-') { + negative = true; + limit = Integer.MIN_VALUE; + i++; + } else { + limit = -Integer.MAX_VALUE; + } + multmin = limit / radix; + if (i < max) { + digit = Character.digit(s.charAt(i++), radix); + if (digit < 0) + return 0; + else + result = -digit; + } + while (i < max) { + // Accumulating negatively avoids surprises near MAX_VALUE + digit = Character.digit(s.charAt(i++), radix); + if (digit < 0) + return 0; + if (result < multmin) + return 0; + result *= radix; + if (result < limit + digit) + return 0; + result -= digit; + } + } else { + return 0; + } + if (negative) { + if (i > 1) + return result; + else /* Only got "-" */ + return 0; + } else { + return -result; + } + } // format == null assumed here private final void setTokens(final String format){ @@ -240,7 +293,6 @@ */ protected String formatNumbers(int[] values) { final int nValues = values.length; - final int length = _format.length(); boolean isEmpty = true; for (int i = 0; i < nValues; i++) @@ -252,7 +304,7 @@ boolean isFirst = true; int t = 0, n = 0, s = 1; _tempBuffer.setLength(0); - final StringBuffer buffer = _tempBuffer; + final StringBuilder buffer = _tempBuffer; // Append separation token before first digit/letter/numeral if (_separFirst) buffer.append((String)_separToks.elementAt(0)); @@ -280,15 +332,15 @@ * This method is based on saxon (Michael Kay) and only implements * lang="en". */ - private void formatValue(int value, String format, StringBuffer buffer) { + private void formatValue(int value, String format, StringBuilder buffer) { char c = format.charAt(0); if (Character.isDigit(c)) { char zero = (char)(c - Character.getNumericValue(c)); - StringBuffer temp = buffer; + StringBuilder temp = buffer; if (_groupSize > 0) { - temp = new StringBuffer(); + temp = new StringBuilder(); } String s = ""; int n = value; diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java --- a/sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java Wed Sep 28 16:53:17 2011 +0100 @@ -34,55 +34,55 @@ */ public final class StringValueHandler extends EmptySerializer { - private StringBuffer _buffer = new StringBuffer(); + private StringBuilder _buffer = new StringBuilder(); private String _str = null; private static final String EMPTY_STR = ""; private boolean m_escaping = false; private int _nestedLevel = 0; - - public void characters(char[] ch, int off, int len) - throws SAXException + + public void characters(char[] ch, int off, int len) + throws SAXException { - if (_nestedLevel > 0) - return; - - if (_str != null) { - _buffer.append(_str); - _str = null; - } - _buffer.append(ch, off, len); + if (_nestedLevel > 0) + return; + + if (_str != null) { + _buffer.append(_str); + _str = null; + } + _buffer.append(ch, off, len); } public String getValue() { - if (_buffer.length() != 0) { - String result = _buffer.toString(); - _buffer.setLength(0); - return result; - } - else { - String result = _str; - _str = null; - return (result != null) ? result : EMPTY_STR; - } + if (_buffer.length() != 0) { + String result = _buffer.toString(); + _buffer.setLength(0); + return result; + } + else { + String result = _str; + _str = null; + return (result != null) ? result : EMPTY_STR; + } } public void characters(String characters) throws SAXException { - if (_nestedLevel > 0) - return; + if (_nestedLevel > 0) + return; - if (_str == null && _buffer.length() == 0) { - _str = characters; - } - else { - if (_str != null) { - _buffer.append(_str); - _str = null; - } - - _buffer.append(characters); - } + if (_str == null && _buffer.length() == 0) { + _str = characters; + } + else { + if (_str != null) { + _buffer.append(_str); + _str = null; + } + + _buffer.append(characters); + } } - + public void startElement(String qname) throws SAXException { _nestedLevel++; } @@ -102,26 +102,26 @@ /** * The value of a PI must not contain the substring "?>". Should - * that substring be present, replace it by "? >". + * that substring be present, replace it by "? >". */ public String getValueOfPI() { - final String value = getValue(); + final String value = getValue(); - if (value.indexOf("?>") > 0) { - final int n = value.length(); - final StringBuffer valueOfPI = new StringBuffer(); + if (value.indexOf("?>") > 0) { + final int n = value.length(); + final StringBuilder valueOfPI = new StringBuilder(); - for (int i = 0; i < n;) { - final char ch = value.charAt(i++); - if (ch == '?' && value.charAt(i) == '>') { - valueOfPI.append("? >"); i++; - } - else { - valueOfPI.append(ch); - } - } - return valueOfPI.toString(); - } - return value; + for (int i = 0; i < n;) { + final char ch = value.charAt(i++); + if (ch == '?' && value.charAt(i) == '>') { + valueOfPI.append("? >"); i++; + } + else { + valueOfPI.append(ch); + } + } + return valueOfPI.toString(); + } + return value; } } diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java --- a/sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Wed Sep 28 16:53:17 2011 +0100 @@ -207,7 +207,7 @@ /** *
State of secure processing feature.
*/ - private boolean _isSecureProcessing = false; + private boolean _isNotSecureProcessing = true; /** *State of secure mode.
*/ @@ -219,7 +219,7 @@ m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(); if (System.getSecurityManager() != null) { _isSecureMode = true; - _isSecureProcessing = true; + _isNotSecureProcessing = false; } } @@ -416,7 +416,7 @@ ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE); throw new TransformerConfigurationException(err.toString()); } - _isSecureProcessing = value; + _isNotSecureProcessing = !value; // all done processing feature return; } @@ -465,7 +465,7 @@ } // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { - return _isSecureProcessing; + return !_isNotSecureProcessing; } // Feature not supported @@ -546,7 +546,7 @@ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); - if (_isSecureProcessing) { + if (!_isNotSecureProcessing) { try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } @@ -610,7 +610,7 @@ result.setURIResolver(_uriResolver); } - if (_isSecureProcessing) { + if (!_isNotSecureProcessing) { result.setSecureProcessing(true); } return result; @@ -756,7 +756,7 @@ final XSLTC xsltc = new XSLTC(); if (_debug) xsltc.setDebug(true); if (_enableInlining) xsltc.setTemplateInlining(true); - if (_isSecureProcessing) xsltc.setSecureProcessing(true); + if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true); xsltc.init(); // Set a document loader (for xsl:include/import) if defined diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xerces/internal/dom/DeferredDocumentImpl.java --- a/sources/jaxp_src/src/com/sun/org/apache/xerces/internal/dom/DeferredDocumentImpl.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xerces/internal/dom/DeferredDocumentImpl.java Wed Sep 28 16:53:17 2011 +0100 @@ -40,7 +40,7 @@ * * @xerces.internal * - * @version $Id: DeferredDocumentImpl.java,v 1.6 2009/09/09 23:09:49 joehw Exp $ + * @version $Id: DeferredDocumentImpl.java,v 1.7 2009/12/01 06:12:02 joehw Exp $ * @since PR-DOM-Level-1-19980818. */ public class DeferredDocumentImpl @@ -132,7 +132,7 @@ // // private data // - private transient final StringBuffer fBufferStr = new StringBuffer(); + private transient final StringBuilder fBufferStr = new StringBuilder(); private transient final Vector fStrChunks = new Vector(); // @@ -430,8 +430,6 @@ // get element's last attribute int lastAttrNodeIndex = getChunkIndex(fNodeExtra, elementChunk, elementIndex); if (lastAttrNodeIndex != 0) { - int lastAttrChunk = lastAttrNodeIndex >> CHUNK_SHIFT; - int lastAttrIndex = lastAttrNodeIndex & CHUNK_MASK; // add link from new attribute to last attribute setChunkIndex(fNodePrevSib, lastAttrNodeIndex, attrChunk, attrIndex); } diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/AbstractDOMParser.java --- a/sources/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/AbstractDOMParser.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/AbstractDOMParser.java Wed Sep 28 16:53:17 2011 +0100 @@ -84,6 +84,7 @@ * @author Andy Clark, IBM * @author Elena Litani, IBM * + * @version $Id: AbstractDOMParser.java,v 1.5 2009/12/01 06:12:03 joehw Exp $ */ public class AbstractDOMParser extends AbstractXMLDocumentParser { @@ -216,14 +217,14 @@ protected int fDeferredEntityDecl; /** Character buffer */ - protected final StringBuffer fStringBuffer = new StringBuffer (50); + protected final StringBuilder fStringBuilder = new StringBuilder (50); // internal subset /** Internal subset buffer. */ - protected StringBuffer fInternalSubset; + protected StringBuilder fInternalSubset; - // deferred expansion data + // deferred expansion datfInternalSubseta protected boolean fDeferNodeExpansion; protected boolean fNamespaceAware; @@ -413,7 +414,7 @@ fCurrentNode = null; // reset string buffer - fStringBuffer.setLength (0); + fStringBuilder.setLength (0); // reset state information fRoot.clear(); @@ -1147,14 +1148,14 @@ // collect all the data into the string buffer. if (fFirstChunk) { if (fDocumentImpl != null) { - fStringBuffer.append (((TextImpl)child).removeData ()); + fStringBuilder.append (((TextImpl)child).removeData ()); } else { - fStringBuffer.append (((Text)child).getData ()); + fStringBuilder.append (((Text)child).getData ()); ((Text)child).setNodeValue (null); } fFirstChunk = false; } - fStringBuffer.append (value); + fStringBuilder.append (value); } else { fFirstChunk = true; @@ -1749,7 +1750,7 @@ fBaseURIStack.push (locator.getBaseSystemId ()); } if (fDeferNodeExpansion || fDocumentImpl != null) { - fInternalSubset = new StringBuffer (1024); + fInternalSubset = new StringBuilder (1024); } } // startDTD(XMLLocator) @@ -2525,18 +2526,18 @@ Node child = fCurrentNode.getLastChild (); if (child != null) { - if (fStringBuffer.length () > 0) { + if (fStringBuilder.length () > 0) { // REVISIT: should this check be performed? if (child.getNodeType () == Node.TEXT_NODE) { if (fDocumentImpl != null) { - ((TextImpl)child).replaceData (fStringBuffer.toString ()); + ((TextImpl)child).replaceData (fStringBuilder.toString ()); } else { - ((Text)child).setData (fStringBuffer.toString ()); + ((Text)child).setData (fStringBuilder.toString ()); } } // reset string buffer - fStringBuffer.setLength (0); + fStringBuilder.setLength (0); } if (fDOMFilter !=null && !fInEntityRef) { diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xerces/internal/util/NamespaceContextWrapper.java --- a/sources/jaxp_src/src/com/sun/org/apache/xerces/internal/util/NamespaceContextWrapper.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xerces/internal/util/NamespaceContextWrapper.java Wed Sep 28 16:53:17 2011 +0100 @@ -30,9 +30,9 @@ import javax.xml.namespace.NamespaceContext; /** - * Writing a wrapper to re-use most of the namespace functionality + * Writing a wrapper to re-use most of the namespace functionality * already provided by NamespaceSupport, which implements NamespaceContext - * from XNI. It would be good if we can change the XNI NamespaceContext + * from XNI. It would be good if we can change the XNI NamespaceContext * interface to implement the JAXP NamespaceContext interface. * * Note that NamespaceSupport assumes the use of symbols. Since this class @@ -44,42 +44,42 @@ * */ public class NamespaceContextWrapper implements NamespaceContext { - + private com.sun.org.apache.xerces.internal.xni.NamespaceContext fNamespaceContext; - + public NamespaceContextWrapper(NamespaceSupport namespaceContext) { fNamespaceContext = namespaceContext ; } - + public String getNamespaceURI(String prefix) { if (prefix == null) { throw new IllegalArgumentException("Prefix can't be null"); } return fNamespaceContext.getURI(prefix.intern()); } - + public String getPrefix(String namespaceURI) { - if (namespaceURI == null || namespaceURI.trim().length() == 0) { - throw new IllegalArgumentException("URI can't be null or empty String"); + if (namespaceURI == null) { + throw new IllegalArgumentException("URI can't be null."); } return fNamespaceContext.getPrefix(namespaceURI.intern()); } - + /** * TODO: Namespace doesn't give information giving multiple prefixes for * the same namespaceURI. */ public java.util.Iterator getPrefixes(String namespaceURI) { - if (namespaceURI == null || namespaceURI.trim().length() == 0) { - throw new IllegalArgumentException("URI can't be null or empty String"); - } + if (namespaceURI == null) { + throw new IllegalArgumentException("URI can't be null."); + } else { - Vector vector = + Vector vector = ((NamespaceSupport) fNamespaceContext).getPrefixes(namespaceURI.intern()); return vector.iterator(); } } - + /** * This method supports all functions in the NamespaceContext utility class */ diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java --- a/sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java Wed Sep 28 16:53:17 2011 +0100 @@ -28,7 +28,7 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashMap; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import java.security.AccessController; @@ -54,7 +54,7 @@ final class CharInfo { /** Given a character, lookup a String to output (e.g. a decorated entity reference). */ - private Hashtable m_charToString = new Hashtable(); + private HashMap m_charToString = new HashMap(); /** * The name of the HTML entities file. @@ -360,7 +360,7 @@ */ private void defineEntity(String name, char value) { - StringBuffer sb = new StringBuffer("&"); + StringBuilder sb = new StringBuilder("&"); sb.append(name); sb.append(';'); String entityString = sb.toString(); @@ -534,7 +534,7 @@ } /** Table of user-specified char infos. */ - private static Hashtable m_getCharInfoCache = new Hashtable(); + private static HashMap m_getCharInfoCache = new HashMap(); /** * Returns the array element holding the bit value for the diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/Encodings.java --- a/sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/Encodings.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/Encodings.java Wed Sep 28 16:53:17 2011 +0100 @@ -28,14 +28,11 @@ import java.io.UnsupportedEncodingException; import java.io.Writer; import java.io.BufferedWriter; -import java.lang.reflect.Method; import java.net.URL; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Properties; import java.util.StringTokenizer; -import java.security.PrivilegedAction; -import java.security.AccessController; /** @@ -44,7 +41,7 @@ * to override encoding names and provide the last printable character * for each encoding. * - * @version $Revision: 1.8 $ $Date: 2007/10/12 04:14:45 $ + * @version $Revision: 1.9 $ $Date: 2009/12/01 22:17:31 $ * @author Assaf Arkin */ @@ -308,7 +305,6 @@ */ private static EncodingInfo[] loadEncodingInfo() { - URL url = null; try { String urlString = null; @@ -323,7 +319,7 @@ } if (urlString != null && urlString.length() > 0) { - url = new URL(urlString); + URL url = new URL(urlString); is = url.openStream(); } @@ -462,7 +458,7 @@ return codePoint; } - private static final Hashtable _encodingTableKeyJava = new Hashtable(); - private static final Hashtable _encodingTableKeyMime = new Hashtable(); + private static final HashMap _encodingTableKeyJava = new HashMap(); + private static final HashMap _encodingTableKeyMime = new HashMap(); private static final EncodingInfo[] _encodings = loadEncodingInfo(); } diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/NamespaceMappings.java --- a/sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/NamespaceMappings.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/NamespaceMappings.java Wed Sep 28 16:53:17 2011 +0100 @@ -22,8 +22,8 @@ */ package com.sun.org.apache.xml.internal.serializer; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Iterator; import java.util.Stack; import org.xml.sax.ContentHandler; @@ -33,7 +33,7 @@ * This class keeps track of the currently defined namespaces. Conceptually the * prefix/uri/depth triplets are pushed on a stack pushed on a stack. The depth * indicates the nesting depth of the element for which the mapping was made. - * + * *For example: *
*- * + * * When the@@ -45,7 +45,7 @@ * * *
State of secure processing feature.
*/ - private boolean featureSecureProcessing = false; + private boolean _isNotSecureProcessing = true; /** *State of secure mode.
*/ @@ -67,7 +67,7 @@ public XPathFactoryImpl() { if (System.getSecurityManager() != null) { _isSecureMode = true; - featureSecureProcessing = true; + _isNotSecureProcessing = false; } } @@ -119,7 +119,7 @@ public javax.xml.xpath.XPath newXPath() { return new com.sun.org.apache.xpath.internal.jaxp.XPathImpl( xPathVariableResolver, xPathFunctionResolver, - featureSecureProcessing ); + !_isNotSecureProcessing ); } /** @@ -168,7 +168,7 @@ throw new XPathFactoryConfigurationException( fmsg ); } - featureSecureProcessing = value; + _isNotSecureProcessing = !value; // all done processing feature return; @@ -217,7 +217,7 @@ // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { - return featureSecureProcessing; + return !_isNotSecureProcessing; } // unknown feature diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/xml/internal/stream/XMLInputFactoryImpl.java --- a/sources/jaxp_src/src/com/sun/xml/internal/stream/XMLInputFactoryImpl.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/xml/internal/stream/XMLInputFactoryImpl.java Wed Sep 28 16:53:17 2011 +0100 @@ -280,7 +280,24 @@ } XMLInputSource jaxpSourcetoXMLInputSource(Source source){ - throw new UnsupportedOperationException("Cannot create " + + if(source instanceof StreamSource){ + StreamSource stSource = (StreamSource)source; + String systemId = stSource.getSystemId(); + String publicId = stSource.getPublicId(); + InputStream istream = stSource.getInputStream(); + Reader reader = stSource.getReader(); + + if(istream != null){ + return new XMLInputSource(publicId, systemId, null, istream, null); + } + else if(reader != null){ + return new XMLInputSource(publicId, systemId,null, reader, null); + }else{ + return new XMLInputSource(publicId, systemId, null); + } + } + + throw new UnsupportedOperationException("Cannot create " + "XMLStreamReader or XMLEventReader from a " + source.getClass().getName()); } diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/xml/internal/stream/events/StartDocumentEvent.java --- a/sources/jaxp_src/src/com/sun/xml/internal/stream/events/StartDocumentEvent.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/xml/internal/stream/events/StartDocumentEvent.java Wed Sep 28 16:53:17 2011 +0100 @@ -43,38 +43,43 @@ protected String fEncodingScheam; protected boolean fStandalone; protected String fVersion; - private boolean fEncodingSchemeSet; - private boolean fStandaloneSet; - + private boolean fEncodingSchemeSet = false; + private boolean fStandaloneSet = false; + private boolean nestedCall = false; + public StartDocumentEvent() { - this("UTF-8","1.0",true,null); + init("UTF-8","1.0",true,null); } public StartDocumentEvent(String encoding){ - this(encoding,"1.0",true,null); + init(encoding,"1.0",true,null); } public StartDocumentEvent(String encoding, String version){ - this(encoding,version,true,null); + init(encoding,version,true,null); } public StartDocumentEvent(String encoding, String version, boolean standalone){ - this(encoding,version,standalone,null); + this.fStandaloneSet = true; + init(encoding,version,standalone,null); } public StartDocumentEvent(String encoding, String version, boolean standalone,Location loc){ - init(); + this.fStandaloneSet = true; + init(encoding, version, standalone, loc); + } + protected void init(String encoding, String version, boolean standalone,Location loc) { + setEventType(XMLStreamConstants.START_DOCUMENT); this.fEncodingScheam = encoding; this.fVersion = version; this.fStandalone = standalone; - this.fEncodingSchemeSet = false; - this.fStandaloneSet = false; - if (loc != null) { - this.fLocation = loc; + if (encoding != null && !encoding.equals("")) + this.fEncodingSchemeSet = true; + else { + this.fEncodingSchemeSet = false; + this.fEncodingScheam = "UTF-8"; } - } - protected void init() { - setEventType(XMLStreamConstants.START_DOCUMENT); + this.fLocation = loc; } public String getSystemId() { diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java --- a/sources/jaxp_src/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java Wed Sep 28 16:53:17 2011 +0100 @@ -34,6 +34,7 @@ import java.nio.charset.CharsetEncoder; import java.util.AbstractMap; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.Random; import java.util.Vector; @@ -43,6 +44,7 @@ import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.stream.StreamResult; @@ -160,6 +162,13 @@ */ private CharsetEncoder fEncoder = null; + /** + * This is used to hold the namespace for attributes which happen to have + * the same uri as the default namespace; It's added to avoid changing the + * current impl. which has many redundant code for the repair mode + */ + HashMap fAttrNamespace = null; + /** * Creates a new instance of XMLStreamWriterImpl. Uses platform's default * encoding. @@ -1482,7 +1491,7 @@ if (fIsRepairingNamespace) { repair(); - correctPrefix(currentElement); + correctPrefix(currentElement, XMLStreamConstants.START_ELEMENT); if ((currentElement.prefix != null) && (currentElement.prefix != XMLConstants.DEFAULT_NS_PREFIX)) { @@ -1518,8 +1527,13 @@ String tmp = fInternalNamespaceContext.getPrefix(attr.uri); if ((tmp == null) || (tmp != attr.prefix)) { - if (fInternalNamespaceContext.declarePrefix(attr.prefix, - attr.uri)) { + tmp = getAttrPrefix(attr.uri); + if (tmp == null) { + if (fInternalNamespaceContext.declarePrefix(attr.prefix, + attr.uri)) { + writenamespace(attr.prefix, attr.uri); + } + } else { writenamespace(attr.prefix, attr.uri); } } @@ -1529,7 +1543,7 @@ writeAttributeWithPrefix(attr.prefix, attr.localpart, attr.value); } - + fAttrNamespace = null; fAttributeCache.clear(); } @@ -1561,18 +1575,19 @@ * @param uri * @return */ - private void correctPrefix(QName attr) { + private void correctPrefix(QName attr, int type) { String tmpPrefix = null; String prefix; String uri; prefix = attr.prefix; uri = attr.uri; + boolean isSpecialCaseURI = false; if (prefix == null || prefix.equals("")) { if (uri == null) { return; } - + if (prefix == XMLConstants.DEFAULT_NS_PREFIX && uri == XMLConstants.DEFAULT_NS_PREFIX) return; @@ -1593,7 +1608,14 @@ tmpPrefix = fNamespaceContext.getPrefix(uri); if (tmpPrefix == XMLConstants.DEFAULT_NS_PREFIX) { - return; + if (type == XMLStreamConstants.START_ELEMENT) { + return; + } + else if (type == XMLStreamConstants.ATTRIBUTE) { + //the uri happens to be the same as that of the default namespace + tmpPrefix = getAttrPrefix(uri); + isSpecialCaseURI = true; + } } if (tmpPrefix == null) { @@ -1610,11 +1632,15 @@ } if (tmpPrefix == null) { - QName qname = new QName(); - qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null, uri); - fNamespaceDecls.add(qname); - fInternalNamespaceContext.declarePrefix(fSymbolTable.addSymbol( + if (isSpecialCaseURI) { + addAttrNamespace(prefix, uri); + } else { + QName qname = new QName(); + qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null, uri); + fNamespaceDecls.add(qname); + fInternalNamespaceContext.declarePrefix(fSymbolTable.addSymbol( prefix), uri); + } } } @@ -1622,6 +1648,21 @@ } /** + * return the prefix if the attribute has an uri the same as that of the default namespace + */ + private String getAttrPrefix(String uri) { + if (fAttrNamespace != null) { + return (String)fAttrNamespace.get(uri); + } + return null; + } + private void addAttrNamespace(String prefix, String uri) { + if (fAttrNamespace == null) { + fAttrNamespace = new HashMap(); + } + fAttrNamespace.put(prefix, uri); + } + /** * @param uri * @return */ @@ -1713,7 +1754,7 @@ for (i = 0; i < fAttributeCache.size(); i++) { attr = (Attribute) fAttributeCache.get(i); - correctPrefix(attr); + correctPrefix(attr, XMLStreamConstants.ATTRIBUTE); } } diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/org/xml/sax/SAXException.java --- a/sources/jaxp_src/src/org/xml/sax/SAXException.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/org/xml/sax/SAXException.java Wed Sep 28 16:53:17 2011 +0100 @@ -163,7 +163,7 @@ public String toString () { if (exception != null) { - return exception.toString(); + return super.toString() + "\n" + exception.toString(); } else { return super.toString(); } diff -r 47ef99bcbcb0 -r c20bbcc510ff sources/jaxp_src/src/org/xml/sax/SAXParseException.java --- a/sources/jaxp_src/src/org/xml/sax/SAXParseException.java Wed Sep 28 16:49:43 2011 +0100 +++ b/sources/jaxp_src/src/org/xml/sax/SAXParseException.java Wed Sep 28 16:53:17 2011 +0100 @@ -44,23 +44,24 @@ * in the original XML document, as if it came from a {@link Locator} * object. Note that although the application * will receive a SAXParseException as the argument to the handlers - * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface, - * the application is not actually required to throw the exception; - * instead, it can simply read the information in it and take a + * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface, + * the application is not actually required to throw the exception; + * instead, it can simply read the information in it and take a * different action. * - *Since this exception is a subclass of {@link org.xml.sax.SAXException + *
Since this exception is a subclass of {@link org.xml.sax.SAXException * SAXException}, it inherits the ability to wrap another exception.
* * @since SAX 1.0 * @author David Megginson + * @version 2.0.1 (sax2r2) * @see org.xml.sax.SAXException * @see org.xml.sax.Locator * @see org.xml.sax.ErrorHandler */ public class SAXParseException extends SAXException { - - + + ////////////////////////////////////////////////////////////////////// // Constructors. ////////////////////////////////////////////////////////////////////// @@ -79,16 +80,16 @@ * @see org.xml.sax.Locator */ public SAXParseException (String message, Locator locator) { - super(message); - if (locator != null) { - init(locator.getPublicId(), locator.getSystemId(), - locator.getLineNumber(), locator.getColumnNumber()); - } else { - init(null, null, -1, -1); - } + super(message); + if (locator != null) { + init(locator.getPublicId(), locator.getSystemId(), + locator.getLineNumber(), locator.getColumnNumber()); + } else { + init(null, null, -1, -1); + } } - - + + /** * Wrap an existing exception in a SAXParseException. * @@ -105,17 +106,17 @@ * @see org.xml.sax.Locator */ public SAXParseException (String message, Locator locator, - Exception e) { - super(message, e); - if (locator != null) { - init(locator.getPublicId(), locator.getSystemId(), - locator.getLineNumber(), locator.getColumnNumber()); - } else { - init(null, null, -1, -1); - } + Exception e) { + super(message, e); + if (locator != null) { + init(locator.getPublicId(), locator.getSystemId(), + locator.getLineNumber(), locator.getColumnNumber()); + } else { + init(null, null, -1, -1); + } } - - + + /** * Create a new SAXParseException. * @@ -138,13 +139,13 @@ * cause the error or warning. */ public SAXParseException (String message, String publicId, String systemId, - int lineNumber, int columnNumber) + int lineNumber, int columnNumber) { - super(message); - init(publicId, systemId, lineNumber, columnNumber); + super(message); + init(publicId, systemId, lineNumber, columnNumber); } - - + + /** * Create a new SAXParseException with an embedded exception. * @@ -170,10 +171,10 @@ * @param e Another exception to embed in this one. */ public SAXParseException (String message, String publicId, String systemId, - int lineNumber, int columnNumber, Exception e) + int lineNumber, int columnNumber, Exception e) { - super(message, e); - init(publicId, systemId, lineNumber, columnNumber); + super(message, e); + init(publicId, systemId, lineNumber, columnNumber); } @@ -188,15 +189,15 @@ * @param columnNumber The column number of the error, or -1. */ private void init (String publicId, String systemId, - int lineNumber, int columnNumber) + int lineNumber, int columnNumber) { - this.publicId = publicId; - this.systemId = systemId; - this.lineNumber = lineNumber; - this.columnNumber = columnNumber; + this.publicId = publicId; + this.systemId = systemId; + this.lineNumber = lineNumber; + this.columnNumber = columnNumber; } - - + + /** * Get the public identifier of the entity where the exception occurred. * @@ -206,10 +207,10 @@ */ public String getPublicId () { - return this.publicId; + return this.publicId; } - - + + /** * Get the system identifier of the entity where the exception occurred. * @@ -222,10 +223,10 @@ */ public String getSystemId () { - return this.systemId; + return this.systemId; } - - + + /** * The line number of the end of the text where the exception occurred. * @@ -237,10 +238,10 @@ */ public int getLineNumber () { - return this.lineNumber; + return this.lineNumber; } - - + + /** * The column number of the end of the text where the exception occurred. * @@ -252,10 +253,27 @@ */ public int getColumnNumber () { - return this.columnNumber; + return this.columnNumber; } + + /** + * Override toString to provide more detailed error message. + * + * @return A string representation of this exception. + */ + public String toString() { + StringBuilder buf = new StringBuilder(getClass().getName()); + String message = getLocalizedMessage(); + if (publicId!=null) buf.append("publicId: ").append(publicId); + if (systemId!=null) buf.append("; systemId: ").append(systemId); + if (lineNumber!=-1) buf.append("; lineNumber: ").append(lineNumber); + if (columnNumber!=-1) buf.append("; columnNumber: ").append(columnNumber); - + //append the exception message at the end + if (message!=null) buf.append("; ").append(message); + return buf.toString(); + } + ////////////////////////////////////////////////////////////////////// // Internal state. ////////////////////////////////////////////////////////////////////// @@ -264,7 +282,7 @@ /** * @serial The public identifier, or null. * @see #getPublicId - */ + */ private String publicId; @@ -287,7 +305,7 @@ * @see #getColumnNumber */ private int columnNumber; - + // Added serialVersionUID to preserve binary compatibility static final long serialVersionUID = -5651165872476709336L; }