⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlwriterbase.java

📁 SAP这个系统的一个转换器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    switch(c)
                    {
                    case 60: // '<'
                        System.arraycopy(LESSTHAN, 0, m_xmldoc, m_offset, LESSTHAN.length);
                        m_offset += LESSTHAN.length;
                        break;

                    case 62: // '>'
                        System.arraycopy(GREATERTHAN, 0, m_xmldoc, m_offset, GREATERTHAN.length);
                        m_offset += GREATERTHAN.length;
                        break;

                    case 38: // '&'
                        System.arraycopy(AMPERSAND, 0, m_xmldoc, m_offset, AMPERSAND.length);
                        m_offset += AMPERSAND.length;
                        break;

                    default:
                        m_xmldoc[m_offset++] = c;
                        break;
                    }
                }

            } else
            {
                System.arraycopy(value, offset, m_xmldoc, m_offset, length);
                m_offset += length;
            }
        } else
        {
            boolean must_escape = false;
            int end = offset + length;
            required_length = length;
            for(int i = offset; i < end && !must_escape; i++)
            {
                char c = value[i];
                if(c == '<' || c == '>' || c == '&')
                    must_escape = true;
            }

            if(must_escape)
            {
                end = (offset + length) - 2;
                for(int i = offset; i < end; i++)
                    if(value[i] == ']' && value[i + 1] == ']' && value[i + 2] == '>')
                        required_length += GREATERTHAN.length;

                ensureBufferCapacity(required_length + CDATASTART.length + CDATAEND.length);
                System.arraycopy(CDATASTART, 0, m_xmldoc, m_offset, CDATASTART.length);
                m_offset += CDATASTART.length;
                if(required_length > length)
                {
                    int i = offset;
                    for(end = (offset + length) - 2; i < end;)
                    {
                        char c = value[i];
                        if(c == ']' && value[i + 1] == ']' && value[i + 2] == '>')
                        {
                            m_xmldoc[m_offset++] = ']';
                            m_xmldoc[m_offset++] = ']';
                            System.arraycopy(GREATERTHAN, 0, m_xmldoc, m_offset, GREATERTHAN.length);
                            m_offset += GREATERTHAN.length;
                            i += 3;
                        } else
                        {
                            m_xmldoc[m_offset++] = c;
                            i++;
                        }
                    }

                    for(i = end; i < end + 2; i++)
                        m_xmldoc[m_offset++] = value[i];

                } else
                {
                    System.arraycopy(value, offset, m_xmldoc, m_offset, length);
                    m_offset += length;
                }
                System.arraycopy(CDATAEND, 0, m_xmldoc, m_offset, CDATAEND.length);
                m_offset += CDATAEND.length;
            } else
            {
                ensureBufferCapacity(required_length);
                System.arraycopy(value, offset, m_xmldoc, m_offset, length);
                m_offset += length;
            }
        }
        return this;
    }

    public final XMLWriterBase content(String value)
        throws IOException
    {
        if(value == null)
            return this;
        int length = value.length();
        if(length > m_buffer.length)
            m_buffer = new char[length];
        value.getChars(0, length, m_buffer, 0);
        return content(m_buffer, 0, length);
    }

    public final XMLWriterBase stag(String name)
        throws IOException
    {
        return name != null ? stag(name, null, m_with_end_of_line) : this;
    }

    public final XMLWriterBase stag(String name, String attributes[])
        throws IOException
    {
        return name != null ? stag(name, attributes, m_with_end_of_line) : this;
    }

    protected final XMLWriterBase stag(String name, String attributes[], boolean eol)
        throws IOException
    {
        int length;
        if(name == null || (length = name.length()) == 0)
            return this;
        int required_length = length + 2;
        if(eol)
            required_length++;
        if(attributes == null || attributes.length == 0)
        {
            ensureBufferCapacity(required_length);
            m_xmldoc[m_offset++] = '<';
            name.getChars(0, length, m_xmldoc, m_offset);
            m_offset += length;
            m_xmldoc[m_offset++] = '>';
        } else
        {
            for(int i = 0; i < attributes.length; i++)
                required_length += attributes[i].length() + 1;

            ensureBufferCapacity(required_length);
            m_xmldoc[m_offset++] = '<';
            name.getChars(0, length, m_xmldoc, m_offset);
            m_offset += length;
            for(int i = 0; i < attributes.length; i++)
            {
                length = attributes[i].length();
                m_xmldoc[m_offset++] = ' ';
                attributes[i].getChars(0, length, m_xmldoc, m_offset);
                m_offset += length;
            }

            m_xmldoc[m_offset++] = '>';
        }
        if(eol)
            m_xmldoc[m_offset++] = '\n';
        return this;
    }

    public final XMLWriterBase etag(String name)
        throws IOException
    {
        int length;
        if(name == null || (length = name.length()) == 0)
            return this;
        int required_length = length + 3;
        if(m_with_end_of_line)
            required_length++;
        ensureBufferCapacity(required_length);
        m_xmldoc[m_offset++] = '<';
        m_xmldoc[m_offset++] = '/';
        name.getChars(0, length, m_xmldoc, m_offset);
        m_offset += length;
        m_xmldoc[m_offset++] = '>';
        if(m_with_end_of_line)
            m_xmldoc[m_offset++] = '\n';
        return this;
    }

    public final XMLWriterBase empty(String name)
        throws IOException
    {
        return empty(name, null);
    }

    public final XMLWriterBase empty(String name, String attributes[])
        throws IOException
    {
        int length;
        if(name == null || (length = name.length()) == 0)
            return this;
        int required_length = length + 3;
        if(m_with_end_of_line)
            required_length++;
        if(attributes == null || attributes.length == 0)
        {
            ensureBufferCapacity(required_length);
            m_xmldoc[m_offset++] = '<';
            name.getChars(0, length, m_xmldoc, m_offset);
            m_offset += length;
            m_xmldoc[m_offset++] = '/';
            m_xmldoc[m_offset++] = '>';
        } else
        {
            for(int i = 0; i < attributes.length; i++)
                required_length += attributes[i].length() + 1;

            ensureBufferCapacity(required_length);
            m_xmldoc[m_offset++] = '<';
            name.getChars(0, length, m_xmldoc, m_offset);
            m_offset += length;
            for(int i = 0; i < attributes.length; i++)
            {
                length = attributes[i].length();
                m_xmldoc[m_offset++] = ' ';
                attributes[i].getChars(0, length, m_xmldoc, m_offset);
                m_offset += length;
            }

            m_xmldoc[m_offset++] = '/';
            m_xmldoc[m_offset++] = '>';
        }
        if(m_with_end_of_line)
            m_xmldoc[m_offset++] = '\n';
        return this;
    }

    public final XMLWriterBase prolog()
        throws IOException
    {
        String prolog = "<?xml version=\"1.0\" encoding=\"" + m_encoding + "\"?>";
        int length = prolog.length();
        ensureBufferCapacity(length + (m_with_end_of_line ? 1 : 0));
        prolog.getChars(0, length, m_xmldoc, m_offset);
        m_offset += length;
        if(m_with_end_of_line)
            m_xmldoc[m_offset++] = '\n';
        return this;
    }

    public final XMLWriterBase comment(String comment)
        throws IOException
    {
        int length = comment.length();
        ensureBufferCapacity(length + COMMENTSTART.length + COMMENTEND.length + (m_with_end_of_line ? 1 : 0));
        System.arraycopy(COMMENTSTART, 0, m_xmldoc, m_offset, COMMENTSTART.length);
        m_offset += COMMENTSTART.length;
        comment.getChars(0, length, m_xmldoc, m_offset);
        m_offset += length;
        System.arraycopy(COMMENTEND, 0, m_xmldoc, m_offset, COMMENTEND.length);
        m_offset += COMMENTEND.length;
        if(m_with_end_of_line)
            m_xmldoc[m_offset++] = '\n';
        return this;
    }

    public XMLWriterBase element(String name, String value)
        throws IOException
    {
        stag(name, null, false);
        content(value);
        return etag(name);
    }

    public XMLWriterBase element(String name, String attributes[], String value)
        throws IOException
    {
        stag(name, attributes, false);
        content(value);
        return etag(name);
    }

    public XMLWriterBase element(String name, byte value[])
        throws IOException
    {
        return element(name, null, value);
    }

    public XMLWriterBase element(String name, String attributes[], byte value[])
        throws IOException
    {
        stag(name, attributes, false);
        if(value != null)
            content(value, 0, value.length);
        return etag(name);
    }

    public static final String NAMESPACE_URN_SOAP_UC = "urn:sap-com:document:sap:soap:functions:uc-style";
    public static final String NAMESPACE_URN_SAP_RFC = "urn:sap-com:document:sap:rfc:functions";
    public static final byte ESCAPE_NONE = 0;
    public static final byte ESCAPE_DEFAULT = 1;
    public static final byte ESCAPE_IDOC46 = 2;
    public static final byte ESCAPE_IDOC610 = 3;
    protected static final int DOCUMENT_BUFFER_SIZE = 1024;
    private static final char hex[] = {
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
        'A', 'B', 'C', 'D', 'E', 'F'
    };
    private static final char LESSTHAN[] = {
        '&', '#', '6', '0', ';'
    };
    private static final char GREATERTHAN[] = {
        '&', '#', '6', '2', ';'
    };
    private static final char AMPERSAND[] = {
        '&', '#', '3', '8', ';'
    };
    private static final char CDATASTART[] = {
        '<', '!', '[', 'C', 'D', 'A', 'T', 'A', '['
    };
    private static final char CDATAEND[] = {
        ']', ']', '>'
    };
    private static final char COMMENTSTART[] = {
        '<', '!', '-', '-', ' '
    };
    private static final char COMMENTEND[] = {
        ' ', '-', '-', '>'
    };
    protected XMLWriterBase m_parent;
    private char m_xmldoc[];
    private int m_offset;
    private int m_length;
    private char m_buffer[];
    private Writer m_out;
    private String m_encoding;
    protected byte m_escape_mode;
    protected boolean m_trim_spaces;
    protected boolean m_with_end_of_line;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -