影视仓 v5.0.24版本的 MD5 值为:620341689ccdc375a3b86527e140060e
以下内容为反编译后的 Dom4JDriver.java 源代码,内容仅作参考
package com.thoughtworks.xstream.io.xml;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.naming.NameCoder;
import java.io.File;
import java.io.FilterWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.nio.charset.Charset;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.xml.sax.SAXException;
public class Dom4JDriver extends AbstractXmlDriver {
private DocumentFactory documentFactory;
private OutputFormat outputFormat;
public Dom4JDriver() {
this(new XmlFriendlyNameCoder());
}
@Override
public HierarchicalStreamReader createReader(Reader reader) {
try {
return new Dom4JReader(createReader().read(reader), getNameCoder());
} catch (DocumentException e) {
throw new StreamException((Throwable) e);
}
}
@Override
public HierarchicalStreamWriter createWriter(Writer writer) {
Dom4JXmlWriter dom4JXmlWriter = new Dom4JXmlWriter(new XMLWriter(new FilterWriter(writer) {
@Override
public void close() {
r3[0].close();
}
}, this.outputFormat), getNameCoder());
final HierarchicalStreamWriter[] hierarchicalStreamWriterArr = {dom4JXmlWriter};
return dom4JXmlWriter;
}
public DocumentFactory getDocumentFactory() {
return this.documentFactory;
}
public OutputFormat getOutputFormat() {
return this.outputFormat;
}
public void setDocumentFactory(DocumentFactory documentFactory) {
this.documentFactory = documentFactory;
}
public void setOutputFormat(OutputFormat outputFormat) {
this.outputFormat = outputFormat;
}
public Dom4JDriver(NameCoder nameCoder) {
this(new DocumentFactory(), OutputFormat.createPrettyPrint(), nameCoder);
this.outputFormat.setTrimText(false);
}
@Override
public HierarchicalStreamWriter createWriter(OutputStream outputStream) {
Charset charset = null;
String encoding = getOutputFormat() != null ? getOutputFormat().getEncoding() : null;
if (encoding != null && Charset.isSupported(encoding)) {
charset = Charset.forName(encoding);
}
return createWriter(charset != null ? new OutputStreamWriter(outputStream, charset) : new OutputStreamWriter(outputStream));
}
public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat) {
this(documentFactory, outputFormat, new XmlFriendlyNameCoder());
}
@Override
public HierarchicalStreamReader createReader(InputStream inputStream) {
try {
return new Dom4JReader(createReader().read(inputStream), getNameCoder());
} catch (DocumentException e) {
throw new StreamException((Throwable) e);
}
}
public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat, NameCoder nameCoder) {
super(nameCoder);
this.documentFactory = documentFactory;
this.outputFormat = outputFormat;
}
@Override
public HierarchicalStreamReader createReader(URL url) {
try {
return new Dom4JReader(createReader().read(url), getNameCoder());
} catch (DocumentException e) {
throw new StreamException((Throwable) e);
}
}
public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat, XmlFriendlyReplacer xmlFriendlyReplacer) {
this(documentFactory, outputFormat, (NameCoder) xmlFriendlyReplacer);
}
@Override
public HierarchicalStreamReader createReader(File file) {
try {
return new Dom4JReader(createReader().read(file), getNameCoder());
} catch (DocumentException e) {
throw new StreamException((Throwable) e);
}
}
public SAXReader createReader() {
SAXReader sAXReader = new SAXReader();
try {
sAXReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return sAXReader;
} catch (SAXException e) {
throw new DocumentException("Cannot disable DOCTYPE processing", e);
}
}
}