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);
}
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());
}
}
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());
}
}
}
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;
}
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();
}
}
Aggregations