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

📄 saxwriterfilter.java

📁 一个自然语言处理的Java开源工具包。LingPipe目前已有很丰富的功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            mWriter.flush();         } catch (IOException e) {             // do nothing        }    }    /**     * Prints the start element, using the qualified name, and sorting     * the attributes using the underlying string ordering.  Namespace     * URI and local names are ignored, and qualified name must not be     * <code>null</code>.     *     * @param namespaceURI The URI of the namespace for this element.     * @param localName The local name (without prefix) for this     * element.     * @param qName The qualified name (with prefix, if any) for this     * element.     * @param atts The attributes for this element.     */    public void startElement(String namespaceURI, String localName,                             String qName, Attributes atts)        throws SAXException {        super.startElement(namespaceURI,localName,qName,atts);        if (mStartedElement) {            mPrinter.print(">");            mStartedElement=false;        }        mPrinter.print('<');        mPrinter.print(qName);        printAttributes(atts);        mStartedElement = true;        // close is picked up later in implicit continuation        // mPrinter.print('>');    }    /**     * Prints the end element, using the qualified name.  Namespace     * URI and local name parameters are ignored, and the qualified     * name must not be <code>null</code>     *     * @param namespaceURI The URI of the namespace for this element.     * @param localName The local name (without prefix) for this     * element.     * @param qName The qualified name (with prefix, if any) for this     * element.     */    public void endElement(String namespaceURI, String localName,                           String qName)        throws SAXException{        super.endElement(namespaceURI,localName,qName);        if (mStartedElement) {            mPrinter.print("/>");            mStartedElement = false;            return;        }        mPrinter.print('<');        mPrinter.print('/');        mPrinter.print(qName);        mPrinter.print('>');    }    /**     * Prints the characters in the specified range.     *     * @param ch Character array from which to draw characters.     * @param start Index of first character to print.     * @param length Number of characters to print.     */    public void characters(char[] ch, int start, int length)        throws SAXException {        super.characters(ch,start,length);        if (mStartedElement) {            mPrinter.print('>');            mStartedElement = false;        }        printCharacters(ch,start,length);    }    /**     * Does not print ignorable whitespace, nor does it send the     * event to the contained handler.     *     * @param ch Character array from which to draw characters.     * @param start Index of first character to print.     * @param length Number of characters to print.     */    public void ignorableWhitespace(char[] ch, int start, int length)        throws SAXException {        // super.ignorableWhitespace(ch,start,length);    }    /**     * Print a representation of the proecssing instruction.  This     * will be <code>&langle;?<i>Target</i>&rangle;</code> if there is     * no data, or * <code>&lt;?<i>Target</i>     * <i>Data</i>&gt;</code> if there is data.     *     * @param target Target of the instruction.     * @param data Value of the instruction, or <code>null</code>.     */    public void processingInstruction(String target, String data)        throws SAXException {        super.processingInstruction(target,data);        if (mStartedElement) {            mPrinter.print('>');            mStartedElement = false;        }        mPrinter.print("<?");        mPrinter.print(target);        if (data != null && data.length() > 0) {            mPrinter.print(' ');            mPrinter.print(data);        }        mPrinter.print("?>");    }    // prints atts and outstanding namespace decls    private void printAttributes(Attributes atts) {        if (mPrefixMap.size() > 0) {            Iterator it = mPrefixMap.entrySet().iterator();            while (it.hasNext()) {                Map.Entry entry = (Map.Entry) it.next();                String key = entry.getKey().toString();                String value = entry.getValue().toString();                printAttribute("xmlns:" + key,value);            }            mPrefixMap.clear();        }        TreeSet orderedAtts = new TreeSet();        for (int i = 0; i < atts.getLength(); ++i)            orderedAtts.add(atts.getQName(i));        Iterator attsIterator = orderedAtts.iterator();        while (attsIterator.hasNext()) {            String attQName = attsIterator.next().toString();            printAttribute(attQName,atts.getValue(attQName));        }    }    /**     * Prints an attribute and value, with value properly     * escaped. Prints leading space before attribute and value pair.     *     * @param att Attribute name.     * @param val Attribute value.     */    private void printAttribute(String att, String val) {        mPrinter.print(' ');        mPrinter.print(att);        mPrinter.print('=');        mPrinter.print('"');        printCharacters(val);        mPrinter.print('"');    }    /**     * Print the specified string, with appropriate escapes.     *     * @param s Print the characters in the specified string.     */    private void printCharacters(String s) {        printCharacters(s.toCharArray(),0,s.length());    }    /**     * Print the specified range of characters, with escapes.     *     * @param ch Array of characters from which to draw.     * @param start Index of first character to print.     * @param length Number of characters to print.     */    private void printCharacters(char[] ch, int start, int length) {        for (int i = start; i < start+length; ++i)            printCharacter(ch[i]);    }    /**     * Print the specified character, rendering it as an entity if     * necessary (see class doc).     *     * @param c Character to print.     */    private void printCharacter(char c) {        // note: does not catch illegal conjugate pairs        if (!mCharsetEncoder.canEncode(c)) {            printEntity("#x" + Integer.toHexString((int)c));            return;        }        switch (c) {        case '<':  { printEntity("lt"); break; }        case '>':  { printEntity("gt"); break; }        case '&':  { printEntity("amp"); break; }        case '"':  { printEntity("quot"); break; }        default:   { mPrinter.print(c); }        }    }    /**     * Print the specified entity.     *     * @param entity Name of entity to print.     */    private void printEntity(String entity) {        mPrinter.print('&');        mPrinter.print(entity);        mPrinter.print(';');    }    /**     * Prints the XML declaration, including the character set     * declaration and the DTD if any is defined.  The declaration     * printed is:     * <blockquote>     *   <code>&lt;?xml version="1.0" encoding="<i>CharSet</i>"?&gt;</code>.     * </blockquote>     * where <code><i>CharSet</i></code> is the string representation     * of the character set being used.  No spaces are included after     *  the XML declaration or the DTD declaration, if any.     */    private void printXMLDeclaration() {        mPrinter.print("<?xml");        printAttribute("version","1.0");        printAttribute("encoding",mCharsetName);        mPrinter.print("?>");        if (mDtdString != null) {            mPrinter.print(mDtdString);        }    }}

⌨️ 快捷键说明

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