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

📄 xmlrpc.java

📁 xmlrpc-2.0-src.zip java程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        keepalive = val;    }    /**     * get current HTTP keepalive mode.     */    public static boolean getKeepAlive()    {        return keepalive;    }    /**     * Parse the input stream. For each root level object, method     * <code>objectParsed</code> is called.     */    synchronized void parse(InputStream is) throws Exception    {        // reset values (XmlRpc objects are reusable)        errorLevel = NONE;        errorMsg = null;        values = new Stack();        if (cdata == null)        {            cdata = new StringBuffer(128);        }        else        {            cdata.setLength(0);        }        readCdata = false;        currentValue = null;        long now = System.currentTimeMillis();        if (parserClass == null)        {            // try to get the name of the SAX driver from the System properties            String driver;            try            {                driver = System.getProperty("sax.driver", DEFAULT_PARSER);            }            catch (SecurityException e)            {                // An unsigned applet may not access system properties.                driver = DEFAULT_PARSER;            }            setDriver(driver);        }        Parser parser = null;        try        {            parser = (Parser) parserClass.newInstance();        }        catch (NoSuchMethodError nsm)        {            // This is thrown if no constructor exists for the parser class            // and is transformed into a regular exception.            throw new Exception("Can't create Parser: " + parserClass);        }        parser.setDocumentHandler(this);        parser.setErrorHandler(this);        if (debug)        {            System.out.println("Beginning parsing XML input stream");        }        try        {            if(inputEncoding == null)            {                       parser.parse(new InputSource(is));            }            else            {              parser.parse( new InputSource( new InputStreamReader(is, inputEncoding)));            }        }        finally        {            // Clear any huge buffers.            if (cdata.length() > 128 * 4)            {                // Exceeded original capacity by greater than 4x; release                // buffer to prevent leakage.                cdata = null;            }        }        if (debug)        {            System.out.println ("Spent " + (System.currentTimeMillis() - now)                    + " millis parsing");        }    }    /**     * This method is called when a root level object has been parsed.     * Sub-classes implement this callback to receive the fully parsed     * object.     */    protected abstract void objectParsed(Object what);    ////////////////////////////////////////////////////////////////    // methods called by XML parser    /**     * Method called by SAX driver.     */    public void characters(char ch[], int start, int length)            throws SAXException    {        if (readCdata)        {            cdata.append(ch, start, length);        }    }    /**     * Method called by SAX driver.     */    public void endElement(String name) throws SAXException    {        if (debug)        {            System.out.println("endElement: " + name);        }        // finalize character data, if appropriate        if (currentValue != null && readCdata)        {            currentValue.characterData(cdata.toString());            cdata.setLength(0);            readCdata = false;        }        if ("value".equals(name))        {            // Only handle top level objects or objects contained in            // arrays here.  For objects contained in structs, wait            // for </member> (see code below).            int depth = values.size();            if (depth < 2 || values.elementAt(depth - 2).hashCode() != STRUCT)            {                Value v = currentValue;                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.out.println("startElement: " + name);        }        if ("value".equals(name))        {            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 a XML-RPC value parsed from the request.     */    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)        {            switch (type)            {                case ARRAY:                    array.addElement(child.value);                    break;                case 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.out.println ("setting type to "+types[type]);            this.type = type;            switch (type)            {                case ARRAY:                    value = array = new Vector();                    break;                case STRUCT:                    value = struct = new Hashtable();                    break;            }        }        /**         * 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 = typeFactory.createInteger(cdata);                    break;                case BOOLEAN:                    value = typeFactory.createBoolean(cdata);                    break;                case DOUBLE:                    value = typeFactory.createDouble(cdata);                    break;                case DATE:                    value = typeFactory.createDate(cdata);                    break;                case BASE64:                    value = typeFactory.createBase64(cdata);                    break;                case STRING:                    value = typeFactory.createString(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);        }    }}

⌨️ 快捷键说明

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