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

📄 saxchunkproducer.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    if (this.sourceNodesIndex < this.sourceNodes.getLength()) {
                        this.nextNode = this.sourceNodes.item(this.sourceNodesIndex);
                        this.chunkState = CHUNK_STATE_NODE;
                    }

                }

                break;
                }
            default:
                throw new IllegalStateException("Unsupported value in member chunkState: " + chunkState);
            }
        }

        if (chunkState == CHUNK_STATE_FINISH) {
            chunkOutput.setEndFlag();
        }
    }


    /**
     *  This method is used for DOM nodes that don't require two SAX events.
     *  i.e. every node except document and element nodes.
     *  @param _node the node to convert
     */
    private void convertSingleEventNode(Node _node) throws SAXException {

        switch (_node.getNodeType()) {
        case Node.TEXT_NODE:
            char[] ch = _node.getNodeValue().toCharArray();
            this.contentHandler.characters( ch, 0, ch.length );
            break;
        case Node.CDATA_SECTION_NODE:
            char[] cdata = _node.getNodeValue().toCharArray();
            if (this.lexicalHandler != null) {
                this.lexicalHandler.startCDATA();
            }

            this.contentHandler.characters( cdata, 0, cdata.length );

            if (this.lexicalHandler != null) {
                this.lexicalHandler.endCDATA();
            }
            break;
        case Node.PROCESSING_INSTRUCTION_NODE:
            this.contentHandler.processingInstruction( _node.getNodeName(), _node.getNodeValue() );
            break;
        case Node.ENTITY_REFERENCE_NODE:
            this.contentHandler.skippedEntity( _node.getNodeName() );
            break;
        case Node.COMMENT_NODE:
            if (this.lexicalHandler != null) {
                char[] comment = _node.getNodeValue().toCharArray();
                this.lexicalHandler.comment(comment, 0, comment.length);
            }
            break;
        case Node.DOCUMENT_TYPE_NODE:
            //"Document type node can't be translated: "
            break;
        case Node.DOCUMENT_FRAGMENT_NODE:
            //"Document fragment node can't be translated: "
            break;
        case Node.NOTATION_NODE:
            //"Notation node can't be translated: "
            break;
        case Node.ENTITY_NODE:
            //"Entity node can't be translated: "
            break;
        case Node.ATTRIBUTE_NODE:
            //"Standalone attribute node can't be translated: "
            break;
        default:
            //"unknown node type or node type not supported by this method
            break;
        }
    }


    /**
     *  creates a Attributes object (list of SAX attributes) containing the
     *  attributes of a given DOM element node.
     *  @param elem the element whose attributes shall be converted
     *  @return the SAX attribute list
     */
    private Attributes createSAXAttributes( Element elem ) {
        NamedNodeMap domAttributes = elem.getAttributes();
        AttributesImpl saxAttributes = new AttributesImpl();

        int length = domAttributes.getLength();

        for (int i = 0; i < length; i++) {

            Node node = domAttributes.item(i);
            String uri = domLevel2 ? node.getNamespaceURI() : "";
            String qName = node.getNodeName();
            String lName = domLevel2 ? node.getLocalName() : qName;

            saxAttributes.addAttribute(
                    (uri == null) ? "" : uri,
                    (lName == null) ? qName : lName,
                    qName, "",
                    node.getNodeValue());
        }

        return saxAttributes;
    }


    // SAX ContentHandler implementation


    /**
     *  Received notification of the beginning of the document.
     */
    public final void startDocument() throws SAXException {
        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.startDocument()..." );
            }

            this.contentHandler.startDocument();
            this.processLevel++;
            checkChunk();
        }

        depth -= deep ? 0 : 1;
    }


    /**
     *  Received notification of the end of the document.
     */
    public final void endDocument() throws SAXException {
        depth += deep ? 0 : 1;

        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.endDocument()..." );
            }

            this.contentHandler.endDocument();
            this.processLevel--;
            checkChunk();
        }
    }


    /**
     *  Receive notification of the start of an element.
     */
    public final void startElement( String namespaceURI, String localName, String rawName, Attributes atts )
            throws SAXException {
        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.startElement()..." );
            }

            this.contentHandler.startElement( namespaceURI, localName, rawName, atts );
            this.processLevel++;
            checkChunk();
        }

        depth -= deep ? 0 : 1;
    }


    /**
     *  Receive notification of the end of an element.
     */
    public final void endElement( String _namespaceURI, String _localName, String _rawName ) throws SAXException {
        depth = deep ? 0 : 1;

        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.endElement()..." );
            }

            this.contentHandler.endElement( _namespaceURI, _localName, _rawName );
            this.processLevel--;
            checkChunk();
        }
    }


    /**
     *  Receive notification of character data inside an element.
     */
    public final void characters( char[] ch, int start, int length ) throws SAXException {
        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.characters()..." );
            }

            char[] characters = new char[length];
            System.arraycopy( ch, start, characters, 0, length );

            this.contentHandler.characters( characters, 0, characters.length );
            checkChunk();
        }
    }


    /**
     *  Receive notification of a processing instruction.
     */
    public final void processingInstruction( String target, String data ) throws SAXException {
        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.pi ..." );
            }

            this.contentHandler.processingInstruction( target, data );
            checkChunk();
        }
    }


    /**
     *  Receive notification of a skipped entity.
     */
    public final void skippedEntity( java.lang.String name ) throws SAXException {
        if (deep || depth >= 0) {
            this.contentHandler.skippedEntity( name );
            checkChunk();
        }
    }


    /**
     *  Begin the scope of a prefix-URI Namespace mapping.
     */
    public final void startPrefixMapping( String prefix, String uri ) throws SAXException {
        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.startPrefixMapping ..." );
            }

            this.contentHandler.startPrefixMapping( prefix, uri );
            checkChunk();
        }
    }


    /**
     *  End the scope of a prefix-URI mapping.
     */
    public final void endPrefixMapping( String prefix ) throws SAXException {
        if (deep || depth >= 0) {
            if (debug) {
                System.out.println( "SAXChunkProducer.endPrefixMapping()..." );
            }

            this.contentHandler.endPrefixMapping( prefix );
            checkChunk();
        }
    }


    /**
     *  Receive notification of ignorable whitespace in element content.
     */
    public final void ignorableWhitespace( char[] ch, int start, int length ) throws SAXException {
        // ignorable whitespaces will be ignored
    }


    /**
     *  Receive an object for locating the origin of SAX document events.
     */
    public final void setDocumentLocator( Locator locator ) {
    // we don't care about the origin of the document
    }


    //
    // SAX LexicalHandler implemenation
    //


    public void comment( char[] ch, int start, int length ) throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.comment(ch, start, length);
            checkChunk();
        }
    }


    public void startCDATA() throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.startCDATA();
            checkChunk();
        }
    }


    public void endCDATA() throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.endCDATA();
            checkChunk();
        }
    }


    public void startDTD(String name, String publicId, String systemId)
            throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.startDTD(name, publicId, systemId);
            checkChunk();
        }
    }


    public void endDTD() throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.endDTD();
            checkChunk();
        }
    }


    public void startEntity(String name) throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.startEntity(name);
            checkChunk();
        }
    }


    public void endEntity(String name) throws SAXException {
        if ((this.lexicalHandler != null)
                && (deep || depth >= 0)) {
            this.lexicalHandler.startEntity(name);
            checkChunk();
        }
    }


    protected final void checkChunk() {
        if (this.delegate == null) {
            return;
        }

        try {
            if ((this.chunkOutput.getState() == ChunkOutputStream.STATE_OVERFLOW)
                    || (this.processLevel == 0)) {
                this.delegate.processChunk(this);
                this.chunkOutput.reset();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.toString());
        }
    }

}

⌨️ 快捷键说明

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