use of javax.xml.stream.XMLStreamException in project modrun by nanosai.
the class ModuleDependencyReader method readDependencies.
public static List<Dependency> readDependencies(Reader pomReader) {
List<Dependency> dependencies = new ArrayList<>();
XMLInputFactory factory = XMLInputFactory.newInstance();
try {
XMLStreamReader streamReader = factory.createXMLStreamReader(pomReader);
while (streamReader.hasNext()) {
streamReader.next();
if (streamReader.getEventType() == XMLStreamReader.START_ELEMENT) {
String elementName = streamReader.getLocalName();
if (elementName.equals("dependency")) {
Dependency dependency = parseDependency(streamReader);
dependencies.add(dependency);
}
}
}
} catch (XMLStreamException e) {
e.printStackTrace();
}
return dependencies;
}
use of javax.xml.stream.XMLStreamException in project openhab1-addons by openhab.
the class DenonConnector method getDocument.
private <T> T getDocument(String uri, Class<T> response) {
try {
String result = doHttpRequest("GET", uri, null);
logger.trace("result of getDocument for uri '{}':\r\n{}", uri, result);
if (StringUtils.isNotBlank(result)) {
JAXBContext jc = JAXBContext.newInstance(response);
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(IOUtils.toInputStream(result));
xsr = new PropertyRenamerDelegate(xsr);
@SuppressWarnings("unchecked") T obj = (T) jc.createUnmarshaller().unmarshal(xsr);
return obj;
}
} catch (UnmarshalException e) {
logger.debug("Failed to unmarshal xml document: {}", e.getMessage());
} catch (JAXBException e) {
logger.debug("Unexpected error occurred during unmarshalling of document: {}", e.getMessage());
} catch (XMLStreamException e) {
logger.debug("Communication error: {}", e.getMessage());
}
return null;
}
use of javax.xml.stream.XMLStreamException in project spring-framework by spring-projects.
the class AbstractStaxHandler method startDocument.
@Override
public final void startDocument() throws SAXException {
removeAllNamespaceMappings();
newNamespaceMapping();
try {
startDocumentInternal();
} catch (XMLStreamException ex) {
throw new SAXException("Could not handle startDocument: " + ex.getMessage(), ex);
}
}
use of javax.xml.stream.XMLStreamException in project spring-framework by spring-projects.
the class AbstractXMLStreamReader method getElementText.
@Override
public String getElementText() throws XMLStreamException {
if (getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", getLocation());
}
int eventType = next();
StringBuilder builder = new StringBuilder();
while (eventType != XMLStreamConstants.END_ELEMENT) {
if (eventType == XMLStreamConstants.CHARACTERS || eventType == XMLStreamConstants.CDATA || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
builder.append(getText());
} else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) {
// skipping
} else if (eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException("unexpected end of document when reading element text content", getLocation());
} else if (eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("element text content may not contain START_ELEMENT", getLocation());
} else {
throw new XMLStreamException("Unexpected event type " + eventType, getLocation());
}
eventType = next();
}
return builder.toString();
}
use of javax.xml.stream.XMLStreamException in project spring-framework by spring-projects.
the class Jaxb2CollectionHttpMessageConverter method read.
@Override
@SuppressWarnings("unchecked")
public T read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ParameterizedType parameterizedType = (ParameterizedType) type;
T result = createCollection((Class<?>) parameterizedType.getRawType());
Class<?> elementClass = (Class<?>) parameterizedType.getActualTypeArguments()[0];
try {
Unmarshaller unmarshaller = createUnmarshaller(elementClass);
XMLStreamReader streamReader = this.inputFactory.createXMLStreamReader(inputMessage.getBody());
int event = moveToFirstChildOfRootElement(streamReader);
while (event != XMLStreamReader.END_DOCUMENT) {
if (elementClass.isAnnotationPresent(XmlRootElement.class)) {
result.add(unmarshaller.unmarshal(streamReader));
} else if (elementClass.isAnnotationPresent(XmlType.class)) {
result.add(unmarshaller.unmarshal(streamReader, elementClass).getValue());
} else {
// should not happen, since we check in canRead(Type)
throw new HttpMessageConversionException("Could not unmarshal to [" + elementClass + "]");
}
event = moveToNextElement(streamReader);
}
return result;
} catch (UnmarshalException ex) {
throw new HttpMessageNotReadableException("Could not unmarshal to [" + elementClass + "]: " + ex.getMessage(), ex);
} catch (JAXBException ex) {
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
} catch (XMLStreamException ex) {
throw new HttpMessageConversionException(ex.getMessage(), ex);
}
}
Aggregations