Search in sources :

Example 51 with XMLReader

use of org.xml.sax.XMLReader in project asterixdb by apache.

the class TopologyDefinitionParser method parseInternal.

private ClusterTopology parseInternal(InputSource in) throws IOException, SAXException {
    XMLReader parser;
    parser = XMLReaderFactory.createXMLReader();
    SAXContentHandler handler = new SAXContentHandler();
    parser.setContentHandler(handler);
    parser.parse(in);
    if (stack.size() != 1) {
        throw new IllegalStateException("Malformed topology definition");
    }
    ElementStackEntry e = stack.pop();
    if (e.ports.size() != 1) {
        throw new IllegalArgumentException("Malformed topology definition");
    }
    NetworkEndpoint endpoint = e.ports.get(0).getEndpoint();
    if (endpoint.getType() != EndpointType.NETWORK_SWITCH) {
        throw new IllegalArgumentException("Top level content in cluster-topology must be network-switch");
    }
    return new ClusterTopology((NetworkSwitch) endpoint);
}
Also used : XMLReader(org.xml.sax.XMLReader)

Example 52 with XMLReader

use of org.xml.sax.XMLReader in project poi by apache.

the class XSSFEventBasedExcelExtractor method processSheet.

/**
     * Processes the given sheet
     */
public void processSheet(SheetContentsHandler sheetContentsExtractor, StylesTable styles, CommentsTable comments, ReadOnlySharedStringsTable strings, InputStream sheetInputStream) throws IOException, SAXException {
    DataFormatter formatter;
    if (locale == null) {
        formatter = new DataFormatter();
    } else {
        formatter = new DataFormatter(locale);
    }
    InputSource sheetSource = new InputSource(sheetInputStream);
    try {
        XMLReader sheetParser = SAXHelper.newXMLReader();
        ContentHandler handler = new XSSFSheetXMLHandler(styles, comments, strings, sheetContentsExtractor, formatter, formulasNotResults);
        sheetParser.setContentHandler(handler);
        sheetParser.parse(sheetSource);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
    }
}
Also used : InputSource(org.xml.sax.InputSource) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) ContentHandler(org.xml.sax.ContentHandler) DataFormatter(org.apache.poi.ss.usermodel.DataFormatter) XSSFSheetXMLHandler(org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler)

Example 53 with XMLReader

use of org.xml.sax.XMLReader in project poi by apache.

the class ReadOnlySharedStringsTable method readFrom.

/**
     * Read this shared strings table from an XML file.
     *
     * @param is The input stream containing the XML document.
     * @throws IOException if an error occurs while reading.
     * @throws SAXException if parsing the XML data fails.
     */
public void readFrom(InputStream is) throws IOException, SAXException {
    // test if the file is empty, otherwise parse it
    PushbackInputStream pis = new PushbackInputStream(is, 1);
    int emptyTest = pis.read();
    if (emptyTest > -1) {
        pis.unread(emptyTest);
        InputSource sheetSource = new InputSource(pis);
        try {
            XMLReader sheetParser = SAXHelper.newXMLReader();
            sheetParser.setContentHandler(this);
            sheetParser.parse(sheetSource);
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) PushbackInputStream(java.io.PushbackInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader)

Example 54 with XMLReader

use of org.xml.sax.XMLReader in project poi by apache.

the class FromHowTo method fetchSheetParser.

public XMLReader fetchSheetParser(SharedStringsTable sst) throws SAXException {
    XMLReader parser = XMLReaderFactory.createXMLReader();
    ContentHandler handler = new SheetHandler(sst);
    parser.setContentHandler(handler);
    return parser;
}
Also used : XMLReader(org.xml.sax.XMLReader) ContentHandler(org.xml.sax.ContentHandler)

Example 55 with XMLReader

use of org.xml.sax.XMLReader in project poi by apache.

the class FromHowTo method processAllSheets.

public void processAllSheets(String filename) throws Exception {
    OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ);
    try {
        XSSFReader r = new XSSFReader(pkg);
        SharedStringsTable sst = r.getSharedStringsTable();
        XMLReader parser = fetchSheetParser(sst);
        Iterator<InputStream> sheets = r.getSheetsData();
        while (sheets.hasNext()) {
            System.out.println("Processing new sheet:\n");
            InputStream sheet = sheets.next();
            InputSource sheetSource = new InputSource(sheet);
            parser.parse(sheetSource);
            sheet.close();
            System.out.println("");
        }
    } finally {
        pkg.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SharedStringsTable(org.apache.poi.xssf.model.SharedStringsTable) InputStream(java.io.InputStream) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) XMLReader(org.xml.sax.XMLReader) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Aggregations

XMLReader (org.xml.sax.XMLReader)234 InputSource (org.xml.sax.InputSource)186 SAXException (org.xml.sax.SAXException)82 IOException (java.io.IOException)75 SAXParserFactory (javax.xml.parsers.SAXParserFactory)51 SAXSource (javax.xml.transform.sax.SAXSource)48 SAXParser (javax.xml.parsers.SAXParser)42 StringReader (java.io.StringReader)37 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)35 InputStream (java.io.InputStream)28 ExpatReader (org.apache.harmony.xml.ExpatReader)24 ContentHandler (org.xml.sax.ContentHandler)20 TransformerException (javax.xml.transform.TransformerException)19 DOMSource (javax.xml.transform.dom.DOMSource)18 StreamSource (javax.xml.transform.stream.StreamSource)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 FileReader (java.io.FileReader)16 InputStreamReader (java.io.InputStreamReader)12 SAXParseException (org.xml.sax.SAXParseException)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10