List of usage examples for javax.xml.stream XMLStreamException XMLStreamException
public XMLStreamException(Throwable th)
From source file:org.restcomm.connect.http.client.Downloader.java
private HttpResponseDescriptor validateXML(final HttpResponseDescriptor descriptor) throws XMLStreamException { if (descriptor.getContentLength() > 0) { try {// ww w . j av a 2 s .co m // parse an XML document into a DOM tree String xml = descriptor.getContentAsString().trim().replaceAll("&([^;]+(?!(?:\\w|;)))", "&$1"); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); //FIXME:should we externalize RVD encoding default? parser.parse(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8")))); return descriptor; } catch (final Exception e) { throw new XMLStreamException("Error parsing the RCML:" + e); } } return descriptor; }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
/** * @param wrt//from w w w . j a v a 2 s . co m * @param syn * @return * @throws XMLStreamException */ private void exportSingle(XMLStreamWriter wrt, Synchronizer<?, ?> syn) throws XMLStreamException { ExporterMessages messages = new ExporterMessages(); messagesPerExporter.put(syn.getClass().getName(), messages); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.ENTITIES_EXPORT_ELEMENT); wrt.writeAttribute(SynchronizationConstants.ID_ATTRIBUTE, syn.getClass().getName()); Exporter<?, ?> exp = syn.getExporter(); ExportingIterator<?> it = exp.getExportingIterator(); DefaultImportConfigurationDescriptor importConfig = getDefaultImportConfiguraton(syn); if (importConfig != null) { try { configurationMarshaller.marshal(importConfig, wrt); } catch (JAXBException e) { throw new XMLStreamException(e); } } messages.setPerEntityErrorMessages(new ArrayList<String>()); messages.setPerEntityNotes(new ArrayList<String>()); while (it.hasNext()) { it.next(); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.ENTITY_EXPORT_ELEMENT); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.DATA_ELEMENT); Exception exportError = null; try { it.export(new ExportWriter(wrt)); } catch (XMLStreamException e) { //there's not much we can do about these but to give up. throw e; } catch (Exception e) { exportError = e; } wrt.writeEndElement(); //data if (exportError == null) { String notes = it.getNotes(); if (notes != null) { messages.getPerEntityNotes().add(notes); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.NOTES_ELEMENT); wrt.writeCharacters(notes); wrt.writeEndElement(); } } else { String message = ThrowableUtil.getStackAsString(exportError); messages.getPerEntityErrorMessages().add(message); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.ERROR_MESSAGE_ELEMENT); wrt.writeCharacters(message); wrt.writeEndElement(); } wrt.writeEndElement(); //entity } String notes = exp.getNotes(); messages.setExporterNotes(notes); if (notes != null) { wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.NOTES_ELEMENT); wrt.writeCharacters(notes); wrt.writeEndElement(); } wrt.writeEndElement(); //entities }
From source file:org.slc.sli.api.resources.config.StAXMsgBodyReader.java
/** * Adds elements to the underlying HashMap for EntityBody * @param key The position to insert into * @param memberDataPair A pair representing the Object to insert into (Left) as well as * a boolean value to determine whether the element is a part of a * list or a single value * @param elements The underlying map to insert into *//*from w w w . jav a 2 s . c o m*/ @SuppressWarnings("unchecked") private static void addToElements(final String key, final Pair<Object, Boolean> memberDataPair, final Map<String, Object> elements) throws XMLStreamException { final boolean member = memberDataPair.getRight(); final Object toAdd = memberDataPair.getLeft(); // Duplicate key for a non list item if (elements.containsKey(key) && !member) { throw new XMLStreamException("Reassignment of key for non list member"); } if (member) { if (elements.containsKey(key)) { // We have already inserted this list ((List<Object>) elements.get(key)).add(toAdd); } else { // First time inserting to a list element elements.put(key, new ArrayList<Object>(Arrays.asList(toAdd))); } } else { elements.put(key, toAdd); } }
From source file:org.slc.sli.api.resources.config.StAXMsgBodyReader.java
/** * Reads individual elements inside of a XML Document * @param reader xml reader/*from w w w. jav a 2 s .c o m*/ * @return a pair representing the Object value of the element (Left) as well as * a boolean value representing either true (part of a list) or false * (single value) * @throws XMLStreamException on malformed XML */ private static final Pair<Object, Boolean> readElement(final XMLStreamReader reader) throws XMLStreamException { final QName elementName = reader.getName(); final StringBuilder sb = new StringBuilder(); final Map<String, Object> data = new HashMap<String, Object>(); final Boolean member = isMember(reader); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { final QName key = reader.getName(); final Pair<Object, Boolean> elem = readElement(reader); addToElements(key.getLocalPart(), elem, data); break; } case XMLStreamConstants.END_ELEMENT: { if (elementName.equals(reader.getName())) { if (data.size() > 0) { return new ImmutablePair<Object, Boolean>(data, member); } else { return new ImmutablePair<Object, Boolean>(sb.toString(), member); } } else { throw new XMLStreamException(reader.getName().getLocalPart()); } } case XMLStreamConstants.CHARACTERS: { sb.append(reader.getText()); break; } default: { throw new XMLStreamException(); } } } throw new XMLStreamException(); }
From source file:org.slc.sli.modeling.xmi.comp.XmiMappingReader.java
private static final XmiMapping readMapping(final XMLStreamReader reader) throws XMLStreamException { assertStartElement(reader);/* ww w. j av a 2s .c o m*/ assertName(XmiMappingConstants.MAPPING, reader); XmiFeature lhs = null; XmiFeature rhs = null; XmiMappingStatus status = null; String comment = null; String tracking = ""; boolean done = false; while (!done && reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if (match(XmiMappingConstants.LHS_FEATURE, reader)) { if (lhs == null) { lhs = readFeature(reader.getName(), reader); } else { throw new XMLStreamException("duplicate " + XmiMappingConstants.LHS_FEATURE + " tag."); } } else if (match(XmiMappingConstants.RHS_FEATURE, reader)) { rhs = readFeature(reader.getName(), reader); } else if (match(XmiMappingConstants.STATUS, reader)) { status = readStatus(reader); } else if (match(XmiMappingConstants.COMMENT, reader)) { comment = readStringContent(reader.getName(), reader); } else if (match(XmiMappingConstants.TRACKING, reader)) { tracking = readStringContent(reader.getName(), reader); } else if (match(XmiMappingConstants.LHS_MISSING, reader)) { XMLStreamReaderTools.skipElement(reader); } else if (match(XmiMappingConstants.RHS_MISSING, reader)) { XMLStreamReaderTools.skipElement(reader); } else { throw new AssertionError(reader.getLocalName()); } break; } case XMLStreamConstants.END_ELEMENT: { assertName(XmiMappingConstants.MAPPING, reader); done = true; break; } case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.COMMENT: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } return new XmiMapping(lhs, rhs, status, tracking, comment); }
From source file:org.sonar.cxx.sensors.utils.StaxParser.java
/** * parse XML stream:// w w w . jav a 2 s. c o m * * @param xmlReader - java.io.Reader = input file * @exception XMLStreamException javax.xml.stream.XMLStreamException */ public void parse(Reader xmlReader) throws XMLStreamException { if (isoControlCharsAwareParser) { throw new XMLStreamException("Method call not supported when isoControlCharsAwareParser=true"); } parse(inf.rootElementCursor(xmlReader)); }
From source file:org.sonar.cxx.sensors.utils.StaxParser.java
/** * parse XML stream:// ww w. ja va 2 s .co m * * @param xmlUrl - java.net.URL = input stream * @exception XMLStreamException javax.xml.stream.XMLStreamException */ public void parse(URL xmlUrl) throws XMLStreamException { try { parse(xmlUrl.openStream()); } catch (IOException e) { throw new XMLStreamException(e); } }
From source file:org.sonar.plugins.android.lint.AndroidLintProfileImporter.java
public void parse(Reader reader, final ValidationMessages messages) { try {//from ww w. j a v a 2 s .c o m StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() { @Override public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { try { rootCursor.advance(); collectRules(rootCursor.descendantElementCursor("issue"), messages); } catch (ParseException e) { throw new XMLStreamException(e); } } }); parser.parse(reader); } catch (XMLStreamException e) { throw new XmlParserException(e); } }
From source file:org.sonar.plugins.clover.CloverXmlReportParser.java
private StaxParser createStaxParser() { return new StaxParser(new StaxParser.XmlStreamHandler() { @Override/*from w ww . ja v a 2 s. c o m*/ public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { try { collectProjectMeasures(rootCursor.advance()); } catch (ParseException e) { throw new XMLStreamException(e); } } }); }
From source file:org.sonar.plugins.clover.XmlReportParser.java
protected void collect(File xmlFile) { try {/*from w ww . j a va 2s. co m*/ if (reportExists(xmlFile)) { LOG.info("Parsing " + xmlFile.getCanonicalPath()); StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() { public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { try { collectProjectMeasures(rootCursor.advance()); } catch (ParseException e) { throw new XMLStreamException(e); } } }); parser.parse(xmlFile); } } catch (Exception e) { throw new XmlParserException(e); } }