home *** CD-ROM | disk | FTP | other *** search
- package com.ms.xml.om;
-
- import com.ms.xml.parser.DTD;
- import com.ms.xml.parser.ElementDecl;
- import com.ms.xml.parser.ElementDeclEnumeration;
- import com.ms.xml.parser.Entity;
- import com.ms.xml.parser.ParseException;
- import com.ms.xml.parser.Parser;
- import com.ms.xml.util.Atom;
- import com.ms.xml.util.Name;
- import com.ms.xml.util.XMLOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.Enumeration;
-
- public class Document extends ElementImpl implements ElementFactory {
- URL URLdoc;
- Element DTDnode;
- Element root;
- Element XML;
- protected DTD dtd;
- String outputEncoding;
- boolean shortendtags;
- protected ElementFactory factory;
- Parser parser;
- int outputStyle;
- boolean caseInsensitive;
- boolean loadExternal;
- static Name nameVERSION = Name.create("version");
- static Name nameENCODING = Name.create("encoding");
- static Name nameStandalone = Name.create("standalone");
- static Name nameDOCTYPE = Name.create("DOCTYPE");
- static Name nameNAME = Name.create("NAME");
- static Name nameURL = Name.create("URL");
- static Name namePUBLICID = Name.create("PUBLICID");
- static Name nameXML = Name.create("xml");
- static String defaultEncoding = "UTF-8";
- static String defaultVersion = "1.0";
-
- public final String getId() {
- if (this.DTDnode == null) {
- return null;
- } else {
- Object var1 = this.DTDnode.getAttribute(namePUBLICID);
- return var1 != null ? var1.toString() : null;
- }
- }
-
- public final String getCharset() {
- return this.getEncoding();
- }
-
- public final void setCharset(String var1) {
- this.setEncoding(var1);
- }
-
- private final Element getXML() {
- return this.XML;
- }
-
- public void setShortEndTags(boolean var1) {
- this.shortendtags = var1;
- }
-
- public void setOutputStyle(int var1) {
- this.outputStyle = var1;
- }
-
- public int getOutputStyle() {
- return this.outputStyle;
- }
-
- public final String getDTDURL() {
- if (this.DTDnode == null) {
- return null;
- } else {
- Object var1 = this.DTDnode.getAttribute(nameURL);
- return var1 != null ? var1.toString() : null;
- }
- }
-
- public final String getVersion() {
- if (this.getXML() != null) {
- Object var1 = this.getXML().getAttribute(nameVERSION);
- if (var1 != null) {
- return var1.toString();
- }
- }
-
- return defaultVersion;
- }
-
- public final void setVersion(String var1) {
- if (this.XML == null) {
- this.XML = this.createElement(this, 5, nameXML, (String)null);
- }
-
- this.XML.setAttribute(nameVERSION, var1);
- }
-
- public void load(String var1) throws ParseException {
- URL var2;
- try {
- var2 = new URL(var1);
- } catch (MalformedURLException var4) {
- throw new ParseException("MalformedURLException: " + var4);
- }
-
- this.load(var2);
- }
-
- public void load(URL var1) throws ParseException {
- this.clear();
- this.URLdoc = var1;
- this.parser = new Parser();
- this.parser.setShortEndTags(this.shortendtags);
- this.parser.parse(var1, this, this.dtd, this, this.caseInsensitive, this.loadExternal);
- }
-
- public void load(InputStream var1) throws ParseException {
- this.clear();
- this.parser = new Parser();
- this.parser.setShortEndTags(this.shortendtags);
- this.parser.parse(var1, this, this.dtd, this, this.caseInsensitive, this.loadExternal);
- }
-
- public void reportError(ParseException var1, OutputStream var2) {
- if (this.parser != null) {
- this.parser.report(var1, var2);
- }
-
- }
-
- public XMLOutputStream createOutputStream(OutputStream var1) throws IOException {
- XMLOutputStream var2 = null;
- if (this.outputEncoding == null && this.parser != null) {
- var2 = this.parser.createOutputStream(var1);
- }
-
- if (var2 == null) {
- var2 = new XMLOutputStream(var1);
- String var3 = this.getEncoding();
- if (var3 != null) {
- var2.setEncoding(var3, true, true);
- }
- }
-
- var2.setOutputStyle(this.outputStyle);
- var2.dtd = this.getDTD();
- return var2;
- }
-
- public DTD getDTD() {
- return this.dtd;
- }
-
- public boolean isCaseInsensitive() {
- return this.caseInsensitive;
- }
-
- public void addChild(Element var1, Element var2) {
- if (var1.getType() == 0) {
- this.root = var1;
- } else if (var1.getType() == 5 && var1.getTagName() == nameXML) {
- this.XML = var1;
- } else if (var1.getType() == 4) {
- this.DTDnode = var1;
- }
-
- super.addChild(var1, var2);
- }
-
- public void save(XMLOutputStream var1) throws IOException {
- var1.dtd = this.dtd;
- ElementEnumeration var2 = new ElementEnumeration(this);
-
- while(var2.hasMoreElements()) {
- Element var3 = (Element)var2.nextElement();
- if (var3 == this.DTDnode) {
- var1.writeChars("<!DOCTYPE ");
- Name var8 = this.getDocType();
- if (var8.getNameSpace() != null) {
- var1.writeQualifiedName(this.getDocType(), Atom.create(""));
- } else {
- var1.writeChars(var8.getName());
- }
-
- if (this.getDTDURL() != null) {
- if (this.getId() != null) {
- var1.writeChars(" PUBLIC ");
- var1.writeQuotedString(this.getId());
- var1.write(32);
- } else {
- var1.writeChars(" SYSTEM ");
- }
-
- var1.writeQuotedString(this.getDTDURL());
- }
-
- if (var3.numElements() > 0) {
- var1.writeChars(" [");
- var1.writeNewLine();
- var1.addIndent(1);
- var1.savingDTD = true;
- ElementEnumeration var9 = new ElementEnumeration(var3);
-
- while(var9.hasMoreElements()) {
- Element var10 = (Element)var9.nextElement();
- var10.save(var1);
- }
-
- var1.savingDTD = false;
- var1.addIndent(-1);
- var1.write(93);
- }
-
- var1.write(62);
- var1.writeNewLine();
- } else if (var3 != this.XML) {
- var3.save(var1);
- } else {
- var1.writeChars("<?xml version=\"1.0\"");
- Name[] var4 = new Name[]{nameENCODING, nameStandalone};
-
- for(int var5 = 0; var5 < var4.length; ++var5) {
- Name var6 = var4[var5];
- Object var7 = var3.getAttribute(var6);
- if (var7 != null) {
- var1.writeChars(" " + var6 + "=");
- var1.writeQuotedString(var7.toString());
- }
- }
-
- var1.writeChars("?>");
- var1.writeNewLine();
- }
- }
-
- }
-
- public int getType() {
- return 3;
- }
-
- public Element getElementDecl(Name var1) {
- ElementDecl var2 = this.dtd.findElementDecl(var1);
- return var2 == null ? null : var2.toSchema();
- }
-
- public final String getStandalone() {
- if (this.getXML() != null) {
- Object var1 = this.getXML().getAttribute(nameStandalone);
- if (var1 != null) {
- return var1.toString();
- }
- }
-
- return null;
- }
-
- public final void setStandalone(String var1) {
- if (this.XML == null) {
- this.XML = this.createElement(this, 5, nameXML, (String)null);
- }
-
- this.XML.setAttribute(nameStandalone, var1);
- }
-
- public Element findEntity(Name var1) {
- Entity var2 = this.dtd.findEntity(var1);
- return var2 == null ? null : ((ElementImpl)var2).toSchema();
- }
-
- public final String getEncoding() {
- if (this.outputEncoding != null) {
- return this.outputEncoding;
- } else {
- if (this.getXML() != null) {
- Object var1 = this.getXML().getAttribute(nameENCODING);
- if (var1 != null) {
- return var1.toString();
- }
- }
-
- return defaultEncoding;
- }
- }
-
- public final Element createElement(Element var1, int var2, Name var3, String var4) {
- return this.factory.createElement(var1, var2, var3, var4);
- }
-
- public Document() {
- this.outputStyle = XMLOutputStream.DEFAULT;
- this.factory = new ElementFactoryImpl();
- this.dtd = new DTD();
- this.caseInsensitive = false;
- this.loadExternal = true;
- }
-
- public Document(ElementFactory var1) {
- this.outputStyle = XMLOutputStream.DEFAULT;
- this.factory = var1;
- this.dtd = new DTD();
- this.caseInsensitive = false;
- this.loadExternal = true;
- }
-
- public Element getParent() {
- return null;
- }
-
- public final void setEncoding(String var1) {
- this.outputEncoding = var1;
- if (this.XML == null) {
- this.XML = this.createElement(this, 5, nameXML, (String)null);
- this.XML.setAttribute(nameENCODING, var1);
- }
-
- }
-
- public long getFileModifiedDate() {
- if (this.URLdoc != null) {
- if (this.URLdoc.getProtocol().equals("file")) {
- File var3 = new File(this.URLdoc.getFile());
- return var3.lastModified();
- } else {
- try {
- URLConnection var1 = this.URLdoc.openConnection();
- var1.connect();
- return var1.getLastModified();
- } catch (IOException var2) {
- return 0L;
- }
- }
- } else {
- return 0L;
- }
- }
-
- public final Name getDocType() {
- if (this.DTDnode == null) {
- return null;
- } else {
- Object var1 = this.DTDnode.getAttribute(nameNAME);
- return var1 != null ? (Name)var1 : null;
- }
- }
-
- public void removeChild(Element var1) {
- super.removeChild(var1);
- if (this.root == var1) {
- this.root = null;
- } else if (this.XML == var1) {
- this.XML = null;
- } else {
- if (this.XML == this.DTDnode) {
- this.DTDnode = null;
- }
-
- }
- }
-
- public final Element createElement(int var1, String var2) {
- return this.factory.createElement((Element)null, var1, Name.create(var2), (String)null);
- }
-
- public final Element createElement(int var1) {
- return this.factory.createElement((Element)null, var1, (Name)null, (String)null);
- }
-
- public void setCaseInsensitive(boolean var1) {
- this.caseInsensitive = var1;
- }
-
- public final Element getRoot() {
- return this.root;
- }
-
- public void parsed(Element var1) {
- this.factory.parsed(var1);
- }
-
- public final String getURL() {
- return this.URLdoc.toString();
- }
-
- public void setURL(String var1) throws ParseException {
- this.load(var1);
- }
-
- public final Enumeration elementDeclarations() {
- return new ElementDeclEnumeration(this.dtd.elementDeclarations());
- }
-
- public void clear() {
- this.DTDnode = null;
- this.dtd = new DTD();
- this.root = null;
- this.XML = null;
- this.URLdoc = null;
- this.outputEncoding = null;
- super.clear();
- }
-
- public void parsedAttribute(Element var1, Name var2, Object var3) {
- this.factory.parsedAttribute(var1, var2, var3);
- }
-
- public void setLoadExternal(boolean var1) {
- this.loadExternal = var1;
- }
-
- public boolean loadExternal() {
- return this.loadExternal;
- }
-
- public boolean shortEndTags() {
- return this.shortendtags;
- }
-
- public String getText() {
- return this.root != null ? this.root.getText() : null;
- }
-
- public void setText(String var1) {
- if (this.root != null) {
- this.root.setText(var1);
- }
-
- }
- }
-