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

📄 simplexmlrpcclient.java

📁 xmlrpc-2.0-src.zip java程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                values.pop();                if (depth < 2)                {                    // This is a top-level object                    objectParsed(v.value);                    currentValue = null;                }                else                {                    // add object to sub-array; if current container is a struct, add later (at </member>)                    currentValue = (Value) values.peek();                    currentValue.endElement(v);                }            }        }        // Handle objects contained in structs.        if ("member".equals(name))        {            Value v = currentValue;            values.pop();            currentValue = (Value) values.peek();            currentValue.endElement(v);        }        else if ("methodName".equals(name))        {            methodName = cdata.toString();            cdata.setLength(0);            readCdata = false;        }    }    /**     * Method called by SAX driver.     */    public void startElement (String name, AttributeList atts)            throws SAXException    {        if (debug)        {            System.err.println("startElement: " + name);        }        if ("value".equals(name))        {            // System.err.println ("starting value");            Value v = new Value();            values.push(v);            currentValue = v;            // cdata object is reused            cdata.setLength(0);            readCdata = true;        }        else if ("methodName".equals(name))        {            cdata.setLength(0);            readCdata = true;        }        else if ("name".equals(name))        {            cdata.setLength(0);            readCdata = true;        }        else if ("string".equals(name))        {            // currentValue.setType (STRING);            cdata.setLength(0);            readCdata = true;        }        else if ("i4".equals(name) || "int".equals(name))        {            currentValue.setType(INTEGER);            cdata.setLength(0);            readCdata = true;        }        else if ("boolean".equals(name))        {            currentValue.setType(BOOLEAN);            cdata.setLength(0);            readCdata = true;        }        else if ("double".equals(name))        {            currentValue.setType(DOUBLE);            cdata.setLength(0);            readCdata = true;        }        else if ("dateTime.iso8601".equals(name))        {            currentValue.setType(DATE);            cdata.setLength(0);            readCdata = true;        }        else if ("base64".equals(name))        {            currentValue.setType(BASE64);            cdata.setLength(0);            readCdata = true;        }        else if ("struct".equals(name))        {            currentValue.setType(STRUCT);        }        else if ("array".equals(name))        {            currentValue.setType(ARRAY);        }    }    /**     *     * @param e     * @throws SAXException     */    public void error(SAXParseException e) throws SAXException    {        System.err.println("Error parsing XML: " + e);        // errorLevel = RECOVERABLE;        // errorMsg = e.toString ();    }    /**     *     * @param e     * @throws SAXException     */    public void fatalError(SAXParseException e) throws SAXException    {        System.err.println("Fatal error parsing XML: " + e);        // errorLevel = FATAL;        // errorMsg = e.toString ();    }    /**     * This represents an XML-RPC Value while the request is being parsed.     */    class Value    {        int type;        Object value;        // the name to use for the next member of struct values        String nextMemberName;        Hashtable struct;        Vector array;        /**         * Constructor.         */        public Value()        {            this.type = STRING;        }        /**         * Notification that a new child element has been parsed.         */        public void endElement(Value child)        {            if (type == ARRAY)            {                array.addElement(child.value);            }            else if (type == STRUCT)            {                struct.put(nextMemberName, child.value);            }        }        /**         * Set the type of this value. If it's a container, create the         * corresponding java container.         */        public void setType(int type)        {            // System.err.println ("setting type to "+types[type]);            this.type = type;            if (type == ARRAY)            {                value = array = new Vector();            }            if (type == STRUCT)            {                value = struct = new Hashtable();            }        }        /**         * Set the character data for the element and interpret it according to         * the element type         */        public void characterData (String cdata)        {            switch (type)            {                case INTEGER:                    value = new Integer(cdata.trim());                    break;                case BOOLEAN:                    value = new Boolean("1".equals(cdata.trim()));                    break;                case DOUBLE:                    value = new Double(cdata.trim());                    break;                case DATE:                    try                    {                        value = format.parse(cdata.trim());                    }                    catch (ParseException p)                    {                        // System.err.println ("Exception while parsing date: "+p);                        throw new RuntimeException(p.getMessage());                    }                    break;                case BASE64:                    try                    {                        value = base64.decode((Object) cdata.getBytes());                    }                    catch (DecoderException e) {                        /* FIXME: We should Probably throw an                         * Exception here.  Punting because this class                         * is slated for complete overhaul using the                         * core library.                         */                         value = cdata;                    }                    break;                case STRING:                    value = cdata;                    break;                case STRUCT:                    // this is the name to use for the next member of this struct                    nextMemberName = cdata;                    break;            }        }        /**         * This is a performance hack to get the type of a value without casting         * the Object. It breaks the contract of method hashCode, but it doesn't         * matter since Value objects are never used as keys in Hashtables.         */        public int hashCode ()        {            return type;        }        /**         *         * @return         */        public String toString ()        {            return (types[type] + " element " + value);        }    }    /**     * A quick and dirty XML writer.     * TODO: Replace with core package's XmlWriter class.     *     * @see <a     * href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=28982">Bugzilla     * bug 28982</a>     */    class XmlWriter    {        StringBuffer buf;        String enc;        /**         *         * @param buf         */        public XmlWriter(StringBuffer buf)        {            this.buf = buf;            buf.append("<?xml version=\"1.0\"?>");        }        /**         *         * @param elem         */        public void startElement(String elem)        {            buf.append("<");            buf.append(elem);            buf.append(">");        }        /**         *         * @param elem         */        public void endElement(String elem)        {            buf.append("</");            buf.append(elem);            buf.append(">");        }        /**         *         * @param elem         */        public void emptyElement(String elem)        {            buf.append("<");            buf.append(elem);            buf.append("/>");        }        /**         *         * @param text         */        public void chardata(String text)        {            int l = text.length();            for (int i = 0; i < l; i++)            {                char c = text.charAt(i);                switch (c)                {                    case '<' :                        buf.append("&lt;");                        break;                    case '>' :                        buf.append("&gt;");                        break;                    case '&' :                        buf.append("&amp;");                        break;                    default :                        buf.append(c);                }            }        }        /**         *         * @param text         */        public void write(byte[] text)        {            // ### This may cause encoding complications for            // ### multi-byte characters.  This should be properly            // ### fixed by implementing Bugzilla issue 28982.            for (int i = 0; i < text.length; i++)            {                buf.append((char) text[i]);            }        }        /**         *         * @param text         */        public void write(char[] text)        {            buf.append(text);        }        /**         *         * @param text         */        public void write(String text)        {            buf.append(text);        }        /**         *         * @return         */        public String toString()        {            return buf.toString();        }        /**         *         * @return         * @throws UnsupportedEncodingException         */        public byte[] getBytes() throws UnsupportedEncodingException        {            return buf.toString().getBytes();        }    }}

⌨️ 快捷键说明

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