📄 xmlwriterbase.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: XMLWriterBase.java
package com.sap.mw.jco.util;
import com.sap.mw.jco.JCO;
import java.io.*;
// Referenced classes of package com.sap.mw.jco.util:
// Codecs
public class XMLWriterBase
{
public XMLWriterBase()
{
m_parent = null;
m_xmldoc = null;
m_offset = 0;
m_length = 0;
m_buffer = new char[0];
m_out = null;
m_encoding = "UTF-8";
m_escape_mode = 1;
m_trim_spaces = true;
m_with_end_of_line = false;
m_xmldoc = new char[1024];
}
public XMLWriterBase(OutputStream out, String encoding)
throws UnsupportedEncodingException
{
this(null, out, encoding);
}
public XMLWriterBase(XMLWriterBase parent, OutputStream out, String encoding)
throws UnsupportedEncodingException
{
this(parent, ((Writer) (new OutputStreamWriter(out, encoding == null ? "UTF-8" : encoding))));
if(m_encoding != null)
m_encoding = encoding;
}
public XMLWriterBase(XMLWriterBase parent, Writer out)
{
m_parent = null;
m_xmldoc = null;
m_offset = 0;
m_length = 0;
m_buffer = new char[0];
m_out = null;
m_encoding = "UTF-8";
m_escape_mode = 1;
m_trim_spaces = true;
m_with_end_of_line = false;
m_parent = parent;
if(m_parent == null)
{
m_buffer = new char[1024];
m_xmldoc = new char[1024];
m_offset = 0;
m_out = out;
} else
{
m_buffer = m_parent.m_buffer;
m_xmldoc = m_parent.m_xmldoc;
m_offset = m_parent.m_offset;
m_length = m_parent.m_length;
m_out = m_parent.m_out;
m_encoding = m_parent.m_encoding;
m_escape_mode = m_parent.m_escape_mode;
m_trim_spaces = m_parent.m_trim_spaces;
m_with_end_of_line = m_parent.m_with_end_of_line;
}
}
private final void propagateToParent()
{
for(XMLWriterBase parent = m_parent; parent != null; parent = parent.m_parent)
{
parent.m_xmldoc = m_xmldoc;
parent.m_offset = m_offset;
parent.m_length = m_length;
}
}
protected final void ensureBufferCapacity(int size)
throws IOException
{
if(m_offset + size >= m_xmldoc.length)
{
if(m_out != null && m_offset > 0)
flush();
if(m_offset + size >= m_xmldoc.length)
{
char old[] = m_xmldoc;
size += m_offset;
size = (size / 1024 + 1) * 2 * 1024;
m_xmldoc = new char[size];
System.arraycopy(old, 0, m_xmldoc, 0, m_offset);
}
propagateToParent();
}
}
public final String getEncoding()
{
return m_encoding;
}
public final byte getEscapeMode()
{
return m_escape_mode;
}
public final void setEscapeMode(byte escape_mode)
{
m_escape_mode = escape_mode;
}
public final boolean getTrimTrailingSpaces()
{
return m_trim_spaces;
}
public final void setTrimTrailingSpaces(boolean trim_spaces)
{
m_trim_spaces = trim_spaces;
}
public final boolean getEndOfLineMode()
{
return m_with_end_of_line;
}
public final void setEndOfLineMode(boolean with_end_of_line)
{
m_with_end_of_line = with_end_of_line;
}
public final int length()
{
return m_out != null ? m_length + m_offset : m_offset;
}
protected final char[] getBuffer()
{
return m_out != null ? null : m_xmldoc;
}
public final char[] toCharArray()
{
if(m_out != null)
{
return new char[0];
} else
{
char xmldoc[] = new char[m_offset];
System.arraycopy(m_xmldoc, 0, xmldoc, 0, m_offset);
return xmldoc;
}
}
public final String toString()
{
return m_out != null ? "" : new String(m_xmldoc, 0, m_offset);
}
public void reset()
{
if(JCO.getTraceLevel() > 9)
JCO.fireTrace(10, "[JAV-LAYER] XMLWriterBase.reset()");
m_xmldoc = new char[1024];
m_offset = 0;
m_length = 0;
propagateToParent();
}
public void flush()
throws IOException
{
if(m_out != null && m_offset > 0)
{
m_out.write(m_xmldoc, 0, m_offset);
m_out.flush();
m_length += m_offset;
m_offset = 0;
propagateToParent();
}
}
public void close()
throws IOException
{
if(m_parent == null)
{
flush();
} else
{
m_parent.m_buffer = m_buffer;
propagateToParent();
}
}
protected void finalize()
throws IOException
{
}
public String escape(String tag)
throws CharConversionException
{
if(m_escape_mode == 0)
return tag;
int ioffset = 0;
int length = tag.length();
if(length * 5 > m_buffer.length)
m_buffer = new char[length * 5];
if(m_escape_mode == 2)
{
for(int i = 0; i < length; i++)
{
char c = tag.charAt(i);
if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z')
m_buffer[ioffset++] = c;
else
if(i > 0 && (c >= '0' && c <= '9' || c == '_'))
m_buffer[ioffset++] = c;
else
if(c == '/')
m_buffer[ioffset++] = i != 0 ? '-' : '_';
else
throw new CharConversionException("Field name '" + tag + "' cannot be converted to an XML compliant element tag");
}
} else
{
for(int i = 0; i < length; i++)
{
char c = tag.charAt(i);
if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_')
m_buffer[ioffset++] = c;
else
if(i > 0 && (c >= '0' && c <= '9' || c == '.'))
m_buffer[ioffset++] = c;
else
if(c == '/')
{
m_buffer[ioffset++] = '_';
m_buffer[ioffset++] = '-';
} else
{
m_buffer[ioffset++] = '_';
m_buffer[ioffset++] = '-';
m_buffer[ioffset++] = '-';
m_buffer[ioffset++] = hex[c >> 4 & 0xf];
m_buffer[ioffset++] = hex[c >> 0 & 0xf];
}
}
}
return new String(m_buffer, 0, ioffset);
}
public final XMLWriterBase content(byte value[])
throws IOException
{
if(value == null)
return this;
else
return content(value, 0, value.length);
}
public final XMLWriterBase content(byte value[], int offset, int length)
throws IOException
{
if(value == null)
{
return this;
} else
{
char svalue[] = Codecs.Base64.encode(value, offset, length);
length = svalue.length;
ensureBufferCapacity(length);
System.arraycopy(svalue, 0, m_xmldoc, m_offset, length);
m_offset += length;
return this;
}
}
public final XMLWriterBase content(char value[], int offset, int length)
throws IOException
{
if(value == null)
return this;
if(m_trim_spaces && length > 0)
for(; length > 0 && value[(offset + length) - 1] == ' '; length--);
if(length <= 0)
return this;
int required_length = length;
if(m_escape_mode == 0)
{
ensureBufferCapacity(required_length);
System.arraycopy(value, offset, m_xmldoc, m_offset, length);
m_offset += length;
} else
if(m_escape_mode == 1 || m_escape_mode == 3)
{
int end = offset + length;
required_length = length;
for(int i = offset; i < end; i++)
{
char c = value[i];
if(c == '<' || c == '>' || c == '&')
required_length += 4;
}
ensureBufferCapacity(required_length);
if(required_length > length)
{
end = offset + length;
for(int i = offset; i < end; i++)
{
char c = value[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -