Search in sources :

Example 1 with UnicodeReader

use of org.talend.xml.sax.io.UnicodeReader in project tdi-studio-se by Talend.

the class ComplexSAXLooper method parse.

/**
     * Parse the XML file. Buffer the result in LoopEntry.
     * 
     * @param is InputStream
     */
public void parse(java.io.InputStream is, String charset) {
    this.charset = charset;
    Reader reader = null;
    try {
        DefaultHandler hd = null;
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        if (rootPath == null || rootPath.equals("")) {
            hd = newHandler();
        } else {
            hd = newHandler2();
        }
        saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
        // routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
        reader = new UnicodeReader(is, this.charset);
        org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
        saxParser.parse(inSource, hd);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : UnicodeReader(org.talend.xml.sax.io.UnicodeReader) Reader(java.io.Reader) SAXParser(javax.xml.parsers.SAXParser) UnicodeReader(org.talend.xml.sax.io.UnicodeReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException)

Example 2 with UnicodeReader

use of org.talend.xml.sax.io.UnicodeReader in project tdi-studio-se by Talend.

the class ComplexSAXLooper method parse.

/**
     * Parse the XML file. Buffer the result in LoopEntry.
     * 
     * @param fileURL file URL
     */
public void parse(String fileURL, String charset) {
    this.charset = charset;
    Reader reader = null;
    try {
        DefaultHandler hd = null;
        SAXParser saxParser = null;
        if (!ignoreDTD) {
            //orginal code
            saxParser = SAXParserFactory.newInstance().newSAXParser();
        } else {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            saxParser = spf.newSAXParser();
        }
        if (rootPath == null || rootPath.equals("")) {
            hd = newHandler();
        } else {
            hd = newHandler2();
        }
        saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
        reader = new UnicodeReader(new java.io.FileInputStream(fileURL), this.charset);
        org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
        saxParser.parse(inSource, hd);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : UnicodeReader(org.talend.xml.sax.io.UnicodeReader) Reader(java.io.Reader) UnicodeReader(org.talend.xml.sax.io.UnicodeReader) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 3 with UnicodeReader

use of org.talend.xml.sax.io.UnicodeReader in project tdi-studio-se by Talend.

the class SimpleSAXLooper method call.

public Object call() throws Exception {
    Reader reader = null;
    try {
        DefaultHandler handler = null;
        if (nodesList.size() > 0) {
            SAXLoopCompositeHandler chd = new SAXLoopCompositeHandler();
            for (int i = 0; i < nodesList.size(); i++) {
                XMLNodes ns = nodesList.get(i);
                chd.register(new SimpleSAXLoopHandler(ns, multiCache));
            }
            handler = chd;
        } else {
            hd = new SimpleSAXLoopHandler(nodes, bcache);
            handler = hd;
        }
        SAXParser saxParser = null;
        if (!ignoreDTD) {
            //orginal code
            saxParser = SAXParserFactory.newInstance().newSAXParser();
        } else {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            saxParser = spf.newSAXParser();
        }
        saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
        if (fileURL != null) {
            // routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
            reader = new UnicodeReader(new java.io.FileInputStream(fileURL), this.charset);
            org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
            saxParser.parse(inSource, handler);
        } else {
            reader = new UnicodeReader(is, this.charset);
            org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
            saxParser.parse(inSource, handler);
        }
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } finally {
            if (multiCache != null) {
                multiCache.notifyErrorOccurred();
            }
            if (bcache != null) {
                bcache.notifyErrorOccurred();
            }
        }
    }
    return null;
}
Also used : UnicodeReader(org.talend.xml.sax.io.UnicodeReader) Reader(java.io.Reader) UnicodeReader(org.talend.xml.sax.io.UnicodeReader) XMLNodes(org.talend.xml.sax.simpleparser.model.XMLNodes) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXParser(javax.xml.parsers.SAXParser) SAXLoopCompositeHandler(org.talend.xml.sax.SAXLoopCompositeHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

Reader (java.io.Reader)3 SAXParser (javax.xml.parsers.SAXParser)3 UnicodeReader (org.talend.xml.sax.io.UnicodeReader)3 DefaultHandler (org.xml.sax.helpers.DefaultHandler)3 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 SAXException (org.xml.sax.SAXException)2 SAXLoopCompositeHandler (org.talend.xml.sax.SAXLoopCompositeHandler)1 XMLNodes (org.talend.xml.sax.simpleparser.model.XMLNodes)1