List of usage examples for javax.xml.stream XMLStreamException printStackTrace
public void printStackTrace(PrintStream s)
From source file:gate.corpora.FastInfosetDocumentFormat.java
/** * Unpacks markup in the GATE-specific standoff XML markup format. * // w w w . j av a 2s. c o m * @param doc * the document to process * @param statusListener * optional status listener to receive status messages * @throws DocumentFormatException * if a fatal error occurs during parsing */ private void unpackGateFormatMarkup(Document doc, StatusListener statusListener) throws DocumentFormatException { boolean docHasContentButNoValidURL = hasContentButNoValidUrl(doc); try { Reader inputReader = null; InputStream inputStream = null; XMLStreamReader xsr = null; String encoding = ((TextualDocument) doc).getEncoding(); if (docHasContentButNoValidURL) { xsr = new StAXDocumentParser(IOUtils.toInputStream(doc.getContent().toString(), encoding), getStAXManager()); } else { inputStream = doc.getSourceUrl().openStream(); xsr = new StAXDocumentParser(inputStream, getStAXManager()); } // find the opening GateDocument tag xsr.nextTag(); // parse the document try { DocumentStaxUtils.readGateXmlDocument(xsr, doc, statusListener); } finally { xsr.close(); if (inputStream != null) { inputStream.close(); } if (inputReader != null) { inputReader.close(); } } } catch (XMLStreamException e) { doc.getFeatures().put("parsingError", Boolean.TRUE); Boolean bThrow = (Boolean) doc.getFeatures().get(GateConstants.THROWEX_FORMAT_PROPERTY_NAME); if (bThrow != null && bThrow.booleanValue()) { // the next line is commented to avoid Document creation fail on // error throw new DocumentFormatException(e); } else { Out.println("Warning: Document remains unparsed. \n" + "\n Stack Dump: "); e.printStackTrace(Out.getPrintWriter()); } // if } catch (IOException ioe) { throw new DocumentFormatException("I/O exception for " + doc.getSourceUrl().toString(), ioe); } }