< prev index next >

src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java

Print this page

        

*** 33,54 **** import java.nio.charset.Charset; 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; import java.util.Set; import java.util.Iterator; 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; import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.PropertyManager; import com.sun.org.apache.xerces.internal.util.NamespaceSupport; --- 33,52 ----
*** 69,79 **** * @author Neeraj Bajaj * @author K.Venugopal * @author Santiago.Pericas-Geertsen@sun.com * @author Sunitha.Reddy@sun.com */ ! public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamWriterBase { public static final String START_COMMENT = "<!--"; public static final String END_COMMENT = "-->"; public static final String DEFAULT_ENCODING = " encoding=\"utf-8\""; public static final String DEFAULT_XMLDECL = "<?xml version=\"1.0\" ?>"; --- 67,78 ---- * @author Neeraj Bajaj * @author K.Venugopal * @author Santiago.Pericas-Geertsen@sun.com * @author Sunitha.Reddy@sun.com */ ! public final class XMLStreamWriterImpl extends AbstractMap<Object, Object> ! implements XMLStreamWriterBase { public static final String START_COMMENT = "<!--"; public static final String END_COMMENT = "-->"; public static final String DEFAULT_ENCODING = " encoding=\"utf-8\""; public static final String DEFAULT_XMLDECL = "<?xml version=\"1.0\" ?>";
*** 113,128 **** private OutputStream fOutputStream = null; /** * Collects attributes when the writer is in reparing mode. */ ! private ArrayList fAttributeCache; /** * Collects namespace declarations when the writer is in reparing mode. */ ! private ArrayList fNamespaceDecls; /** * Namespace context encapsulating user specified context * and context built by the writer */ --- 112,127 ---- private OutputStream fOutputStream = null; /** * Collects attributes when the writer is in reparing mode. */ ! private ArrayList<Attribute> fAttributeCache; /** * Collects namespace declarations when the writer is in reparing mode. */ ! private ArrayList<QName> fNamespaceDecls; /** * Namespace context encapsulating user specified context * and context built by the writer */
*** 151,161 **** private ElementStack fElementStack = new ElementStack(); //Change this .-Venu final private String DEFAULT_PREFIX = fSymbolTable.addSymbol(""); ! private final ReadOnlyIterator fReadOnlyIterator = new ReadOnlyIterator(); /** * In some cases, this charset encoder is used to determine if a char is * encodable by underlying writer. For example, an 8-bit char from the * extended ASCII set is not encodable by 7-bit ASCII encoder. Unencodable --- 150,160 ---- private ElementStack fElementStack = new ElementStack(); //Change this .-Venu final private String DEFAULT_PREFIX = fSymbolTable.addSymbol(""); ! private final ReadOnlyIterator<String> fReadOnlyIterator = new ReadOnlyIterator<>(); /** * In some cases, this charset encoder is used to determine if a char is * encodable by underlying writer. For example, an 8-bit char from the * extended ASCII set is not encodable by 7-bit ASCII encoder. Unencodable
*** 166,176 **** /** * 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. * --- 165,175 ---- /** * 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<String, String> fAttrNamespace = null; /** * Creates a new instance of XMLStreamWriterImpl. Uses platform's default * encoding. *
*** 228,250 **** * Initialize an instance of this XMLStreamWriter. Allocate new instances * for all the data structures. Set internal flags based on property values. */ private void init() { fReuse = false; ! fNamespaceDecls = new ArrayList(); fPrefixGen = new Random(); ! fAttributeCache = new ArrayList(); fInternalNamespaceContext = new NamespaceSupport(); fInternalNamespaceContext.reset(); fNamespaceContext = new NamespaceContextImpl(); fNamespaceContext.internalContext = fInternalNamespaceContext; // Set internal state based on property values Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); ! fIsRepairingNamespace = ob.booleanValue(); ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS); ! setEscapeCharacters(ob.booleanValue()); } /** * Reset this instance so that it can be re-used. Do not read properties * again. The method <code>setOutput(StreamResult, encoding)</code> must --- 227,249 ---- * Initialize an instance of this XMLStreamWriter. Allocate new instances * for all the data structures. Set internal flags based on property values. */ private void init() { fReuse = false; ! fNamespaceDecls = new ArrayList<>(); fPrefixGen = new Random(); ! fAttributeCache = new ArrayList<>(); fInternalNamespaceContext = new NamespaceSupport(); fInternalNamespaceContext.reset(); fNamespaceContext = new NamespaceContextImpl(); fNamespaceContext.internalContext = fInternalNamespaceContext; // Set internal state based on property values Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); ! fIsRepairingNamespace = ob; ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS); ! setEscapeCharacters(ob); } /** * Reset this instance so that it can be re-used. Do not read properties * again. The method <code>setOutput(StreamResult, encoding)</code> must
*** 277,289 **** fStartTagOpened = false; fNamespaceContext.userContext = null; if (resetProperties) { Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); ! fIsRepairingNamespace = ob.booleanValue(); ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS); ! setEscapeCharacters(ob.booleanValue()); } } /** * Use a StreamResult to initialize the output for this XMLStreamWriter. Check --- 276,288 ---- fStartTagOpened = false; fNamespaceContext.userContext = null; if (resetProperties) { Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); ! fIsRepairingNamespace = ob; ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS); ! setEscapeCharacters(ob); } } /** * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
*** 367,376 **** --- 366,376 ---- } /** * Close this XMLStreamWriter by closing underlying writer. */ + @Override public void close() throws XMLStreamException { if (fWriter != null) { try { //fWriter.close(); fWriter.flush();
*** 390,399 **** --- 390,400 ---- } /** * Flush this XMLStreamWriter by flushin underlying writer. */ + @Override public void flush() throws XMLStreamException { try { fWriter.flush(); } catch (IOException e) { throw new XMLStreamException(e);
*** 403,412 **** --- 404,414 ---- /** * Return <code>NamespaceContext</code> being used by the writer. * * @return NamespaceContext */ + @Override public NamespaceContext getNamespaceContext() { return fNamespaceContext; } /**
*** 414,423 **** --- 416,426 ---- * uri is unknown. * * @param uri The namespace uri * @throws XMLStreamException if uri specified is "" or null */ + @Override public String getPrefix(String uri) throws XMLStreamException { return fNamespaceContext.getPrefix(uri); } /**
*** 425,434 **** --- 428,438 ---- * * @param str Property name * @throws IllegalArgumentException if the specified property is not supported * @return value associated with the specified property. */ + @Override public Object getProperty(String str) throws IllegalArgumentException { if (str == null) { throw new NullPointerException(); }
*** 444,453 **** --- 448,458 ---- /** * Set the specified URI as default namespace in the current namespace context. * * @param uri Namespace URI */ + @Override public void setDefaultNamespace(String uri) throws XMLStreamException { if (uri != null) { uri = fSymbolTable.addSymbol(uri); }
*** 477,486 **** --- 482,492 ---- * <code>XMLStreamWriter</code>. * * @param namespaceContext the namespace context to use for this writer, may not be null * @throws XMLStreamException */ + @Override public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException { fNamespaceContext.userContext = namespaceContext; }
*** 491,500 **** --- 497,507 ---- * * @param prefix * @param uri * @throws XMLStreamException */ + @Override public void setPrefix(String prefix, String uri) throws XMLStreamException { if (prefix == null) { throw new XMLStreamException("Prefix cannot be null"); }
*** 523,532 **** --- 530,540 ---- } fInternalNamespaceContext.declarePrefix(prefix, uri); } + @Override public void writeAttribute(String localName, String value) throws XMLStreamException { try { if (!fStartTagOpened) { throw new XMLStreamException(
*** 552,561 **** --- 560,570 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException { try { if (!fStartTagOpened) { throw new XMLStreamException(
*** 588,598 **** private void writeAttributeWithPrefix(String prefix, String localName, String value) throws IOException { fWriter.write(SPACE); ! if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) { fWriter.write(prefix); fWriter.write(":"); } fWriter.write(localName); --- 597,607 ---- private void writeAttributeWithPrefix(String prefix, String localName, String value) throws IOException { fWriter.write(SPACE); ! if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) { fWriter.write(prefix); fWriter.write(":"); } fWriter.write(localName);
*** 601,610 **** --- 610,620 ---- true, // true = escapeChars true); // true = escapeDoubleQuotes fWriter.write("\""); } + @Override public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException { try { if (!fStartTagOpened) { throw new XMLStreamException(
*** 627,637 **** writeAttributeWithPrefix(null, localName, value); return; } } ! if (!prefix.equals(XMLConstants.XML_NS_PREFIX) || !namespaceURI.equals(XMLConstants.XML_NS_URI)) { prefix = fSymbolTable.addSymbol(prefix); namespaceURI = fSymbolTable.addSymbol(namespaceURI); if (fInternalNamespaceContext.containsPrefixInCurrentContext(prefix)){ --- 637,648 ---- writeAttributeWithPrefix(null, localName, value); return; } } ! if (!prefix.equals(XMLConstants.XML_NS_PREFIX) || ! !namespaceURI.equals(XMLConstants.XML_NS_URI)) { prefix = fSymbolTable.addSymbol(prefix); namespaceURI = fSymbolTable.addSymbol(namespaceURI); if (fInternalNamespaceContext.containsPrefixInCurrentContext(prefix)){
*** 661,670 **** --- 672,682 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeCData(String cdata) throws XMLStreamException { try { if (cdata == null) { throw new XMLStreamException("cdata cannot be null"); }
*** 679,688 **** --- 691,701 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeCharacters(String data) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); }
*** 691,700 **** --- 704,714 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeCharacters(char[] data, int start, int len) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag();
*** 704,713 **** --- 718,728 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeComment(String comment) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); }
*** 722,731 **** --- 737,747 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeDTD(String dtd) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); }
*** 748,762 **** * @throws XMLStreamException * * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting"> * Namespaces in XML, 5.2 Namespace Defaulting</a> */ public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { // normalize namespaceURI ! String namespaceURINormalized = null; if (namespaceURI == null) { namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI } else { namespaceURINormalized = namespaceURI; } --- 764,779 ---- * @throws XMLStreamException * * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting"> * Namespaces in XML, 5.2 Namespace Defaulting</a> */ + @Override public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { // normalize namespaceURI ! String namespaceURINormalized; if (namespaceURI == null) { namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI } else { namespaceURINormalized = namespaceURI; }
*** 780,790 **** if (fInternalNamespaceContext.containsPrefixInCurrentContext("")){ String tmp = fInternalNamespaceContext.getURI(""); ! if (tmp != null && tmp != namespaceURINormalized) { throw new XMLStreamException( "xmlns has been already bound to " +tmp + ". Rebinding it to "+ namespaceURINormalized + " is an error"); } --- 797,807 ---- if (fInternalNamespaceContext.containsPrefixInCurrentContext("")){ String tmp = fInternalNamespaceContext.getURI(""); ! if (tmp != null && !tmp.equals(namespaceURINormalized)) { throw new XMLStreamException( "xmlns has been already bound to " +tmp + ". Rebinding it to "+ namespaceURINormalized + " is an error"); }
*** 796,805 **** --- 813,823 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeEmptyElement(String localName) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); }
*** 814,823 **** --- 832,842 ---- } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { if (namespaceURI == null) { throw new XMLStreamException("NamespaceURI cannot be null"); }
*** 826,835 **** --- 845,855 ---- String prefix = fNamespaceContext.getPrefix(namespaceURI); writeEmptyElement(prefix, localName, namespaceURI); } + @Override public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { try { if (localName == null) { throw new XMLStreamException("Local Name cannot be null");
*** 861,891 **** } } else { return; } ! if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) { fWriter.write(prefix); fWriter.write(":"); } fWriter.write(localName); } catch (IOException e) { throw new XMLStreamException(e); } } public void writeEndDocument() throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); } - ElementState elem = null; - while (!fElementStack.empty()) { ! elem = (ElementState) fElementStack.pop(); fInternalNamespaceContext.popContext(); if (elem.isEmpty) { //fWriter.write(CLOSE_EMPTY_ELEMENT); } else { --- 881,910 ---- } } else { return; } ! if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) { fWriter.write(prefix); fWriter.write(":"); } fWriter.write(localName); } catch (IOException e) { throw new XMLStreamException(e); } } + @Override public void writeEndDocument() throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); } while (!fElementStack.empty()) { ! ElementState elem = fElementStack.pop(); fInternalNamespaceContext.popContext(); if (elem.isEmpty) { //fWriter.write(CLOSE_EMPTY_ELEMENT); } else {
*** 905,921 **** } catch (ArrayIndexOutOfBoundsException e) { throw new XMLStreamException("No more elements to write"); } } public void writeEndElement() throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); } ! ElementState currentElement = (ElementState) fElementStack.pop(); if (currentElement == null) { throw new XMLStreamException("No element was found to write"); } --- 924,941 ---- } catch (ArrayIndexOutOfBoundsException e) { throw new XMLStreamException("No more elements to write"); } } + @Override public void writeEndElement() throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); } ! ElementState currentElement = fElementStack.pop(); if (currentElement == null) { throw new XMLStreamException("No element was found to write"); }
*** 942,951 **** --- 962,972 ---- "No element was found to write: " + e.toString(), e); } } + @Override public void writeEntityRef(String refName) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag(); }
*** 971,993 **** * @throws XMLStreamException * * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting"> * Namespaces in XML, 5.2 Namespace Defaulting</a> */ public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { // normalize namespaceURI ! String namespaceURINormalized = null; if (namespaceURI == null) { namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI } else { namespaceURINormalized = namespaceURI; } try { ! QName qname = null; if (!fStartTagOpened) { throw new IllegalStateException( "Invalid state: start tag is not opened at writeNamespace(" + prefix --- 992,1015 ---- * @throws XMLStreamException * * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting"> * Namespaces in XML, 5.2 Namespace Defaulting</a> */ + @Override public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { // normalize namespaceURI ! String namespaceURINormalized; if (namespaceURI == null) { namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI } else { namespaceURINormalized = namespaceURI; } try { ! QName qname; if (!fStartTagOpened) { throw new IllegalStateException( "Invalid state: start tag is not opened at writeNamespace(" + prefix
*** 1011,1021 **** namespaceURINormalized = fSymbolTable.addSymbol(namespaceURINormalized); if (fIsRepairingNamespace) { String tmpURI = fInternalNamespaceContext.getURI(prefix); ! if ((tmpURI != null) && (tmpURI == namespaceURINormalized)) { return; } qname = new QName(); qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null, --- 1033,1043 ---- namespaceURINormalized = fSymbolTable.addSymbol(namespaceURINormalized); if (fIsRepairingNamespace) { String tmpURI = fInternalNamespaceContext.getURI(prefix); ! if ((tmpURI != null) && (tmpURI.equals(namespaceURINormalized))) { return; } qname = new QName(); qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null,
*** 1028,1038 **** if (fInternalNamespaceContext.containsPrefixInCurrentContext(prefix)){ String tmp = fInternalNamespaceContext.getURI(prefix); ! if (tmp != null && tmp != namespaceURINormalized) { throw new XMLStreamException("prefix "+prefix+ " has been already bound to " +tmp + ". Rebinding it to "+ namespaceURINormalized+ " is an error"); --- 1050,1060 ---- if (fInternalNamespaceContext.containsPrefixInCurrentContext(prefix)){ String tmp = fInternalNamespaceContext.getURI(prefix); ! if (tmp != null && !tmp.equals(namespaceURINormalized)) { throw new XMLStreamException("prefix "+prefix+ " has been already bound to " +tmp + ". Rebinding it to "+ namespaceURINormalized+ " is an error");
*** 1049,1059 **** private void writenamespace(String prefix, String namespaceURI) throws IOException { fWriter.write(" xmlns"); ! if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) { fWriter.write(":"); fWriter.write(prefix); } fWriter.write("=\""); --- 1071,1081 ---- private void writenamespace(String prefix, String namespaceURI) throws IOException { fWriter.write(" xmlns"); ! if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) { fWriter.write(":"); fWriter.write(prefix); } fWriter.write("=\"");
*** 1062,1071 **** --- 1084,1094 ---- true, // true = escapeChars true); // true = escapeDoubleQuotes fWriter.write("\""); } + @Override public void writeProcessingInstruction(String target) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag();
*** 1088,1097 **** --- 1111,1121 ---- /** * @param target * @param data * @throws XMLStreamException */ + @Override public void writeProcessingInstruction(String target, String data) throws XMLStreamException { try { if (fStartTagOpened) { closeStartTag();
*** 1114,1133 **** --- 1138,1159 ---- /** * Writes the XML declaration. * * @throws XMLStreamException in case of an IOException */ + @Override public void writeStartDocument() throws XMLStreamException { writeStartDocument(null, null, false, false); } /** * Writes the XML declaration. * * @param version the specified version * @throws XMLStreamException in case of an IOException */ + @Override public void writeStartDocument(String version) throws XMLStreamException { writeStartDocument(null, version, false, false); } /**
*** 1141,1151 **** public void writeStartDocument(String encoding, String version) throws XMLStreamException { writeStartDocument(encoding, version, false, false); } - @Override public void writeStartDocument(String encoding, String version, boolean standalone, boolean standaloneSet) throws XMLStreamException { try { --- 1167,1176 ----
*** 1210,1222 **** } if (streamEncoding != null && !streamEncoding.equalsIgnoreCase(encoding)) { // If the equality check failed, check for charset encoding aliases boolean foundAlias = false; ! Set aliases = Charset.forName(encoding).aliases(); ! for (Iterator it = aliases.iterator(); !foundAlias && it.hasNext(); ) { ! if (streamEncoding.equalsIgnoreCase((String) it.next())) { foundAlias = true; } } // If no alias matches the encoding name, then report error if (!foundAlias) { --- 1235,1247 ---- } if (streamEncoding != null && !streamEncoding.equalsIgnoreCase(encoding)) { // If the equality check failed, check for charset encoding aliases boolean foundAlias = false; ! Set<String> aliases = Charset.forName(encoding).aliases(); ! for (Iterator<String> it = aliases.iterator(); !foundAlias && it.hasNext(); ) { ! if (streamEncoding.equalsIgnoreCase(it.next())) { foundAlias = true; } } // If no alias matches the encoding name, then report error if (!foundAlias) {
*** 1230,1239 **** --- 1255,1265 ---- /** * @param localName * @throws XMLStreamException */ + @Override public void writeStartElement(String localName) throws XMLStreamException { try { if (localName == null) { throw new XMLStreamException("Local Name cannot be null"); }
*** 1259,1268 **** --- 1285,1295 ---- /** * @param namespaceURI * @param localName * @throws XMLStreamException */ + @Override public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException { if (localName == null) { throw new XMLStreamException("Local Name cannot be null"); }
*** 1290,1299 **** --- 1317,1327 ---- * @param prefix * @param localName * @param namespaceURI * @throws XMLStreamException */ + @Override public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { try { if (localName == null) { throw new XMLStreamException("Local Name cannot be null");
*** 1535,1548 **** } fWriter.write(currentElement.localpart); int len = fNamespaceDecls.size(); ! QName qname = null; for (int i = 0; i < len; i++) { ! qname = (QName) fNamespaceDecls.get(i); if (qname != null) { if (fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri)) { writenamespace(qname.prefix, qname.uri); --- 1563,1576 ---- } fWriter.write(currentElement.localpart); int len = fNamespaceDecls.size(); ! QName qname; for (int i = 0; i < len; i++) { ! qname = fNamespaceDecls.get(i); if (qname != null) { if (fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri)) { writenamespace(qname.prefix, qname.uri);
*** 1550,1569 **** } } fNamespaceDecls.clear(); ! Attribute attr = null; for (int j = 0; j < fAttributeCache.size(); j++) { ! attr = (Attribute) fAttributeCache.get(j); if ((attr.prefix != null) && (attr.uri != null)) { if (!attr.prefix.equals("") && !attr.uri.equals("") ) { String tmp = fInternalNamespaceContext.getPrefix(attr.uri); ! if ((tmp == null) || (tmp != attr.prefix)) { tmp = getAttrPrefix(attr.uri); if (tmp == null) { if (fInternalNamespaceContext.declarePrefix(attr.prefix, attr.uri)) { writenamespace(attr.prefix, attr.uri); --- 1578,1597 ---- } } fNamespaceDecls.clear(); ! Attribute attr; for (int j = 0; j < fAttributeCache.size(); j++) { ! attr = fAttributeCache.get(j); if ((attr.prefix != null) && (attr.uri != null)) { if (!attr.prefix.equals("") && !attr.uri.equals("") ) { String tmp = fInternalNamespaceContext.getPrefix(attr.uri); ! if ((tmp == null) || (!tmp.equals(attr.prefix))) { tmp = getAttrPrefix(attr.uri); if (tmp == null) { if (fInternalNamespaceContext.declarePrefix(attr.prefix, attr.uri)) { writenamespace(attr.prefix, attr.uri);
*** 1609,1650 **** * * @param uri * @return */ 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; uri = fSymbolTable.addSymbol(uri); ! QName decl = null; for (int i = 0; i < fNamespaceDecls.size(); i++) { ! decl = (QName) fNamespaceDecls.get(i); ! if ((decl != null) && (decl.uri == attr.uri)) { attr.prefix = decl.prefix; return; } } tmpPrefix = fNamespaceContext.getPrefix(uri); ! if (tmpPrefix == XMLConstants.DEFAULT_NS_PREFIX) { if (type == XMLStreamConstants.START_ELEMENT) { return; } else if (type == XMLStreamConstants.ATTRIBUTE) { //the uri happens to be the same as that of the default namespace --- 1637,1678 ---- * * @param uri * @return */ private void correctPrefix(QName attr, int type) { ! String tmpPrefix; String prefix; String uri; prefix = attr.prefix; uri = attr.uri; boolean isSpecialCaseURI = false; ! if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { if (uri == null) { return; } ! if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix) && uri.equals(XMLConstants.DEFAULT_NS_PREFIX)) return; uri = fSymbolTable.addSymbol(uri); ! QName decl; for (int i = 0; i < fNamespaceDecls.size(); i++) { ! decl = fNamespaceDecls.get(i); ! if ((decl != null) && (decl.uri.equals(attr.uri))) { attr.prefix = decl.prefix; return; } } tmpPrefix = fNamespaceContext.getPrefix(uri); ! if (XMLConstants.DEFAULT_NS_PREFIX.equals(tmpPrefix)) { if (type == XMLStreamConstants.START_ELEMENT) { return; } else if (type == XMLStreamConstants.ATTRIBUTE) { //the uri happens to be the same as that of the default namespace
*** 1652,1662 **** isSpecialCaseURI = true; } } if (tmpPrefix == null) { ! StringBuffer genPrefix = new StringBuffer("zdef"); for (int i = 0; i < 1; i++) { genPrefix.append(fPrefixGen.nextInt()); } --- 1680,1690 ---- isSpecialCaseURI = true; } } if (tmpPrefix == null) { ! StringBuilder genPrefix = new StringBuilder("zdef"); for (int i = 0; i < 1; i++) { genPrefix.append(fPrefixGen.nextInt()); }
*** 1685,1712 **** /** * 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 */ private boolean isDefaultNamespace(String uri) { String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX); ! if (uri == defaultNamespace) { return true; } return false; } --- 1713,1740 ---- /** * 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 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 */ private boolean isDefaultNamespace(String uri) { String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX); ! if (uri.equals(defaultNamespace)) { return true; } return false; }
*** 1730,1746 **** /** * Correct's namespaces as per requirements of isReparisingNamespace property. */ protected void repair() { ! Attribute attr = null; ! Attribute attr2 = null; ElementState currentElement = fElementStack.peek(); removeDuplicateDecls(); for(int i=0 ; i< fAttributeCache.size();i++){ ! attr = (Attribute)fAttributeCache.get(i); if((attr.prefix != null && !attr.prefix.equals("")) || (attr.uri != null && !attr.uri.equals(""))) { correctPrefix(currentElement,attr); } } --- 1758,1774 ---- /** * Correct's namespaces as per requirements of isReparisingNamespace property. */ protected void repair() { ! Attribute attr; ! Attribute attr2; ElementState currentElement = fElementStack.peek(); removeDuplicateDecls(); for(int i=0 ; i< fAttributeCache.size();i++){ ! attr = fAttributeCache.get(i); if((attr.prefix != null && !attr.prefix.equals("")) || (attr.uri != null && !attr.uri.equals(""))) { correctPrefix(currentElement,attr); } }
*** 1752,1776 **** } } } for(int i=0 ; i< fAttributeCache.size();i++){ ! attr = (Attribute)fAttributeCache.get(i); for(int j=i+1;j<fAttributeCache.size();j++){ ! attr2 = (Attribute)fAttributeCache.get(j); if(!"".equals(attr.prefix)&& !"".equals(attr2.prefix)){ correctPrefix(attr,attr2); } } } repairNamespaceDecl(currentElement); ! int i = 0; for (i = 0; i < fAttributeCache.size(); i++) { ! attr = (Attribute) fAttributeCache.get(i); /* If 'attr' is an attribute and it is in no namespace(which means that prefix="", uri=""), attr's namespace should not be redinded. See [http://www.w3.org/TR/REC-xml-names/#defaulting]. */ if (attr.prefix != null && attr.prefix.equals("") && attr.uri != null && attr.uri.equals("")){ repairNamespaceDecl(attr); --- 1780,1804 ---- } } } for(int i=0 ; i< fAttributeCache.size();i++){ ! attr = fAttributeCache.get(i); for(int j=i+1;j<fAttributeCache.size();j++){ ! attr2 = fAttributeCache.get(j); if(!"".equals(attr.prefix)&& !"".equals(attr2.prefix)){ correctPrefix(attr,attr2); } } } repairNamespaceDecl(currentElement); ! int i; for (i = 0; i < fAttributeCache.size(); i++) { ! attr = fAttributeCache.get(i); /* If 'attr' is an attribute and it is in no namespace(which means that prefix="", uri=""), attr's namespace should not be redinded. See [http://www.w3.org/TR/REC-xml-names/#defaulting]. */ if (attr.prefix != null && attr.prefix.equals("") && attr.uri != null && attr.uri.equals("")){ repairNamespaceDecl(attr);
*** 1778,1796 **** } QName qname = null; for (i = 0; i < fNamespaceDecls.size(); i++) { ! qname = (QName) fNamespaceDecls.get(i); if (qname != null) { fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri); } } for (i = 0; i < fAttributeCache.size(); i++) { ! attr = (Attribute) fAttributeCache.get(i); correctPrefix(attr, XMLStreamConstants.ATTRIBUTE); } } /* --- 1806,1824 ---- } QName qname = null; for (i = 0; i < fNamespaceDecls.size(); i++) { ! qname = fNamespaceDecls.get(i); if (qname != null) { fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri); } } for (i = 0; i < fAttributeCache.size(); i++) { ! attr = fAttributeCache.get(i); correctPrefix(attr, XMLStreamConstants.ATTRIBUTE); } } /*
*** 1799,1811 **** *the element or the first occurring attribute retains the original prefix *and the following attributes have their prefixes replaced with a new prefix *that is bound to the namespace URIs of those attributes. */ void correctPrefix(QName attr1, QName attr2) { ! String tmpPrefix = null; ! QName decl = null; ! boolean done = false; checkForNull(attr1); checkForNull(attr2); if(attr1.prefix.equals(attr2.prefix) && !(attr1.uri.equals(attr2.uri))){ --- 1827,1838 ---- *the element or the first occurring attribute retains the original prefix *and the following attributes have their prefixes replaced with a new prefix *that is bound to the namespace URIs of those attributes. */ void correctPrefix(QName attr1, QName attr2) { ! String tmpPrefix; ! QName decl; checkForNull(attr1); checkForNull(attr2); if(attr1.prefix.equals(attr2.prefix) && !(attr1.uri.equals(attr2.uri))){
*** 1813,1834 **** tmpPrefix = fNamespaceContext.getPrefix(attr2.uri); if (tmpPrefix != null) { attr2.prefix = fSymbolTable.addSymbol(tmpPrefix); } else { ! decl = null; ! for(int n=0;n<fNamespaceDecls.size();n++){ ! decl = (QName)fNamespaceDecls.get(n); ! if(decl != null && (decl.uri == attr2.uri)){ attr2.prefix = decl.prefix; return; } } //No namespace mapping found , so declare prefix. ! StringBuffer genPrefix = new StringBuffer("zdef"); for (int k = 0; k < 1; k++) { genPrefix.append(fPrefixGen.nextInt()); } --- 1840,1860 ---- tmpPrefix = fNamespaceContext.getPrefix(attr2.uri); if (tmpPrefix != null) { attr2.prefix = fSymbolTable.addSymbol(tmpPrefix); } else { ! for (int n=0; n<fNamespaceDecls.size(); n++) { ! decl = fNamespaceDecls.get(n); ! if(decl != null && (decl.uri.equals(attr2.uri))){ attr2.prefix = decl.prefix; return; } } //No namespace mapping found , so declare prefix. ! StringBuilder genPrefix = new StringBuilder("zdef"); for (int k = 0; k < 1; k++) { genPrefix.append(fPrefixGen.nextInt()); }
*** 1849,1863 **** if (attr.uri == null) attr.uri = XMLConstants.DEFAULT_NS_PREFIX; } void removeDuplicateDecls(){ QName decl1,decl2; ! for(int i =0;i<fNamespaceDecls.size();i++){ ! decl1 = (QName)fNamespaceDecls.get(i); if(decl1!=null) { for(int j=i+1;j<fNamespaceDecls.size();j++){ ! decl2 = (QName)fNamespaceDecls.get(j); // QName.equals relies on identity equality, so we can't use it, // because prefixes aren't interned if(decl2!=null && decl1.prefix.equals(decl2.prefix) && decl1.uri.equals(decl2.uri)) fNamespaceDecls.remove(j); } --- 1875,1889 ---- if (attr.uri == null) attr.uri = XMLConstants.DEFAULT_NS_PREFIX; } void removeDuplicateDecls(){ QName decl1,decl2; ! for(int i =0; i<fNamespaceDecls.size(); i++) { ! decl1 = fNamespaceDecls.get(i); if(decl1!=null) { for(int j=i+1;j<fNamespaceDecls.size();j++){ ! decl2 = fNamespaceDecls.get(j); // QName.equals relies on identity equality, so we can't use it, // because prefixes aren't interned if(decl2!=null && decl1.prefix.equals(decl2.prefix) && decl1.uri.equals(decl2.uri)) fNamespaceDecls.remove(j); }
*** 1871,1886 **** *is either removed if the correct mapping is inherited from the parent context of that element, *or changed to the namespace URI of the element or attribute using that prefix. * */ void repairNamespaceDecl(QName attr) { ! QName decl = null; String tmpURI; //check for null prefix. for (int j = 0; j < fNamespaceDecls.size(); j++) { ! decl = (QName) fNamespaceDecls.get(j); if (decl != null) { if ((attr.prefix != null) && (attr.prefix.equals(decl.prefix) && !(attr.uri.equals(decl.uri)))) { --- 1897,1912 ---- *is either removed if the correct mapping is inherited from the parent context of that element, *or changed to the namespace URI of the element or attribute using that prefix. * */ void repairNamespaceDecl(QName attr) { ! QName decl; String tmpURI; //check for null prefix. for (int j = 0; j < fNamespaceDecls.size(); j++) { ! decl = fNamespaceDecls.get(j); if (decl != null) { if ((attr.prefix != null) && (attr.prefix.equals(decl.prefix) && !(attr.uri.equals(decl.uri)))) {
*** 1898,1914 **** } } } boolean isDeclared(QName attr) { ! QName decl = null; for (int n = 0; n < fNamespaceDecls.size(); n++) { ! decl = (QName) fNamespaceDecls.get(n); if ((attr.prefix != null) && ! ((attr.prefix == decl.prefix) && (decl.uri == attr.uri))) { return true; } } if (attr.uri != null) { --- 1924,1940 ---- } } } boolean isDeclared(QName attr) { ! QName decl; for (int n = 0; n < fNamespaceDecls.size(); n++) { ! decl = fNamespaceDecls.get(n); if ((attr.prefix != null) && ! ((attr.prefix.equals(decl.prefix)) && (decl.uri.equals(attr.uri)))) { return true; } } if (attr.uri != null) {
*** 2119,2131 **** } return null; } ! public java.util.Iterator getPrefixes(String uri) { Vector prefixes = null; ! Iterator itr = null; if (uri != null) { uri = fSymbolTable.addSymbol(uri); } --- 2145,2158 ---- } return null; } ! //Cleanup note: leaving these warnings to a xerces.internal.util cleanup ! public Iterator<String> getPrefixes(String uri) { Vector prefixes = null; ! Iterator<String> itr = null; if (uri != null) { uri = fSymbolTable.addSymbol(uri); }
*** 2138,2219 **** } if ((prefixes == null) && (itr != null)) { return itr; } else if ((prefixes != null) && (itr == null)) { ! return new ReadOnlyIterator(prefixes.iterator()); } else if ((prefixes != null) && (itr != null)) { String ob = null; while (itr.hasNext()) { ! ob = (String) itr.next(); if (ob != null) { ob = fSymbolTable.addSymbol(ob); } if (!prefixes.contains(ob)) { prefixes.add(ob); } } ! return new ReadOnlyIterator(prefixes.iterator()); } return fReadOnlyIterator; } } // -- Map Interface -------------------------------------------------- public int size() { return 1; } public boolean isEmpty() { return false; } public boolean containsKey(Object key) { return key.equals(OUTPUTSTREAM_PROPERTY); } /** * Returns the value associated to an implementation-specific * property. */ public Object get(Object key) { if (key.equals(OUTPUTSTREAM_PROPERTY)) { return fOutputStream; } return null; } ! public java.util.Set entrySet() { throw new UnsupportedOperationException(); } /** * Overrides the method defined in AbstractMap which is * not completely implemented. Calling toString() in * AbstractMap would cause an unsupported exection to * be thrown. */ public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); } /** * Overrides the method defined in AbstractMap * This is required by the toString() method */ public int hashCode() { return fElementStack.hashCode(); } /** * Overrides the method defined in AbstractMap * This is required to satisfy the contract for hashCode. */ public boolean equals(Object obj) { return (this == obj); } } --- 2165,2254 ---- } if ((prefixes == null) && (itr != null)) { return itr; } else if ((prefixes != null) && (itr == null)) { ! return new ReadOnlyIterator<>(prefixes.iterator()); } else if ((prefixes != null) && (itr != null)) { String ob = null; while (itr.hasNext()) { ! ob = itr.next(); if (ob != null) { ob = fSymbolTable.addSymbol(ob); } if (!prefixes.contains(ob)) { prefixes.add(ob); } } ! return new ReadOnlyIterator<>(prefixes.iterator()); } return fReadOnlyIterator; } } // -- Map Interface -------------------------------------------------- + @Override public int size() { return 1; } + @Override public boolean isEmpty() { return false; } + @Override public boolean containsKey(Object key) { return key.equals(OUTPUTSTREAM_PROPERTY); } /** * Returns the value associated to an implementation-specific * property. */ + @Override public Object get(Object key) { if (key.equals(OUTPUTSTREAM_PROPERTY)) { return fOutputStream; } return null; } ! @Override ! public Set<Entry<Object,Object>> entrySet() { throw new UnsupportedOperationException(); } /** * Overrides the method defined in AbstractMap which is * not completely implemented. Calling toString() in * AbstractMap would cause an unsupported exection to * be thrown. */ + @Override public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); } /** * Overrides the method defined in AbstractMap * This is required by the toString() method */ + @Override public int hashCode() { return fElementStack.hashCode(); } /** * Overrides the method defined in AbstractMap * This is required to satisfy the contract for hashCode. */ + @Override public boolean equals(Object obj) { return (this == obj); } }
< prev index next >