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

📄 staxstream2sax.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//                throw new XMLStreamException(e);//            }//        } while (len == buf.length);    }    private void handleEndElement() throws XMLStreamException {        QName qName = staxStreamReader.getName();        try {            //construct prefix:localName from qName            String qname = "";            if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){                qname = qName.getPrefix() + ":";            }            qname += qName.getLocalPart();                        // fire endElement            _sax.endElement(                qName.getNamespaceURI(),                qName.getLocalPart(),                qname);             // end namespace bindings            int nsCount = staxStreamReader.getNamespaceCount();            for (int i = nsCount - 1; i >= 0; i--) {                String prefix = staxStreamReader.getNamespacePrefix(i);                if (prefix == null) { // true for default namespace                    prefix = "";                }                _sax.endPrefixMapping(prefix);            }        } catch (SAXException e) {            throw new XMLStreamException(e);        }    }    private void handleStartElement() throws XMLStreamException {        try {            // start namespace bindings            int nsCount = staxStreamReader.getNamespaceCount();            for (int i = 0; i < nsCount; i++) {                String prefix = staxStreamReader.getNamespacePrefix(i);                if (prefix == null) { // true for default namespace                    prefix = "";                }                _sax.startPrefixMapping(                    prefix,                    staxStreamReader.getNamespaceURI(i));            }            // fire startElement            QName qName = staxStreamReader.getName();            String prefix = qName.getPrefix();            String rawname;            if(prefix==null || prefix.length()==0)                rawname = qName.getLocalPart();            else                rawname = prefix + ':' + qName.getLocalPart();            Attributes attrs = getAttributes();            _sax.startElement(                qName.getNamespaceURI(),                qName.getLocalPart(),                rawname,                attrs);        } catch (SAXException e) {            throw new XMLStreamException(e);        }    }    /**     * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE     * StAXevent.     *      * @return the StAX attributes converted to an org.xml.sax.Attributes     */    private Attributes getAttributes() {        AttributesImpl attrs = new AttributesImpl();        int eventType = staxStreamReader.getEventType();        if (eventType != XMLStreamConstants.ATTRIBUTE            && eventType != XMLStreamConstants.START_ELEMENT) {            throw new InternalError(                "getAttributes() attempting to process: " + eventType);        }                // in SAX, namespace declarations are not part of attributes by default.        // (there's a property to control that, but as far as we are concerned        // we don't use it.) So don't add xmlns:* to attributes.        // gather non-namespace attrs        for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) {            String uri = staxStreamReader.getAttributeNamespace(i);            if(uri==null)   uri="";            String localName = staxStreamReader.getAttributeLocalName(i);            String prefix = staxStreamReader.getAttributePrefix(i);            String qName;            if(prefix==null || prefix.length()==0)                qName = localName;            else                qName = prefix + ':' + localName;            String type = staxStreamReader.getAttributeType(i);            String value = staxStreamReader.getAttributeValue(i);            attrs.addAttribute(uri, localName, qName, type, value);        }        return attrs;    }    private void handleNamespace() {        // no-op ???        // namespace events don't normally occur outside of a startElement        // or endElement    }    private void handleAttribute() {        // no-op ???        // attribute events don't normally occur outside of a startElement        // or endElement    }    private void handleDTD() {        // no-op ???        // it seems like we need to pass this info along, but how?    }    private void handleComment() {        // no-op ???    }    private void handleEntityReference() {        // no-op ???    }    private void handleSpace() {        // no-op ???        // this event is listed in the javadoc, but not in the spec.    }    private void handleNotationDecl() {        // no-op ???        // this event is listed in the javadoc, but not in the spec.    }    private void handleEntityDecl() {        // no-op ???        // this event is listed in the javadoc, but not in the spec.    }    private void handleCDATA() {        // no-op ???        // this event is listed in the javadoc, but not in the spec.    }            /**     * This class is only used internally so this method should never      * be called.     */    public DTDHandler getDTDHandler() { 	return null;    }    /**     * This class is only used internally so this method should never      * be called.     */    public ErrorHandler getErrorHandler() {	return null;    }    /**     * This class is only used internally so this method should never      * be called.     */    public boolean getFeature(String name) throws SAXNotRecognizedException,	SAXNotSupportedException    {	return false;    }    /**     * This class is only used internally so this method should never      * be called.     */    public void setFeature(String name, boolean value) throws 	SAXNotRecognizedException, SAXNotSupportedException     {    }    /**     * This class is only used internally so this method should never      * be called.     */    public void setDTDHandler(DTDHandler handler) throws NullPointerException {    }    /**     * This class is only used internally so this method should never      * be called.     */    public void setEntityResolver(EntityResolver resolver) throws 	NullPointerException     {    }    /**     * This class is only used internally so this method should never      * be called.     */    public EntityResolver getEntityResolver() {	return null;    }    /**     * This class is only used internally so this method should never      * be called.     */    public void setErrorHandler(ErrorHandler handler) throws 	NullPointerException    {    }    /**     * This class is only used internally so this method should never      * be called.     */    public void setProperty(String name, Object value) throws	SAXNotRecognizedException, SAXNotSupportedException {    }    /**     * This class is only used internally so this method should never      * be called.     */    public Object getProperty(String name) throws SAXNotRecognizedException,	SAXNotSupportedException    {	return null;    }        /**     * This class is only used internally so this method should never      * be called.     */    public int getColumnNumber() { 	return 0;     }        /**     * This class is only used internally so this method should never      * be called.     */    public int getLineNumber() { 	return 0;     }    /**     * This class is only used internally so this method should never      * be called.     */    public String getPublicId() { 	return null;     }    /**     * This class is only used internally so this method should never      * be called.     */    public String getSystemId() { 	return null;     }      }

⌨️ 快捷键说明

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