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

📄 processor.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }

        public final void endEntity(final String arg0) throws SAXException {
        }

        public final void startCDATA() throws SAXException {
        }

        public final void endCDATA() throws SAXException {
        }

        private final void writeAttributes(final Attributes atts) throws IOException {
            final StringBuffer sb = new StringBuffer();
            final int len = atts.getLength();
            for ( int i = 0; i < len; i++ ) {
                sb.append( " " ).append( atts.getLocalName( i ) ).append( "=\"" ).append( esc( atts.getValue( i ) ) ).append( "\"" );
            }
            this.w.write( sb.toString() );
        }

        /**
         * Encode string with escaping.
         * 
         * @param str string to encode.
         * @return encoded string
         */
        private final String esc(final String str) {
            final StringBuffer sb = new StringBuffer( str.length() );
            for ( int i = 0; i < str.length(); i++ ) {
                final char ch = str.charAt( i );
                switch ( ch ) {
                    case '&' :
                        sb.append( "&amp;" );
                        break;

                    case '<' :
                        sb.append( "&lt;" );
                        break;

                    case '>' :
                        sb.append( "&gt;" );
                        break;

                    case '\"' :
                        sb.append( "&quot;" );
                        break;

                    default :
                        if ( ch > 0x7f ) {
                            sb.append( "&#" ).append( Integer.toString( ch ) ).append( ';' );
                        } else {
                            sb.append( ch );
                        }

                }
            }
            return sb.toString();
        }

        private final void writeIdent() throws IOException {
            int n = this.ident;
            while ( n > 0 ) {
                if ( n > SAXWriter.OFF.length ) {
                    this.w.write( SAXWriter.OFF );
                    n -= SAXWriter.OFF.length;
                } else {
                    this.w.write( SAXWriter.OFF,
                                  0,
                                  n );
                    n = 0;
                }
            }
        }

        private final void closeElement() throws IOException {
            if ( this.openElement ) {
                this.w.write( ">\n" );
            }
            this.openElement = false;
        }

    }

    /**
     * A {@link org.xml.sax.ContentHandler ContentHandler} that splits XML
     * documents into smaller chunks. Each chunk is processed by the nested
     * {@link org.xml.sax.ContentHandler ContentHandler} obtained from
     * {@link java.net.ContentHandlerFactory ContentHandlerFactory}. This is
     * useful for running XSLT engine against large XML document that will
     * hardly fit into the memory all together. <p> TODO use complete path for
     * subdocumentRoot
     */
    private final static class InputSlicingHandler extends DefaultHandler {
        private String                subdocumentRoot;

        private ContentHandler        rootHandler;

        private ContentHandlerFactory subdocumentHandlerFactory;

        private boolean               subdocument = false;

        private ContentHandler        subdocumentHandler;

        /**
         * Constructs a new {@link InputSlicingHandler SubdocumentHandler}
         * object.
         * 
         * @param subdocumentRoot name/path to the root element of the
         *        subdocument
         * @param rootHandler content handler for the entire document
         *        (subdocument envelope).
         * @param subdocumentHandlerFactory a
         *        {@link ContentHandlerFactory ContentHandlerFactory} used to
         *        create {@link ContentHandler ContentHandler} instances for
         *        subdocuments.
         */
        public InputSlicingHandler(final String subdocumentRoot,
                                   final ContentHandler rootHandler,
                                   final ContentHandlerFactory subdocumentHandlerFactory) {
            this.subdocumentRoot = subdocumentRoot;
            this.rootHandler = rootHandler;
            this.subdocumentHandlerFactory = subdocumentHandlerFactory;
        }

        public final void startElement(final String namespaceURI,
                                       final String localName,
                                       final String qName,
                                       final Attributes list) throws SAXException {
            if ( this.subdocument ) {
                this.subdocumentHandler.startElement( namespaceURI,
                                                      localName,
                                                      qName,
                                                      list );
            } else if ( localName.equals( this.subdocumentRoot ) ) {
                this.subdocumentHandler = this.subdocumentHandlerFactory.createContentHandler();
                this.subdocumentHandler.startDocument();
                this.subdocumentHandler.startElement( namespaceURI,
                                                      localName,
                                                      qName,
                                                      list );
                this.subdocument = true;
            } else if ( this.rootHandler != null ) {
                this.rootHandler.startElement( namespaceURI,
                                               localName,
                                               qName,
                                               list );
            }
        }

        public final void endElement(final String namespaceURI,
                                     final String localName,
                                     final String qName) throws SAXException {
            if ( this.subdocument ) {
                this.subdocumentHandler.endElement( namespaceURI,
                                                    localName,
                                                    qName );
                if ( localName.equals( this.subdocumentRoot ) ) {
                    this.subdocumentHandler.endDocument();
                    this.subdocument = false;
                }
            } else if ( this.rootHandler != null ) {
                this.rootHandler.endElement( namespaceURI,
                                             localName,
                                             qName );
            }
        }

        public final void startDocument() throws SAXException {
            if ( this.rootHandler != null ) {
                this.rootHandler.startDocument();
            }
        }

        public final void endDocument() throws SAXException {
            if ( this.rootHandler != null ) {
                this.rootHandler.endDocument();

            }
        }

        public final void characters(final char[] buff,
                                     final int offset,
                                     final int size) throws SAXException {
            if ( this.subdocument ) {
                this.subdocumentHandler.characters( buff,
                                                    offset,
                                                    size );
            } else if ( this.rootHandler != null ) {
                this.rootHandler.characters( buff,
                                             offset,
                                             size );
            }
        }

    }

    /**
     * A {@link org.xml.sax.ContentHandler ContentHandler} that splits XML
     * documents into smaller chunks. Each chunk is processed by the nested
     * {@link org.xml.sax.ContentHandler ContentHandler} obtained from
     * {@link java.net.ContentHandlerFactory ContentHandlerFactory}. This is
     * useful for running XSLT engine against large XML document that will
     * hardly fit into the memory all together. <p> TODO use complete path for
     * subdocumentRoot
     */
    private static final class OutputSlicingHandler extends DefaultHandler {
        private String                subdocumentRoot;

        private ContentHandlerFactory subdocumentHandlerFactory;

        private EntryElement          entryElement;

        private boolean               isXml;

        private boolean               subdocument = false;

        private ContentHandler        subdocumentHandler;

        /**
         * Constructs a new {@link OutputSlicingHandler SubdocumentHandler}
         * object.
         * 
         * @param subdocumentHandlerFactory a
         *        {@link ContentHandlerFactory ContentHandlerFactory} used to
         *        create {@link ContentHandler ContentHandler} instances for
         *        subdocuments.
         * @param entryElement TODO.
         * @param isXml TODO.
         */
        public OutputSlicingHandler(final ContentHandlerFactory subdocumentHandlerFactory,
                                    final EntryElement entryElement,
                                    final boolean isXml) {
            this.subdocumentRoot = "class";
            this.subdocumentHandlerFactory = subdocumentHandlerFactory;
            this.entryElement = entryElement;
            this.isXml = isXml;
        }

        public final void startElement(final String namespaceURI,
                                       final String localName,
                                       final String qName,
                                       final Attributes list) throws SAXException {
            if ( this.subdocument ) {
                this.subdocumentHandler.startElement( namespaceURI,
                                                      localName,
                                                      qName,
                                                      list );
            } else if ( localName.equals( this.subdocumentRoot ) ) {
                final String name = list.getValue( "name" );
                if ( name == null || name.length() == 0 ) {
                    throw new SAXException( "Class element without name attribute." );
                }
                try {
                    this.entryElement.openEntry( this.isXml ? name.concat( ".class.xml" ) : name.concat( ".class" ) );
                } catch ( final IOException ex ) {
                    throw new SAXException( ex.toString(),
                                            ex );
                }
                this.subdocumentHandler = this.subdocumentHandlerFactory.createContentHandler();
                this.subdocumentHandler.startDocument();
                this.subdocumentHandler.startElement( namespaceURI,
                                                      localName,
                                                      qName,
                                                      list );
                this.subdocument = true;
            }
        }

        public final void endElement(final String namespaceURI,
                                     final String localName,
                                     final String qName) throws SAXException {
            if ( this.subdocument ) {
                this.subdocumentHandler.endElement( namespaceURI,
                                                    localName,
                                                    qName );
                if ( localName.equals( this.subdocumentRoot ) ) {
                    this.subdocumentHandler.endDocument();
                    this.subdocument = false;
                    try {
                        this.entryElement.closeEntry();
                    } catch ( final IOException ex ) {
                        throw new SAXException( ex.toString(),
                                                ex );
                    }
                }
            }
        }

        public final void startDocument() throws SAXException {
        }

        public final void endDocument() throws SAXException {
        }

        public final void characters(final char[] buff,
                                     final int offset,
                                     final int size) throws SAXException {
            if ( this.subdocument ) {
                this.subdocumentHandler.characters( buff,
                                                    offset,
                                                    size );
            }
        }

    }

    private static interface EntryElement {

        OutputStream openEntry(String name) throws IOException;

        void closeEntry() throws IOException;

    }

    private static final class SingleDocElement
        implements
        EntryElement {
        private OutputStream os;

        public SingleDocElement(final OutputStream os) {
            this.os = os;
        }

        public OutputStream openEntry(final String name) throws IOException {
            return this.os;
        }

        public void closeEntry() throws IOException {
            this.os.flush();
        }

    }

    private static final class ZipEntryElement
        implements
        EntryElement {
        private ZipOutputStream zos;

        public ZipEntryElement(final ZipOutputStream zos) {
            this.zos = zos;
        }

        public OutputStream openEntry(final String name) throws IOException {
            final ZipEntry entry = new ZipEntry( name );
            this.zos.putNextEntry( entry );
            return this.zos;
        }

        public void closeEntry() throws IOException {
            this.zos.flush();
            this.zos.closeEntry();
        }

    }

}

⌨️ 快捷键说明

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