home *** CD-ROM | disk | FTP | other *** search
- package com.sun.xml.tree;
-
- import com.sun.xml.parser.Parser;
- import com.sun.xml.parser.Resolver;
- import com.sun.xml.parser.ValidatingParser;
- import com.sun.xml.util.MessageCatalog;
- import com.sun.xml.util.XmlNames;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.Writer;
- import java.util.Locale;
- import org.w3c.dom.Attr;
- import org.w3c.dom.CDATASection;
- import org.w3c.dom.Comment;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.DOMImplementation;
- import org.w3c.dom.Document;
- import org.w3c.dom.DocumentFragment;
- import org.w3c.dom.DocumentType;
- import org.w3c.dom.Element;
- import org.w3c.dom.EntityReference;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.ProcessingInstruction;
- import org.w3c.dom.Text;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
-
- public class XmlDocument extends ParentNode implements DocumentEx, DOMImplementation {
- static String eol;
- static final MessageCatalog catalog;
- private Locale locale = Locale.getDefault();
- private String systemId;
- private ElementFactory factory;
- int mutationCount;
- boolean replaceRootElement;
- // $FF: synthetic field
- static Class class$com$sun$xml$tree$XmlDocument$Catalog;
-
- static {
- String var0;
- try {
- var0 = System.getProperty("line.separator", "\n");
- } catch (SecurityException var1) {
- var0 = "\n";
- }
-
- eol = var0;
- catalog = new Catalog();
- }
-
- public Node appendChild(Node var1) throws DOMException {
- if (var1 instanceof Element && this.getDocument() != null) {
- throw new DomEx((short)3);
- } else if (var1 instanceof DocumentType && this.getDoctype() != null) {
- throw new DomEx((short)3);
- } else {
- return super.appendChild(var1);
- }
- }
-
- public final void changeNodeOwner(Node var1) throws DOMException {
- if (var1.getOwnerDocument() != this) {
- if (!(var1 instanceof NodeBase)) {
- throw new DomEx((short)4);
- } else {
- switch (var1.getNodeType()) {
- case 6:
- case 9:
- case 10:
- case 12:
- throw new DomEx((short)3);
- case 7:
- case 8:
- case 11:
- default:
- if (var1 instanceof AttributeNode) {
- AttributeNode var4 = (AttributeNode)var1;
- ElementNode var5 = var4.getNameScope();
- if (var5 != null && ((NodeBase)var5).getOwnerDocument() != this) {
- throw new DomEx((short)3);
- }
- }
-
- NodeBase var3 = (NodeBase)var1.getParentNode();
- if (var3 != null) {
- var3.removeChild(var1);
- }
-
- TreeWalker var2 = new TreeWalker(var1);
- var3 = (NodeBase)var2.getCurrent();
-
- for(; var3 != null; var3 = (NodeBase)var2.getNext()) {
- var3.setOwnerDocument(this);
- if (var3 instanceof ElementNode) {
- NamedNodeMap var8 = var3.getAttributes();
- int var9 = var8.getLength();
-
- for(int var6 = 0; var6 < var9; ++var6) {
- this.changeNodeOwner(var8.item(var6));
- }
- }
- }
-
- }
- }
- }
- }
-
- void checkChildType(int var1) throws DOMException {
- switch (var1) {
- case 1:
- case 7:
- case 8:
- case 10:
- return;
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 9:
- default:
- throw new DomEx((short)3);
- }
- }
-
- public Locale chooseLocale(String[] var1) {
- Locale var2 = catalog.chooseLocale(var1);
- if (var2 != null) {
- this.setLocale(var2);
- }
-
- return var2;
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
-
- public Node cloneNode(boolean var1) {
- XmlDocument var2 = new XmlDocument();
- var2.systemId = this.systemId;
- Node var3;
- if (var1) {
- for(int var4 = 0; (var3 = ((ParentNode)this).item(var4)) != null; ++var4) {
- if (!(var3 instanceof DocumentType)) {
- var3 = var3.cloneNode(true);
- var2.changeNodeOwner(var3);
- var2.appendChild(var3);
- }
- }
- }
-
- return var2;
- }
-
- public Attr createAttribute(String var1) throws DOMException {
- if (!XmlNames.isName(var1)) {
- throw new DomEx((short)5);
- } else {
- AttributeNode var2 = new AttributeNode(var1, (String)null, true, (String)null);
- ((NodeBase)var2).setOwnerDocument(this);
- return var2;
- }
- }
-
- public CDATASection createCDATASection(String var1) {
- CDataNode var2 = new CDataNode();
- if (var1 != null) {
- ((DataNode)var2).setText(var1.toCharArray());
- }
-
- ((NodeBase)var2).setOwnerDocument(this);
- return var2;
- }
-
- public Comment createComment(String var1) {
- CommentNode var2 = new CommentNode(var1);
- ((NodeBase)var2).setOwnerDocument(this);
- return var2;
- }
-
- Doctype createDoctype(String var1) {
- Doctype var2 = new Doctype(var1);
- var2.setOwnerDocument(this);
- return var2;
- }
-
- public DocumentFragment createDocumentFragment() {
- DocFragNode var1 = new DocFragNode();
- ((NodeBase)var1).setOwnerDocument(this);
- return var1;
- }
-
- public final Element createElement(String var1) throws DOMException {
- return this.createElementEx(var1);
- }
-
- public final ElementEx createElementEx(String var1) throws DOMException {
- if (!XmlNames.isName(var1)) {
- throw new DomEx((short)5);
- } else {
- ElementNode var2;
- if (this.factory != null) {
- var2 = (ElementNode)this.factory.createElementEx(var1);
- } else {
- var2 = new ElementNode();
- }
-
- var2.setTag(var1);
- ((NodeBase)var2).setOwnerDocument(this);
- return var2;
- }
- }
-
- public final ElementEx createElementEx(String var1, String var2) throws DOMException {
- if (!XmlNames.isName(var2)) {
- throw new DomEx((short)5);
- } else {
- ElementNode var3;
- if (this.factory != null) {
- var3 = (ElementNode)this.factory.createElementEx(var1, var2);
- } else {
- var3 = new ElementNode();
- }
-
- var3.setTag(var2);
- ((NodeBase)var3).setOwnerDocument(this);
- return var3;
- }
- }
-
- public EntityReference createEntityReference(String var1) throws DOMException {
- if (!XmlNames.isName(var1)) {
- throw new DomEx((short)5);
- } else {
- EntityRefNode var2 = new EntityRefNode(var1);
- ((NodeBase)var2).setOwnerDocument(this);
- return var2;
- }
- }
-
- public ProcessingInstruction createProcessingInstruction(String var1, String var2) throws DOMException {
- if (!XmlNames.isName(var1)) {
- throw new DomEx((short)5);
- } else {
- PINode var3 = new PINode(var1, var2);
- ((NodeBase)var3).setOwnerDocument(this);
- return var3;
- }
- }
-
- public Text createTextNode(String var1) {
- TextNode var2 = new TextNode();
- ((NodeBase)var2).setOwnerDocument(this);
- if (var1 != null) {
- ((DataNode)var2).setText(var1.toCharArray());
- }
-
- return var2;
- }
-
- public XmlWriteContext createWriteContext(Writer var1) {
- return new ExtWriteContext(this, var1);
- }
-
- public XmlWriteContext createWriteContext(Writer var1, int var2) {
- return new ExtWriteContext(this, var1, var2);
- }
-
- public static XmlDocument createXmlDocument(InputStream var0, boolean var1) throws IOException, SAXException {
- return createXmlDocument(new InputSource(var0), var1);
- }
-
- public static XmlDocument createXmlDocument(String var0) throws IOException, SAXException {
- return createXmlDocument(new InputSource(var0), false);
- }
-
- public static XmlDocument createXmlDocument(String var0, boolean var1) throws IOException, SAXException {
- return createXmlDocument(new InputSource(var0), var1);
- }
-
- public static XmlDocument createXmlDocument(InputSource var0, boolean var1) throws IOException, SAXException {
- Object var2;
- XmlDocumentBuilder var3;
- try {
- if (var1) {
- var2 = new ValidatingParser(true);
- } else {
- var2 = new Parser();
- }
-
- ((Parser)var2).setEntityResolver(new Resolver());
- var3 = new XmlDocumentBuilder();
- var3.setDisableNamespaces(true);
- } catch (Exception var5) {
- throw new SAXException(var5);
- }
-
- var3.setParser((org.xml.sax.Parser)var2);
- ((Parser)var2).parse(var0);
- return var3.getDocument();
- }
-
- public final DocumentType getDoctype() {
- int var1 = 0;
-
- while(true) {
- Node var2 = ((ParentNode)this).item(var1);
- if (var2 == null) {
- return null;
- }
-
- if (var2 instanceof DocumentType) {
- return (DocumentType)var2;
- }
-
- ++var1;
- }
- }
-
- ElementNode getDocument() {
- int var1 = 0;
-
- while(true) {
- Node var2 = ((ParentNode)this).item(var1);
- if (var2 == null) {
- return null;
- }
-
- if (var2 instanceof ElementNode) {
- return (ElementNode)var2;
- }
-
- ++var1;
- }
- }
-
- public Element getDocumentElement() {
- return this.getDocument();
- }
-
- public ElementEx getElementExById(String var1) {
- if (var1 == null) {
- throw new IllegalArgumentException(((NodeBase)this).getMessage("XD-000"));
- } else {
- TreeWalker var2 = new TreeWalker(this);
-
- ElementEx var3;
- while((var3 = (ElementEx)var2.getNextElement((String)null)) != null) {
- String var4 = var3.getIdAttributeName();
- if (var4 != null) {
- String var5 = var3.getAttribute(var4);
- if (var5.equals(var1)) {
- return var3;
- }
- }
- }
-
- return null;
- }
- }
-
- public final ElementFactory getElementFactory() {
- return this.factory;
- }
-
- public DOMImplementation getImplementation() {
- return this;
- }
-
- public Locale getLocale() {
- return this.locale;
- }
-
- public final String getNodeName() {
- return "#document";
- }
-
- public final short getNodeType() {
- return 9;
- }
-
- public Document getOwnerDoc() {
- return null;
- }
-
- public final String getSystemId() {
- return this.systemId;
- }
-
- public boolean hasFeature(String var1, String var2) {
- if (!"XML".equalsIgnoreCase(var1)) {
- return false;
- } else {
- return var2 != null && "1.0".equals(var2);
- }
- }
-
- public Node insertBefore(Node var1, Node var2) throws DOMException {
- if (!this.replaceRootElement && var1 instanceof Element && this.getDocument() != null) {
- throw new DomEx((short)3);
- } else if (!this.replaceRootElement && var1 instanceof DocumentType && this.getDoctype() != null) {
- throw new DomEx((short)3);
- } else {
- return super.insertBefore(var1, var2);
- }
- }
-
- static String java2std(String var0) {
- if (var0 == null) {
- return null;
- } else if (var0.startsWith("ISO8859_")) {
- return "ISO-8859-" + var0.substring(8);
- } else if (var0.startsWith("8859_")) {
- return "ISO-8859-" + var0.substring(5);
- } else if (!"ASCII7".equalsIgnoreCase(var0) && !"ASCII".equalsIgnoreCase(var0)) {
- if ("UTF8".equalsIgnoreCase(var0)) {
- return "UTF-8";
- } else if (var0.startsWith("Unicode")) {
- return "UTF-16";
- } else if ("SJIS".equalsIgnoreCase(var0)) {
- return "Shift_JIS";
- } else if ("JIS".equalsIgnoreCase(var0)) {
- return "ISO-2022-JP";
- } else {
- return "EUCJIS".equalsIgnoreCase(var0) ? "EUC-JP" : var0;
- }
- } else {
- return "US-ASCII";
- }
- }
-
- TextNode newText(char[] var1, int var2, int var3) throws SAXException {
- TextNode var4 = (TextNode)this.createTextNode((String)null);
- char[] var5 = new char[var3];
- System.arraycopy(var1, var2, var5, 0, var3);
- ((DataNode)var4).setText(var5);
- return var4;
- }
-
- public Node replaceChild(Node var1, Node var2) throws DOMException {
- if (var1 instanceof DocumentFragment) {
- int var3 = 0;
- int var4 = 0;
- this.replaceRootElement = false;
- ParentNode var5 = (ParentNode)var1;
-
- Node var6;
- for(int var7 = 0; (var6 = var5.item(var7)) != null; ++var7) {
- if (var6 instanceof Element) {
- ++var3;
- } else if (var6 instanceof DocumentType) {
- ++var4;
- }
- }
-
- if (var3 > 1 || var4 > 1) {
- throw new DomEx((short)3);
- }
-
- this.replaceRootElement = true;
- }
-
- return super.replaceChild(var1, var2);
- }
-
- public DocumentType setDoctype(String var1, String var2, String var3) {
- Doctype var4 = (Doctype)this.getDoctype();
- if (var4 != null) {
- var4.setPrintInfo(var1, var2, var3);
- } else {
- var4 = new Doctype(var1, var2, var3);
- var4.setOwnerDocument(this);
- this.insertBefore(var4, ((ParentNode)this).getFirstChild());
- }
-
- return var4;
- }
-
- public final void setElementFactory(ElementFactory var1) {
- this.factory = var1;
- }
-
- public void setLocale(Locale var1) {
- if (var1 == null) {
- var1 = Locale.getDefault();
- }
-
- this.locale = var1;
- }
-
- public final void setSystemId(String var1) {
- this.systemId = var1;
- }
-
- public void write(OutputStream var1) throws IOException {
- OutputStreamWriter var2 = new OutputStreamWriter(var1, "UTF8");
- this.write(var2, "UTF-8");
- }
-
- public void write(Writer var1) throws IOException {
- String var2 = null;
- if (var1 instanceof OutputStreamWriter) {
- var2 = java2std(((OutputStreamWriter)var1).getEncoding());
- }
-
- this.write(var1, var2);
- }
-
- public void write(Writer var1, String var2) throws IOException {
- var1.write("<?xml version=\"1.0\"");
- if (var2 != null) {
- var1.write(" encoding=\"");
- var1.write(var2);
- var1.write(34);
- }
-
- var1.write("?>");
- var1.write(eol);
- var1.write(eol);
- this.writeChildrenXml(this.createWriteContext(var1, 0));
- var1.write(eol);
- var1.flush();
- }
-
- public void writeChildrenXml(XmlWriteContext var1) throws IOException {
- int var2 = ((ParentNode)this).getLength();
- Writer var3 = var1.getWriter();
- if (var2 != 0) {
- for(int var4 = 0; var4 < var2; ++var4) {
- ((NodeBase)((ParentNode)this).item(var4)).writeXml(var1);
- var3.write(eol);
- }
-
- }
- }
-
- public void writeXml(XmlWriteContext var1) throws IOException {
- Writer var2 = var1.getWriter();
- String var3 = null;
- if (var2 instanceof OutputStreamWriter) {
- var3 = java2std(((OutputStreamWriter)var2).getEncoding());
- }
-
- var2.write("<?xml version=\"1.0\"");
- if (var3 != null) {
- var2.write(" encoding=\"");
- var2.write(var3);
- var2.write(34);
- }
-
- var2.write("?>");
- var2.write(eol);
- var2.write(eol);
- this.writeChildrenXml(var1);
- }
- }
-