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 PRETTY; public static int COMPACT = 1; private OutputStream out; private OutputStreamWriter outsw; String newline; boolean littleendian; String encoding; private int writeState; int outputStyle; boolean jdk11; 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 void addIndent(int var1) { this.indent += var1; } public void writeIndent() throws IOException { if (this.outputStyle == PRETTY) { for(int var1 = 0; var1 < this.indent; ++var1) { this.write(9); } } } public XMLOutputStream(OutputStream var1) { String var2 = System.getProperty("java.version"); this.jdk11 = var2.equals("1.1"); this.outputStyle = PRETTY; this.littleendian = false; this.savingDTD = 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 writeQualifiedName(Name var1, Name var2) throws IOException { if (!(var1 instanceof QualifiedName)) { if (var2 == null) { this.writeChars(var1.toString()); } else { this.writeChars("::" + var1.toString()); } } else { QualifiedName var3 = (QualifiedName)var1; Name var4 = var3.getNameSpace(); Name var5 = var4; if (var4 != var2 && (var2 != null || var4 != this.dtd.getDocType())) { if (!DTD.isReservedNameSpace(var4)) { var5 = this.nameSpaceContext.findNameSpace(var4); if (var5 == null) { var5 = this.dtd.findShortNameSpace(var4); } } this.writeChars(var5.toString() + "::" + var3.getName().toString()); } else { this.writeChars(var3.getName().toString()); } } } 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) { this.write(var1.charAt(var3)); } } 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.writeChars(this.newline); } } public void writeQuotedString(String var1) throws IOException { byte var2 = 34; if (var1.indexOf(34) >= 0) { var2 = 39; } this.write(var2); this.writeChars(var1); this.write(var2); } }