143 lines
4.7 KiB
Java
143 lines
4.7 KiB
Java
package com.thoughtworks.xstream.io.xml;
|
|
|
|
import com.thoughtworks.xstream.io.StreamException;
|
|
import com.thoughtworks.xstream.io.naming.NameCoder;
|
|
import javax.xml.namespace.QName;
|
|
import javax.xml.stream.XMLStreamException;
|
|
import javax.xml.stream.XMLStreamWriter;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class StaxWriter extends AbstractXmlWriter {
|
|
private boolean namespaceRepairingMode;
|
|
private final XMLStreamWriter out;
|
|
private final QNameMap qnameMap;
|
|
private int tagDepth;
|
|
private final boolean writeEnclosingDocument;
|
|
|
|
public StaxWriter(QNameMap qNameMap, XMLStreamWriter xMLStreamWriter) throws XMLStreamException {
|
|
this(qNameMap, xMLStreamWriter, true, true);
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
|
public void addAttribute(String str, String str2) {
|
|
try {
|
|
this.out.writeAttribute(encodeAttribute(str), str2);
|
|
} catch (XMLStreamException e) {
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
|
public void close() {
|
|
try {
|
|
this.out.close();
|
|
} catch (XMLStreamException e) {
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
|
public void endNode() {
|
|
try {
|
|
this.tagDepth--;
|
|
this.out.writeEndElement();
|
|
if (this.tagDepth == 0 && this.writeEnclosingDocument) {
|
|
this.out.writeEndDocument();
|
|
}
|
|
} catch (XMLStreamException e) {
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
|
public void flush() {
|
|
try {
|
|
this.out.flush();
|
|
} catch (XMLStreamException e) {
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
}
|
|
|
|
protected QNameMap getQNameMap() {
|
|
return this.qnameMap;
|
|
}
|
|
|
|
protected XMLStreamWriter getXMLStreamWriter() {
|
|
return this.out;
|
|
}
|
|
|
|
public boolean isNamespaceRepairingMode() {
|
|
return this.namespaceRepairingMode;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
|
public void setValue(String str) {
|
|
try {
|
|
this.out.writeCharacters(str);
|
|
} catch (XMLStreamException e) {
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
|
public void startNode(String str) {
|
|
QName qName;
|
|
String prefix;
|
|
String namespaceURI;
|
|
boolean z;
|
|
boolean z2;
|
|
boolean z3;
|
|
try {
|
|
qName = this.qnameMap.getQName(encodeNode(str));
|
|
prefix = qName.getPrefix();
|
|
namespaceURI = qName.getNamespaceURI();
|
|
z = false;
|
|
z2 = prefix != null && prefix.length() > 0;
|
|
z3 = namespaceURI != null && namespaceURI.length() > 0;
|
|
} catch (XMLStreamException e) {
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
if (z3) {
|
|
z = z2 ? true : true;
|
|
throw new StreamException((Throwable) e);
|
|
}
|
|
this.out.writeStartElement(prefix, qName.getLocalPart(), namespaceURI);
|
|
if (z2) {
|
|
this.out.setPrefix(prefix, namespaceURI);
|
|
} else if (z3 && z) {
|
|
this.out.setDefaultNamespace(namespaceURI);
|
|
}
|
|
if (z3 && z && !isNamespaceRepairingMode()) {
|
|
if (z2) {
|
|
this.out.writeNamespace(prefix, namespaceURI);
|
|
} else {
|
|
this.out.writeDefaultNamespace(namespaceURI);
|
|
}
|
|
}
|
|
this.tagDepth++;
|
|
}
|
|
|
|
public StaxWriter(QNameMap qNameMap, XMLStreamWriter xMLStreamWriter, NameCoder nameCoder) throws XMLStreamException {
|
|
this(qNameMap, xMLStreamWriter, true, true, nameCoder);
|
|
}
|
|
|
|
public StaxWriter(QNameMap qNameMap, XMLStreamWriter xMLStreamWriter, boolean z, boolean z2, NameCoder nameCoder) throws XMLStreamException {
|
|
super(nameCoder);
|
|
this.qnameMap = qNameMap;
|
|
this.out = xMLStreamWriter;
|
|
this.writeEnclosingDocument = z;
|
|
this.namespaceRepairingMode = z2;
|
|
if (z) {
|
|
xMLStreamWriter.writeStartDocument();
|
|
}
|
|
}
|
|
|
|
public StaxWriter(QNameMap qNameMap, XMLStreamWriter xMLStreamWriter, boolean z, boolean z2) throws XMLStreamException {
|
|
this(qNameMap, xMLStreamWriter, z, z2, new XmlFriendlyNameCoder());
|
|
}
|
|
|
|
public StaxWriter(QNameMap qNameMap, XMLStreamWriter xMLStreamWriter, boolean z, boolean z2, XmlFriendlyReplacer xmlFriendlyReplacer) throws XMLStreamException {
|
|
this(qNameMap, xMLStreamWriter, z, z2, (NameCoder) xmlFriendlyReplacer);
|
|
}
|
|
}
|