List of usage examples for javax.xml.stream XMLStreamException getMessage
public String getMessage()
From source file:com.norconex.collector.http.sitemap.impl.StandardSitemapResolver.java
private void resolveLocation(String location, HttpClient httpClient, SitemapURLAdder sitemapURLAdder, Set<String> resolvedLocations) { if (stopped) { LOG.debug("Skipping resolution of sitemap " + "location (stop requested): " + location); return;/*from ww w . jav a 2 s . co m*/ } if (resolvedLocations.contains(location)) { return; } HttpGet method = null; try { method = new HttpGet(location); // Execute the method. HttpResponse response = httpClient.execute(method); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { LOG.info("Resolving sitemap: " + location); InputStream is = response.getEntity().getContent(); if ("application/x-gzip".equals(response.getFirstHeader("Content-Type").getValue())) { is = new GZIPInputStream(is); } parseLocation(is, httpClient, sitemapURLAdder, resolvedLocations, location); IOUtils.closeQuietly(is); LOG.info(" Resolved: " + location); } else if (statusCode == HttpStatus.SC_NOT_FOUND) { LOG.debug("No sitemap found : " + location); } else { LOG.error("Could not obtain sitemap: " + location + ". Expected status code " + HttpStatus.SC_OK + ", but got " + statusCode); } } catch (XMLStreamException e) { LOG.error("Cannot fetch sitemap: " + location + " -- Likely an invalid sitemap XML format causing " + "a parsing error (actual error: " + e.getMessage() + ")."); } catch (Exception e) { LOG.error("Cannot fetch sitemap: " + location + " (" + e.getMessage() + ")"); } finally { resolvedLocations.add(location); if (method != null) { method.releaseConnection(); } } }
From source file:com.snaplogic.snaps.checkfree.CheckfreeExecute.java
private Object parseXML2JSON(String envelope, XmlUtils xmlUtils) { Source source = new StreamSource(new StringReader(envelope)); try {/* w w w. j av a 2 s.c o m*/ return xmlUtils.convertToJson(xmlInputFactory, jsonOutputFactory, source); } catch (XMLStreamException e) { throw new ExecutionException(e, ERROR_PARSING_XML).withReason(e.getMessage()) .withResolution(VERIFY_THE_RETURNED_XML_IS_PARSEABLE); } }
From source file:com.marklogic.contentpump.AggregateXMLReader.java
protected void initStreamReader(InputSplit inSplit) throws IOException, InterruptedException { start = 0;/*from www . ja v a 2s. co m*/ end = inSplit.getLength(); overflow = false; setFile(((FileSplit) inSplit).getPath()); configFileNameAsCollection(conf, file); fInputStream = fs.open(file); try { xmlSR = f.createXMLStreamReader(fInputStream, encoding); } catch (XMLStreamException e) { LOG.error(e.getMessage(), e); } if (useAutomaticId) { idGen = new IdGenerator(file.toUri().getPath() + "-" + ((FileSplit) inSplit).getStart()); } }
From source file:org.sbml.bargraph.MainWindow.java
/** * Updates the bar graph and other panels in the main window using * data derived by reading the given @p file. * //from w w w . j a v a 2 s . c o m * @param file The SBML file to parse and analyze for the graph. */ public void updatePanelForSBMLFile(File file) { if (file == null) { return; } SBMLStats stats; try { stats = new SBMLStats(file); } catch (javax.xml.stream.XMLStreamException e) { Log.warning("Exception while parsing '" + file.getPath() + "':"); Log.warning(e.getMessage()); Dialog.error(this, "Unable to parse the given SBML File: " + e.getMessage(), "File parsing error"); return; } catch (java.io.IOException e) { Log.warning("Exception while parsing '" + file.getPath() + "':"); Log.warning(e.getMessage()); Dialog.error(this, "I/O error trying to read the given SBML File: " + e.getMessage(), "File parsing error"); return; } Log.note("Graphing data: " + stats.asString()); fileNameField.setText(stats.getFile().getPath()); fileNameField.setDisabledTextColor(Color.BLACK); // The row could be called anything, since we don't display the name. String row = "Row 1"; chartData.clear(); chartData.addValue(stats.getNumSpecies(), row, "Species"); chartData.addValue(stats.getNumCompartments(), row, "Compartments"); chartData.addValue(stats.getNumReactions(), row, "Reactions"); chartData.addValue(stats.getNumParameters(), row, "Parameters"); chartData.addValue(stats.getNumRules(), row, "Rules"); chartData.addValue(stats.getNumUnitDefinitions(), row, "Unit definitions"); if (stats.getSBMLLevel() >= 2) { chartData.addValue(stats.getNumEvents(), row, "Events"); chartData.addValue(stats.getNumFunctionDefinitions(), row, "Function definitions"); if (stats.getSBMLVersion() >= 2) { chartData.addValue(stats.getNumConstraints(), row, "Constraints"); chartData.addValue(stats.getNumInitialAssignments(), row, "Initial assignments"); } if (stats.getSBMLVersion() >= 2 && stats.getSBMLLevel() < 3) { chartData.addValue(stats.getNumSpeciesTypes(), row, "Species types"); chartData.addValue(stats.getNumCompartmentTypes(), row, "Compartment types"); } } validate(); repaint(); }
From source file:com.evolveum.midpoint.common.validator.Validator.java
private EventResult readFromStreamAndValidate(XMLStreamReader stream, OperationResult objectResult, Map<String, String> rootNamespaceDeclarations, OperationResult validatorResult) { objectResult.addContext(START_LINE_NUMBER, stream.getLocation().getLineNumber()); Document objectDoc;/* w ww .ja va2 s . co m*/ try { // Parse the object from stream to DOM objectDoc = domConverter.buildDocument(stream); } catch (XMLStreamException ex) { validatorResult.recordFatalError("XML parsing error: " + ex.getMessage(), ex); if (handler != null) { handler.handleGlobalError(validatorResult); } objectResult.recordFatalError(ex); return EventResult.skipObject(); } objectResult.addContext(END_LINE_NUMBER, stream.getLocation().getLineNumber()); // This element may not have complete namespace definitions for a // stand-alone // processing, therefore copy namespace definitions from the root // element Element objectElement = DOMUtil.getFirstChildElement(objectDoc); DOMUtil.setNamespaceDeclarations(objectElement, rootNamespaceDeclarations); return validateObjectInternal(objectElement, objectResult, validatorResult); }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterImpl.java
@Override @SuppressWarnings("deprecation") public Collection<Class<?>> convert(final Resource... resources) { Map<String, CtClass> ctClasses = new HashMap<String, CtClass>(); Map<String, Class<?>> existingClasses = new HashMap<String, Class<?>>(); for (Resource resource : resources) { if (resource.isReadable()) { LOG.info("Getting existing classes from " + resource); try { existingClasses.putAll(findExistingClasses(resource.getInputStream())); } catch (XMLStreamException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); }//from ww w. j av a2 s. c o m } } for (Resource resource : resources) { if (resource.isReadable()) { LOG.info("Creating classes from " + resource); try { ctClasses.putAll(createClasses(existingClasses, resource.getInputStream())); } catch (XMLStreamException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } } } for (Resource resource : resources) { if (resource.isReadable()) { LOG.info("Defining classes from " + resource + " to classes"); try { defineClasses(ctClasses, resource.getInputStream()); } catch (XMLStreamException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } catch (ModelXmlCompilingException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } catch (NotFoundException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } } } List<Class<?>> classes = new ArrayList<Class<?>>(); for (CtClass ctClass : ctClasses.values()) { try { classes.add(ctClass.toClass(classLoader)); } catch (CannotCompileException e) { throw new IllegalStateException(L_ERROR_WHILE_PARSING_MODEL_XML + e.getMessage(), e); } } classes.addAll(existingClasses.values()); return classes; }
From source file:fedora.server.storage.translation.AtomDODeserializer.java
private void addAuditDatastream(Entry entry) throws ObjectIntegrityException, StreamIOException { try {/* w w w . ja v a 2 s . c o m*/ Reader auditTrail; if (m_format.equals(ATOM_ZIP1_1)) { File f = getContentSrcAsFile(entry.getContentSrc()); auditTrail = new InputStreamReader(new FileInputStream(f), m_encoding); } else { auditTrail = new StringReader(entry.getContent()); } m_obj.getAuditRecords().addAll(DOTranslationUtility.getAuditRecords(auditTrail)); auditTrail.close(); } catch (XMLStreamException e) { throw new ObjectIntegrityException(e.getMessage(), e); } catch (IOException e) { throw new StreamIOException(e.getMessage(), e); } }
From source file:edu.stanford.cfuller.imageanalysistools.fitting.ImageObject.java
public String writeToXMLString() { StringWriter sw = new StringWriter(); try {/*from w ww . j a va2s. c o m*/ XMLStreamWriter xsw = XMLOutputFactory.newFactory().createXMLStreamWriter(sw); this.writeToXML(xsw); } catch (XMLStreamException e) { LoggingUtilities.getLogger() .severe("Exception encountered while writing XML correction output: " + e.getMessage()); } return sw.toString(); }
From source file:com.evolveum.midpoint.common.validator.Validator.java
public void validate(InputStream inputStream, OperationResult validatorResult, String objectResultOperationName) { XMLStreamReader stream = null; try {/*from w ww . j a v a 2s . c om*/ Map<String, String> rootNamespaceDeclarations = new HashMap<String, String>(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); stream = xmlInputFactory.createXMLStreamReader(inputStream); int eventType = stream.nextTag(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (!stream.getName().equals(SchemaConstants.C_OBJECTS)) { // This has to be an import file with a single objects. Try // to process it. OperationResult objectResult = validatorResult.createSubresult(objectResultOperationName); progress++; objectResult.addContext(OperationResult.CONTEXT_PROGRESS, progress); EventResult cont = null; try { cont = readFromStreamAndValidate(stream, objectResult, rootNamespaceDeclarations, validatorResult); } catch (RuntimeException e) { // Make sure that unexpected error is recorded. objectResult.recordFatalError(e); throw e; } if (!cont.isCont()) { String message = null; if (cont.getReason() != null) { message = cont.getReason(); } else { message = "Object validation failed (no reason given)"; } if (objectResult.isUnknown()) { objectResult.recordFatalError(message); } validatorResult.recordFatalError(message); return; } // return to avoid processing objects in loop validatorResult.computeStatus("Validation failed", "Validation warnings"); return; } // Extract root namespace declarations for (int i = 0; i < stream.getNamespaceCount(); i++) { rootNamespaceDeclarations.put(stream.getNamespacePrefix(i), stream.getNamespaceURI(i)); } } else { throw new SystemException("StAX Malfunction?"); } while (stream.hasNext()) { eventType = stream.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { OperationResult objectResult = validatorResult.createSubresult(objectResultOperationName); progress++; objectResult.addContext(OperationResult.CONTEXT_PROGRESS, progress); EventResult cont = null; try { // Read and validate individual object from the stream cont = readFromStreamAndValidate(stream, objectResult, rootNamespaceDeclarations, validatorResult); } catch (RuntimeException e) { if (objectResult.isUnknown()) { // Make sure that unexpected error is recorded. objectResult.recordFatalError(e); } throw e; } if (objectResult.isError()) { errors++; } objectResult.cleanupResult(); validatorResult.summarize(); if (cont.isStop()) { if (cont.getReason() != null) { validatorResult.recordFatalError("Processing has been stopped: " + cont.getReason()); } else { validatorResult.recordFatalError("Processing has been stopped"); } // This means total stop, no other objects will be // processed return; } if (!cont.isCont()) { if (stopAfterErrors > 0 && errors >= stopAfterErrors) { validatorResult.recordFatalError("Too many errors (" + errors + ")"); return; } } } } } catch (XMLStreamException ex) { // validatorResult.recordFatalError("XML parsing error: " + // ex.getMessage()+" on line "+stream.getLocation().getLineNumber(),ex); validatorResult.recordFatalError("XML parsing error: " + ex.getMessage(), ex); if (handler != null) { handler.handleGlobalError(validatorResult); } return; } // Error count is sufficient. Detailed messages are in subresults validatorResult.computeStatus(errors + " errors, " + (progress - errors) + " passed"); }
From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor.java
@Override public void readObjectsIteratively(@NotNull ParserSource source, @NotNull ParsingContext parsingContext, RootXNodeHandler handler) throws SchemaException, IOException { InputStream is = source.getInputStream(); XMLStreamReader stream = null; try {/*from w ww . j a v a 2s.c o m*/ stream = XMLInputFactory.newInstance().createXMLStreamReader(is); int eventType = stream.nextTag(); if (eventType != XMLStreamConstants.START_ELEMENT) { throw new SystemException("StAX Malfunction?"); } DOMConverter domConverter = new DOMConverter(); Map<String, String> rootNamespaceDeclarations = new HashMap<>(); QName objectsMarker = schemaRegistry.getPrismContext().getObjectsElementName(); if (objectsMarker != null && !QNameUtil.match(stream.getName(), objectsMarker)) { readSingleObjectIteratively(stream, rootNamespaceDeclarations, domConverter, handler); } for (int i = 0; i < stream.getNamespaceCount(); i++) { rootNamespaceDeclarations.put(stream.getNamespacePrefix(i), stream.getNamespaceURI(i)); } while (stream.hasNext()) { eventType = stream.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (!readSingleObjectIteratively(stream, rootNamespaceDeclarations, domConverter, handler)) { return; } } } } catch (XMLStreamException ex) { String lineInfo = stream != null ? " on line " + stream.getLocation().getLineNumber() : ""; throw new SchemaException("Exception while parsing XML" + lineInfo + ": " + ex.getMessage(), ex); } finally { if (source.closeStreamAfterParsing()) { IOUtils.closeQuietly(is); } } }