List of usage examples for javax.xml.stream XMLReporter XMLReporter
XMLReporter
From source file:com.ggvaidya.scinames.model.Project.java
public static Project loadFromFile(File loadFromFile) throws IOException { Project project = null;//from ww w .j a va2s. c o m XMLInputFactory factory = XMLInputFactory.newFactory(); factory.setXMLReporter(new XMLReporter() { @Override public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException { LOGGER.warning(errorType + " while loading project from XML file '" + loadFromFile + "': " + message + " (related info: " + relatedInformation.toString() + ", location: " + location); } }); try { XMLEventReader reader = factory.createXMLEventReader( new XmlStreamReader(new GZIPInputStream(new FileInputStream(loadFromFile)))); project = ProjectXMLReader.read(reader); project.setFile(loadFromFile); project.lastModifiedProperty().saved(); reader.close(); } catch (XMLStreamException ex) { throw new IOException("Could not read project from XML file '" + loadFromFile + "': " + ex, ex); } return project; /* DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Configure upcoming document builder. dbf.setIgnoringComments(true); dbf.setIgnoringElementContentWhitespace(true); Document docProject; try { DocumentBuilder db = dbf.newDocumentBuilder(); docProject = db.parse(loadFromFile); } catch (SAXException ex) { throw new IOException("Could not load project XML file: " + ex); } catch (ParserConfigurationException ex) { throw new RuntimeException("Could not load XML parser configuration: " + ex); } // Load project. Project newProject; try { newProject = serializeFromDocument(docProject, loadFromFile); } catch(SAXException e) { throw new IOException("XML file loaded but project could not be read: " + e); } catch(IllegalStateException e) { throw new IOException("XML file contains errors in content: " + e); } return newProject; */ }
From source file:org.gephi.io.importer.api.ImportUtils.java
public static XMLStreamReader getXMLReader(Reader reader) { try {/*from w w w .j av a2 s.c o m*/ XMLInputFactory inputFactory = XMLInputFactory.newInstance(); if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) { inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE); } inputFactory.setXMLReporter(new XMLReporter() { @Override public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException { throw new RuntimeException("Error:" + errorType + ", message : " + message); //System.out.println("Error:" + errorType + ", message : " + message); } }); return inputFactory.createXMLStreamReader(reader); } catch (XMLStreamException ex) { throw new RuntimeException(NbBundle.getMessage(ImportUtils.class, "ImportUtils.error_io")); } }
From source file:org.omegat.util.TMXReader2.java
public TMXReader2() { factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); factory.setXMLReporter(new XMLReporter() { public void report(String message, String error_type, Object info, Location location) throws XMLStreamException { Log.logWarningRB("TMXR_WARNING_WHILE_PARSING", location.getLineNumber(), location.getColumnNumber()); Log.log(message + ": " + info); warningsCount++;/* ww w . j a v a 2s. c o m*/ } }); factory.setXMLResolver(TMX_DTD_RESOLVER_2); dateFormat1 = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); dateFormat1.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); dateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormatOut = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); dateFormatOut.setTimeZone(TimeZone.getTimeZone("UTC")); }