📄 simplexmlparserdocumentimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SimpleXMLParserDocumentImpl.java
package org.gudy.azureus2.pluginsimpl.local.utils.xml.simpleparser;
import java.io.*;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gudy.azureus2.plugins.utils.xml.simpleparser.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.*;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.utils.xml.simpleparser:
// SimpleXMLParserDocumentNodeImpl
public class SimpleXMLParserDocumentImpl
implements SimpleXMLParserDocument
{
private static class MyErrorHandler
implements ErrorHandler
{
private String getParseExceptionInfo(SAXParseException spe)
{
String systemId = spe.getSystemId();
if (systemId == null)
systemId = "null";
String info = (new StringBuilder()).append("URI=").append(systemId).append(" Line=").append(spe.getLineNumber()).append(": ").append(spe.getMessage()).toString();
return info;
}
public void warning(SAXParseException saxparseexception)
throws SAXException
{
}
public void error(SAXParseException spe)
throws SAXException
{
String message = (new StringBuilder()).append("Error: ").append(getParseExceptionInfo(spe)).toString();
throw new SAXException(message);
}
public void fatalError(SAXParseException spe)
throws SAXException
{
String message = (new StringBuilder()).append("Fatal Error: ").append(getParseExceptionInfo(spe)).toString();
throw new SAXException(message, spe);
}
MyErrorHandler(PrintWriter out)
{
}
}
protected Document document;
protected SimpleXMLParserDocumentNodeImpl root_node;
public SimpleXMLParserDocumentImpl(File file)
throws SimpleXMLParserDocumentException
{
try
{
create(new FileInputStream(file));
}
catch (Throwable e)
{
throw new SimpleXMLParserDocumentException(e);
}
}
public SimpleXMLParserDocumentImpl(String data)
throws SimpleXMLParserDocumentException
{
try
{
create(new ByteArrayInputStream(data.getBytes("UTF8")));
}
catch (UnsupportedEncodingException e) { }
}
public SimpleXMLParserDocumentImpl(InputStream input_stream)
throws SimpleXMLParserDocumentException
{
create(input_stream);
}
protected void create(InputStream input_stream)
throws SimpleXMLParserDocumentException
{
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setCoalescing(true);
dbf.setExpandEntityReferences(true);
DocumentBuilder db = dbf.newDocumentBuilder();
OutputStreamWriter errorWriter = new OutputStreamWriter(System.err);
MyErrorHandler error_handler = new MyErrorHandler(new PrintWriter(errorWriter, true));
db.setErrorHandler(error_handler);
document = db.parse(input_stream);
SimpleXMLParserDocumentNodeImpl root_nodes[] = parseNode(document, false);
int root_node_count = 0;
for (int i = 0; i < root_nodes.length; i++)
{
SimpleXMLParserDocumentNodeImpl node = root_nodes[i];
if (node.getNode().getNodeType() != 7)
{
root_node = node;
root_node_count++;
}
}
if (root_node_count != 1)
throw new SimpleXMLParserDocumentException((new StringBuilder()).append("invalid document - ").append(root_nodes.length).append(" root elements").toString());
}
catch (Throwable e)
{
throw new SimpleXMLParserDocumentException(e);
}
}
public String getName()
{
return root_node.getName();
}
public String getFullName()
{
return root_node.getFullName();
}
public String getNameSpaceURI()
{
return root_node.getNameSpaceURI();
}
public String getValue()
{
return root_node.getValue();
}
public SimpleXMLParserDocumentNode[] getChildren()
{
return root_node.getChildren();
}
public SimpleXMLParserDocumentNode getChild(String name)
{
return root_node.getChild(name);
}
public SimpleXMLParserDocumentAttribute[] getAttributes()
{
return root_node.getAttributes();
}
public SimpleXMLParserDocumentAttribute getAttribute(String name)
{
return root_node.getAttribute(name);
}
public void print()
{
PrintWriter pw = new PrintWriter(System.out);
print(pw);
pw.flush();
}
public void print(PrintWriter pw)
{
root_node.print(pw, "");
}
protected SimpleXMLParserDocumentNodeImpl[] parseNode(Node node, boolean skip_this_node)
{
int type = node.getNodeType();
if ((type == 1 || type == 7) && !skip_this_node)
return (new SimpleXMLParserDocumentNodeImpl[] {
new SimpleXMLParserDocumentNodeImpl(this, node)
});
Vector v = new Vector();
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
{
SimpleXMLParserDocumentNodeImpl kids[] = parseNode(child, false);
for (int i = 0; i < kids.length; i++)
v.addElement(kids[i]);
}
SimpleXMLParserDocumentNodeImpl res[] = new SimpleXMLParserDocumentNodeImpl[v.size()];
v.copyInto(res);
return res;
}
public static void main(String args[])
{
try
{
StringBuffer data = new StringBuffer(1024);
FileInputStream is = new FileInputStream("C:\\temp\\upnp_trace3.log");
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8"));
do
{
String line = lnr.readLine();
if (line == null)
break;
for (int i = 0; i < line.length(); i++)
{
char c = line.charAt(i);
if (c < ' ')
data.append(' ');
else
data.append(c);
}
data.append("\n");
} while (true);
String data_str = data.toString();
(new SimpleXMLParserDocumentImpl(data_str)).print();
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -