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

📄 kxmlserializer.java.svn-base

📁 利用J2ME编写的手机应用程序。 功能包括显示图片
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
            nspStack = hlp;        }                nspStack[pos++] = prefix;        nspStack[pos] = namespace;    }        public void setOutput(Writer writer) {        this.writer = writer;                // elementStack = new String[12]; //nsp/prefix/name        //nspCounts = new int[4];        //nspStack = new String[8]; //prefix/nsp        //indent = new boolean[4];                nspCounts[0] = 2;        nspCounts[1] = 2;        nspStack[0] = "";        nspStack[1] = "";        nspStack[2] = "xml";        nspStack[3] = "http://www.w3.org/XML/1998/namespace";        pending = false;        auto = 0;        depth = 0;                unicode = false;    }        public void setOutput(OutputStream os, String encoding)    throws IOException {        if (os == null)            throw new IllegalArgumentException();        setOutput(                encoding == null                ? new OutputStreamWriter(os)                : new OutputStreamWriter(os, encoding));        this.encoding = encoding;        if (encoding != null                && encoding.toLowerCase().startsWith("utf"))            unicode = true;    }        public void startDocument(            String encoding,            Boolean standalone)            throws IOException {        writer.write("<?xml version='1.0' ");                if (encoding != null) {            this.encoding = encoding;            if (encoding.toLowerCase().startsWith("utf"))                unicode = true;        }                if (this.encoding != null) {            writer.write("encoding='");            writer.write(this.encoding);            writer.write("' ");        }                if (standalone != null) {            writer.write("standalone='");            writer.write(                    standalone.booleanValue() ? "yes" : "no");            writer.write("' ");        }        writer.write("?>");    }        public XmlSerializer startTag(String namespace, String name)    throws IOException {        check(false);                //        if (namespace == null)        //            namespace = "";                if (indent[depth]) {            writer.write("\r\n");            for (int i = 0; i < depth; i++)                writer.write("  ");        }                int esp = depth * 3;                if (elementStack.length < esp + 3) {            String[] hlp = new String[elementStack.length + 12];            System.arraycopy(elementStack, 0, hlp, 0, esp);            elementStack = hlp;        }                String prefix =                namespace == null                ? ""                : getPrefix(namespace, true, true);                if ("".equals(namespace)) {            for (int i = nspCounts[depth];            i < nspCounts[depth + 1];            i++) {                if ("".equals(nspStack[i * 2]) && !"".equals(nspStack[i * 2 + 1])) {                    throw new IllegalStateException("Cannot set default namespace for elements in no namespace");                }            }        }                elementStack[esp++] = namespace;        elementStack[esp++] = prefix;        elementStack[esp] = name;                writer.write('<');        if (!"".equals(prefix)) {            writer.write(prefix);            writer.write(':');        }                writer.write(name);                pending = true;                return this;    }        public XmlSerializer attribute(            String namespace,            String name,            String value)            throws IOException {        if (!pending)            throw new IllegalStateException("illegal position for attribute");                //        int cnt = nspCounts[depth];                if (namespace == null)            namespace = "";                //		depth--;        //		pending = false;                String prefix =                "".equals(namespace)                ? ""                : getPrefix(namespace, false, true);                //		pending = true;        //		depth++;                /*        if (cnt != nspCounts[depth]) {                    writer.write(' ');                    writer.write("xmlns");                    if (nspStack[cnt * 2] != null) {                        writer.write(':');                        writer.write(nspStack[cnt * 2]);                    }                    writer.write("=\"");                    writeEscaped(nspStack[cnt * 2 + 1], '"');                    writer.write('"');                }         */                writer.write(' ');        if (!"".equals(prefix)) {            writer.write(prefix);            writer.write(':');        }        writer.write(name);        writer.write('=');        char q = value.indexOf('"') == -1 ? '"' : '\'';        writer.write(q);        writeEscaped(value, q);        writer.write(q);                return this;    }        public void flush() throws IOException {        check(false);        writer.flush();    }        public void close() throws IOException {        //check();        if(writer!=null) {            writer.close();        }    }        public XmlSerializer endTag(String namespace, String name)    throws IOException {                if (!pending)            depth--;        //        if (namespace == null)        //          namespace = "";                if ((namespace == null                && elementStack[depth * 3] != null)                || (namespace != null                && !namespace.equals(elementStack[depth * 3]))                || !elementStack[depth * 3 + 2].equals(name))            throw new IllegalArgumentException("</{"+namespace+"}"+name+"> does not match start");                if (pending) {            check(true);            depth--;        } else {            if (indent[depth + 1]) {                writer.write("\r\n");                for (int i = 0; i < depth; i++)                    writer.write("  ");            }                        writer.write("</");            String prefix = elementStack[depth * 3 + 1];            if (!"".equals(prefix)) {                writer.write(prefix);                writer.write(':');            }            writer.write(name);            writer.write('>');        }                nspCounts[depth + 1] = nspCounts[depth];        return this;    }        public String getNamespace() {        return getDepth() == 0 ? null : elementStack[getDepth() * 3 - 3];    }        public String getName() {        return getDepth() == 0 ? null : elementStack[getDepth() * 3 - 1];    }        public int getDepth() {        return pending ? depth + 1 : depth;    }        public XmlSerializer text(String text) throws IOException {        check(false);        indent[depth] = false;        writeEscaped(text, -1);        return this;    }        public XmlSerializer text(char[] text, int start, int len)    throws IOException {        text(new String(text, start, len));        return this;    }        public void cdsect(String data) throws IOException {        check(false);        writer.write("<![CDATA[");        writer.write(data);        writer.write("]]>");    }        public void comment(String comment) throws IOException {        check(false);        writer.write("<!--");        writer.write(comment);        writer.write("-->");    }        public void processingInstruction(String pi)    throws IOException {        check(false);        writer.write("<?");        writer.write(pi);        writer.write("?>");    }}

⌨️ 快捷键说明

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