xiaodi8 v1.0.0版本的 MD5 值为:6b857c57f508176c5ba1afb422bbb5a9
以下内容为反编译后的 SaxWriter.java 源代码,内容仅作参考
package com.thoughtworks.xstream.io.xml;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.naming.NameCoder;
import io.github.inflationx.calligraphy3.BuildConfig;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;
public final class SaxWriter extends AbstractXmlWriter implements XMLReader {
public static final String CONFIGURED_XSTREAM_PROPERTY = "http://com.thoughtworks.xstream/sax/property/configured-xstream";
public static final String SOURCE_OBJECT_LIST_PROPERTY = "http://com.thoughtworks.xstream/sax/property/source-object-list";
private final AttributesImpl attributeList;
private char[] buffer;
private ContentHandler contentHandler;
private int depth;
private DTDHandler dtdHandler;
private List elementStack;
private EntityResolver entityResolver;
private ErrorHandler errorHandler;
private Map features;
private final boolean includeEnclosingDocument;
private final Map properties;
private boolean startTagInProgress;
public SaxWriter(NameCoder nameCoder) {
this(true, nameCoder);
}
private void endDocument(boolean z) throws SAXException {
int i = this.depth;
if (i == 0 || (i == 1 && z)) {
this.contentHandler.endDocument();
this.depth = 0;
}
}
private void flushStartTag() throws SAXException {
if (this.startTagInProgress) {
String str = (String) this.elementStack.get(0);
this.contentHandler.startElement(BuildConfig.FLAVOR, str, str, this.attributeList);
this.attributeList.clear();
this.startTagInProgress = false;
}
}
private void startDocument(boolean z) throws SAXException {
if (this.depth == 0) {
this.contentHandler.startDocument();
if (z) {
this.depth++;
}
}
}
@Override
public void addAttribute(String str, String str2) {
if (this.startTagInProgress) {
String escapeXmlName = escapeXmlName(str);
this.attributeList.addAttribute(BuildConfig.FLAVOR, escapeXmlName, escapeXmlName, "CDATA", str2);
return;
}
throw new StreamException(new IllegalStateException("No startElement being processed"));
}
@Override
public void close() {
}
@Override
public void endNode() {
try {
flushStartTag();
String str = (String) this.elementStack.remove(0);
this.contentHandler.endElement(BuildConfig.FLAVOR, str, str);
int i = this.depth - 1;
this.depth = i;
if (i == 0 && this.includeEnclosingDocument) {
endDocument(false);
}
} catch (SAXException e2) {
throw new StreamException(e2);
}
}
@Override
public void flush() {
}
@Override
public ContentHandler getContentHandler() {
return this.contentHandler;
}
@Override
public DTDHandler getDTDHandler() {
return this.dtdHandler;
}
@Override
public EntityResolver getEntityResolver() {
return this.entityResolver;
}
@Override
public ErrorHandler getErrorHandler() {
return this.errorHandler;
}
@Override
public boolean getFeature(String str) throws SAXNotRecognizedException {
if (!str.equals("http://xml.org/sax/features/namespaces") && !str.equals("http://xml.org/sax/features/namespace-prefixes")) {
throw new SAXNotRecognizedException(str);
}
Boolean bool = (Boolean) this.features.get(str);
if (bool == null) {
bool = Boolean.FALSE;
}
return bool.booleanValue();
}
@Override
public Object getProperty(String str) throws SAXNotRecognizedException {
if (!str.equals(CONFIGURED_XSTREAM_PROPERTY) && !str.equals(SOURCE_OBJECT_LIST_PROPERTY)) {
throw new SAXNotRecognizedException(str);
}
return this.properties.get(str);
}
@Override
public void parse(String str) throws SAXException {
parse();
}
@Override
public void setContentHandler(ContentHandler contentHandler) {
Objects.requireNonNull(contentHandler, "handler");
this.contentHandler = contentHandler;
}
@Override
public void setDTDHandler(DTDHandler dTDHandler) {
Objects.requireNonNull(dTDHandler, "handler");
this.dtdHandler = dTDHandler;
}
@Override
public void setEntityResolver(EntityResolver entityResolver) {
Objects.requireNonNull(entityResolver, "resolver");
this.entityResolver = entityResolver;
}
@Override
public void setErrorHandler(ErrorHandler errorHandler) {
Objects.requireNonNull(errorHandler, "handler");
this.errorHandler = errorHandler;
}
@Override
public void setFeature(String str, boolean z) throws SAXNotRecognizedException {
if (!str.equals("http://xml.org/sax/features/namespaces") && !str.equals("http://xml.org/sax/features/namespace-prefixes")) {
throw new SAXNotRecognizedException(str);
}
this.features.put(str, z ? Boolean.TRUE : Boolean.FALSE);
}
@Override
public void setProperty(String str, Object obj) throws SAXNotRecognizedException, SAXNotSupportedException {
if (str.equals(CONFIGURED_XSTREAM_PROPERTY)) {
if (!(obj instanceof XStream)) {
throw new SAXNotSupportedException("Value for property \"http://com.thoughtworks.xstream/sax/property/configured-xstream\" must be a non-null XStream object");
}
} else if (str.equals(SOURCE_OBJECT_LIST_PROPERTY)) {
if (obj instanceof List) {
List list = (List) obj;
if (!list.isEmpty()) {
obj = Collections.unmodifiableList(new ArrayList(list));
} else {
throw new SAXNotSupportedException("Value for property \"http://com.thoughtworks.xstream/sax/property/source-object-list\" shall not be an empty list");
}
} else {
throw new SAXNotSupportedException("Value for property \"http://com.thoughtworks.xstream/sax/property/source-object-list\" must be a non-null List object");
}
} else {
throw new SAXNotRecognizedException(str);
}
this.properties.put(str, obj);
}
@Override
public void setValue(String str) {
try {
flushStartTag();
int length = str.length();
if (length > this.buffer.length) {
this.buffer = new char[length];
}
str.getChars(0, length, this.buffer, 0);
this.contentHandler.characters(this.buffer, 0, length);
} catch (SAXException e2) {
throw new StreamException(e2);
}
}
@Override
public void startNode(String str) {
try {
if (this.depth != 0) {
flushStartTag();
} else if (this.includeEnclosingDocument) {
startDocument(false);
}
this.elementStack.add(0, escapeXmlName(str));
this.startTagInProgress = true;
this.depth++;
} catch (SAXException e2) {
throw new StreamException(e2);
}
}
public SaxWriter(boolean z, NameCoder nameCoder) {
super(nameCoder);
this.entityResolver = null;
this.dtdHandler = null;
this.contentHandler = null;
this.errorHandler = null;
this.features = new HashMap();
this.properties = new HashMap();
this.depth = 0;
this.elementStack = new LinkedList();
this.buffer = new char[128];
this.startTagInProgress = false;
this.attributeList = new AttributesImpl();
this.includeEnclosingDocument = z;
}
@Override
public void parse(InputSource inputSource) throws SAXException {
parse();
}
private void parse() throws SAXException {
XStream xStream = (XStream) this.properties.get(CONFIGURED_XSTREAM_PROPERTY);
if (xStream == null) {
xStream = new XStream();
}
List list = (List) this.properties.get(SOURCE_OBJECT_LIST_PROPERTY);
if (list != null && !list.isEmpty()) {
try {
startDocument(true);
Iterator it = list.iterator();
while (it.hasNext()) {
xStream.marshal(it.next(), this);
}
endDocument(true);
return;
} catch (StreamException e2) {
if (e2.getCause() instanceof SAXException) {
throw ((SAXException) e2.getCause());
}
throw new SAXException(e2);
}
}
throw new SAXException("Missing or empty source object list. Setting property \"http://com.thoughtworks.xstream/sax/property/source-object-list\" is mandatory");
}
public SaxWriter(XmlFriendlyReplacer xmlFriendlyReplacer) {
this(true, xmlFriendlyReplacer);
}
public SaxWriter(boolean z, XmlFriendlyReplacer xmlFriendlyReplacer) {
this(z, (NameCoder) xmlFriendlyReplacer);
}
public SaxWriter(boolean z) {
this(z, new XmlFriendlyNameCoder());
}
public SaxWriter() {
this(true);
}
}