org.apache.poi.util.StaxHelper Java Examples
The following examples show how to use
org.apache.poi.util.StaxHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BufferedStringsTable.java From excel-streaming-reader with Apache License 2.0 | 6 votes |
@Override public void readFrom(InputStream is) throws IOException { try { XMLEventReader xmlEventReader = StaxHelper.newXMLInputFactory().createXMLEventReader(is); while(xmlEventReader.hasNext()) { XMLEvent xmlEvent = xmlEventReader.nextEvent(); if(xmlEvent.isStartElement() && xmlEvent.asStartElement().getName().getLocalPart().equals("si")) { list.add(parseCT_Rst(xmlEventReader)); } } } catch(XMLStreamException e) { throw new IOException(e); } }
Example #2
Source File: StreamingWorkbookReader.java From excel-streaming-reader with Apache License 2.0 | 6 votes |
void loadSheets(XSSFReader reader, SharedStringsTable sst, StylesTable stylesTable, int rowCacheSize) throws IOException, InvalidFormatException, XMLStreamException { lookupSheetNames(reader); //Some workbooks have multiple references to the same sheet. Need to filter //them out before creating the XMLEventReader by keeping track of their URIs. //The sheets are listed in order, so we must keep track of insertion order. SheetIterator iter = (SheetIterator) reader.getSheetsData(); Map<URI, InputStream> sheetStreams = new LinkedHashMap<>(); while(iter.hasNext()) { InputStream is = iter.next(); sheetStreams.put(iter.getSheetPart().getPartName().getURI(), is); } //Iterate over the loaded streams int i = 0; for(URI uri : sheetStreams.keySet()) { XMLEventReader parser = StaxHelper.newXMLInputFactory().createXMLEventReader(sheetStreams.get(uri)); sheets.add(new StreamingSheet(sheetProperties.get(i++).get("name"), new StreamingSheetReader(sst, stylesTable, parser, use1904Dates, rowCacheSize))); } }
Example #3
Source File: PresetGeometries.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unused") public void init(InputStream is) throws XMLStreamException, JAXBException { // StAX: EventFilter startElementFilter = new EventFilter() { @Override public boolean accept(XMLEvent event) { return event.isStartElement(); } }; XMLInputFactory staxFactory = StaxHelper.newXMLInputFactory(); XMLEventReader staxReader = staxFactory.createXMLEventReader(is); XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter); // ignore StartElement: /* XMLEvent evDoc = */ staxFiltRd.nextEvent(); // JAXB: JAXBContext jaxbContext = JAXBContext.newInstance(BINDING_PACKAGE); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); long cntElem = 0; while (staxFiltRd.peek() != null) { StartElement evRoot = (StartElement)staxFiltRd.peek(); String name = evRoot.getName().getLocalPart(); JAXBElement<CTCustomGeometry2D> el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class); CTCustomGeometry2D cus = el.getValue(); cntElem++; if(containsKey(name)) { LOG.log(POILogger.WARN, "Duplicate definition of " + name); } put(name, new CustomGeometry(cus)); } }
Example #4
Source File: XSSFPullParser.java From hadoopoffice with Apache License 2.0 | 5 votes |
/** * * @param sheetName name of sheet * @param sheetInputStream sheet in xlsx format input stream * @param sst Shared strings table of Excel file * @param styles StylesTable of the document * @param isDate1904 date format 1904 (true) or 1900 (false) * @throws XMLStreamException */ public XSSFPullParser(String sheetName, InputStream sheetInputStream, SharedStringsTable sst, StylesTable styles, DataFormatter dataFormatter, boolean isDate1904) throws XMLStreamException { this.sheetName = sheetName; this.xer = StaxHelper.newXMLInputFactory().createXMLEventReader(sheetInputStream); this.nextBeingCalled = false; this.finalized = false; this.nextRow = 1; this.currentRow = 1; this.sst = sst; this.styles = styles; this.dataFormatter = dataFormatter; this.isDate1904 = isDate1904; }
Example #5
Source File: DrawSimpleShape.java From lams with GNU General Public License v2.0 | 4 votes |
protected static CustomGeometry getCustomGeometry(String name, Graphics2D graphics) { @SuppressWarnings("unchecked") Map<String, CustomGeometry> presets = (graphics == null) ? null : (Map<String, CustomGeometry>)graphics.getRenderingHint(Drawable.PRESET_GEOMETRY_CACHE); if (presets == null) { presets = new HashMap<String,CustomGeometry>(); if (graphics != null) { graphics.setRenderingHint(Drawable.PRESET_GEOMETRY_CACHE, presets); } String packageName = "org.apache.poi.sl.draw.binding"; InputStream presetIS = Drawable.class.getResourceAsStream("presetShapeDefinitions.xml"); // StAX: EventFilter startElementFilter = new EventFilter() { @Override public boolean accept(XMLEvent event) { return event.isStartElement(); } }; try { XMLInputFactory staxFactory = StaxHelper.newXMLInputFactory(); XMLEventReader staxReader = staxFactory.createXMLEventReader(presetIS); XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter); // Ignore StartElement: staxFiltRd.nextEvent(); // JAXB: JAXBContext jaxbContext = JAXBContext.newInstance(packageName); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); while (staxFiltRd.peek() != null) { StartElement evRoot = (StartElement)staxFiltRd.peek(); String cusName = evRoot.getName().getLocalPart(); // XMLEvent ev = staxReader.nextEvent(); JAXBElement<org.apache.poi.sl.draw.binding.CTCustomGeometry2D> el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class); CTCustomGeometry2D cusGeom = el.getValue(); presets.put(cusName, new CustomGeometry(cusGeom)); } staxFiltRd.close(); staxReader.close(); } catch (Exception e) { throw new RuntimeException("Unable to load preset geometries.", e); } finally { IOUtils.closeQuietly(presetIS); } } return presets.get(name); }