home *** CD-ROM | disk | FTP | other *** search
Wrap
package com.ms.xml.util; import com.ms.xml.parser.DTD; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; public class XMLOutputStream extends OutputStream { static final int OUTPUTSW = 1; static final int UCS2 = 2; static final int UCS2_BOM = 3; static final int ASCII = 4; public static int DEFAULT = 0; public static int PRETTY = 1; public static int COMPACT = 2; private OutputStream out; private OutputStreamWriter outsw; String newline; boolean littleendian; String encoding; private int writeState; int outputStyle; boolean jdk11; public boolean mixed; private int indent; public DTD dtd; public NameSpaceContext nameSpaceContext = new NameSpaceContext(); public boolean savingDTD; public void close() throws IOException { if (this.outsw != null) { this.outsw.close(); } else { this.out.close(); } } public void setEncoding(String var1, boolean var2, boolean var3) throws IOException { this.outsw = null; String var4 = var1; if (var1.equalsIgnoreCase("UTF-8")) { var4 = "UTF8"; } else if (var1.equalsIgnoreCase("Shift_JIS")) { var4 = "SJIS"; } else if (var1.equalsIgnoreCase("ISO-8859-1")) { var4 = "8859_1"; } else { if (var1.equalsIgnoreCase("ISO-10646-UCS-4") || var1.equalsIgnoreCase("UCS-4")) { throw new IOException("UCS-4 not yet supported"); } if (var1.equalsIgnoreCase("UCS-2")) { if (var3) { this.writeState = 3; } else { this.writeState = 2; } this.encoding = "UCS-2"; if (var2) { this.littleendian = true; this.out = new ByteSwapOutputStream(this.out); } return; } this.writeState = 4; this.encoding = "ASCII"; } if (var1.equalsIgnoreCase("ASCII")) { this.outsw = null; } else { try { if (!this.jdk11) { throw new IOException("Writers not supported in JDK 1.0"); } else { this.outsw = new OutputStreamWriter(this.out, var4); this.writeState = 1; this.encoding = var1; } } catch (IOException var5) { throw new IOException(var4 + " is not supported by your Java Virtual Machine." + " Try installing the latest VM from http://www.microsoft.com/java/download.htm"); } } } public XMLOutputStream(OutputStream var1) { String var2 = System.getProperty("java.version"); this.jdk11 = var2.equals("1.1"); this.outputStyle = DEFAULT; this.littleendian = false; this.savingDTD = false; this.mixed = false; this.out = var1; this.newline = System.getProperty("line.separator"); this.indent = 0; try { if (!this.jdk11) { throw new IOException("Writers not supported in JDK 1.0"); } else { this.outsw = new OutputStreamWriter(var1, "UTF8"); this.writeState = 1; this.encoding = "UTF-8"; } } catch (IOException var3) { this.outsw = null; this.writeState = 4; this.encoding = "ASCII"; } } public void addIndent(int var1) { this.indent += var1; } public void writeIndent() throws IOException { if (this.outputStyle == PRETTY && !this.mixed) { for(int var1 = 0; var1 < this.indent; ++var1) { this.write(9); } } } public void writeQualifiedName(Name var1, Atom var2) throws IOException { Atom var3 = var1.getNameSpace(); Atom var4 = var3; if (var3 == var2) { this.writeChars(var1.getName()); } else if (var3 != null) { if (this.dtd != null && !DTD.isReservedNameSpace(var3)) { var4 = this.nameSpaceContext.findNameSpace(var3); if (var4 == null) { var4 = this.dtd.findShortNameSpace(var3); } if (var4 == null) { var4 = var3; } } this.writeChars(var4.toString() + ":" + var1.getName()); } else if (var2 == null) { this.writeChars(var1.getName()); } else { this.writeChars(":" + var1.getName()); } } public void setOutputStyle(int var1) { this.outputStyle = var1; } public int getOutputStyle() { return this.outputStyle; } public void write(int var1) throws IOException { switch (this.writeState) { case 1: this.outsw.write(var1); return; case 2: int var4 = var1 >> 8; int var5 = var1 & 255; this.out.write(var4); this.out.write(var5); return; case 3: this.writeState = 2; this.out.write(254); this.out.write(255); int var2 = var1 >> 8; int var3 = var1 & 255; this.out.write(var2); this.out.write(var3); return; case 4: default: this.out.write(var1); } } public void writeChars(String var1) throws IOException { int var2 = var1.length(); for(int var3 = 0; var3 < var2; ++var3) { char var4 = var1.charAt(var3); if (var4 == '\n') { int var5 = this.newline.length(); for(int var6 = 0; var6 < var5; ++var6) { this.write(this.newline.charAt(var6)); } } else { this.write(var4); } } } public void flush() throws IOException { if (this.outsw != null) { this.outsw.flush(); } else { this.out.flush(); } } public void writeNewLine() throws IOException { if (this.outputStyle == PRETTY && !this.mixed) { int var1 = this.newline.length(); for(int var2 = 0; var2 < var1; ++var2) { this.write(this.newline.charAt(var2)); } } } public void writeQuotedString(String var1) throws IOException { byte var2 = 34; if (var1.indexOf(34) >= 0 && var1.indexOf(39) < 0) { var2 = 39; } this.write(var2); int var3 = var1.length(); for(int var4 = 0; var4 < var3; ++var4) { char var5 = var1.charAt(var4); if (var5 == var2) { if (var2 == 34) { this.writeChars("""); } else { this.writeChars("'"); } } else { this.write(var5); } } this.write(var2); } }