List of usage examples for javax.xml.stream XMLInputFactory newInstance
public static XMLInputFactory newInstance() throws FactoryConfigurationError
From source file:edu.harvard.i2b2.workplace.ws.MessageFactory.java
/** * Function creates Workplace response OMElement from xml string * @param xmlString//from w ww .ja v a 2 s .c o m * @return OMElement * @throws XMLStreamException */ public static OMElement createResponseOMElementFromString(String xmlString) throws I2B2Exception { OMElement returnElement = null; try { StringReader strReader = new StringReader(xmlString); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = xif.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(reader); returnElement = builder.getDocumentElement(); } catch (XMLStreamException e) { log.error("xml stream response WDO to OMElement"); throw new I2B2Exception("XML Stream error ", e); } catch (Exception e) { log.error("Error while converting Workplace response WDO to OMElement"); throw new I2B2Exception("Response OMElement creation error ", e); } return returnElement; }
From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlReader.java
public AlignmentXmlReader(File inputLocation) throws IOException { fs = null;//from w w w. ja v a 2 s .c o m try { fs = new FileInputStream(inputLocation); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlEventReader = xmlInputFactory.createXMLEventReader(fs); JAXBContext context; context = JAXBContext.newInstance(XmlMeta.class, Alignments.class); unmarshaller = context.createUnmarshaller(); } catch (JAXBException | XMLStreamException e1) { throw new IOException(e1); } }
From source file:edu.harvard.i2b2.ontology.ws.MessageFactory.java
/** * Function creates Ontology response OMElement from xml string * /*w w w . j ava 2s . c om*/ * @param xmlString * @return OMElement * @throws XMLStreamException */ public static OMElement createResponseOMElementFromString(String xmlString) throws I2B2Exception { OMElement returnElement = null; try { StringReader strReader = new StringReader(xmlString); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = xif.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(reader); returnElement = builder.getDocumentElement(); } catch (XMLStreamException e) { log.error("Error while converting Ontology response VDO to OMElement"); throw new I2B2Exception("XML Stream error ", e); } return returnElement; }
From source file:com.wavemaker.runtime.data.parser.BaseHbmParser.java
protected BaseHbmParser(Reader reader) { if (reader == null) { throw new IllegalArgumentException("Reader cannot be null"); }//from ww w. j a va 2 s . c o m this.reader = reader; try { XMLInputFactory factory = XMLInputFactory.newInstance(); setupEntityResolver(factory); this.xmlReader = factory.createXMLStreamReader(reader); } catch (XMLStreamException ex) { throw new WMRuntimeException(ex); } }
From source file:eionet.webq.converter.XmlSchemaExtractor.java
/** * Extracts {@code @xsi:noNamespaceSchemaLocation} or {@code @xsi:schemaLocation} attribute value from xml root element. * * @param source source to be searched./*from w w w . j a v a2 s. c o m*/ * @return {@code @xsi:noNamespaceSchemaLocation} or {@code @xsi:schemaLocation} attribute value, default {@code null} */ public String extractXmlSchema(byte[] source) { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); ByteArrayInputStream bais = new ByteArrayInputStream(source); XMLStreamReader xmlStreamReader = null; try { xmlStreamReader = xmlInputFactory.createXMLStreamReader(bais); while (xmlStreamReader.hasNext()) { if (xmlStreamReader.next() == START_ELEMENT) { return StringUtils.defaultString( parseNoNamespaceSchemaLocation(xmlStreamReader.getAttributeValue(XSI_NAMESPACE_URI, "noNamespaceSchemaLocation")), parseSchemaLocation( xmlStreamReader.getAttributeValue(XSI_NAMESPACE_URI, "schemaLocation"))); } } } catch (Exception e) { LOGGER.warn("exception thrown during extracting xml schema", e); } finally { IOUtils.closeQuietly(bais); if (xmlStreamReader != null) { try { xmlStreamReader.close(); } catch (XMLStreamException e) { LOGGER.warn("unable to close xml stream", e); } } } return null; }
From source file:eionet.webq.converter.JsonXMLBidirectionalConverter.java
/** * Converts xml to json./*ww w . j a va2s .co m*/ * * @param xml xml as byte array. * @return json as byte array. */ public byte[] convertXmlToJson(byte[] xml) { JsonXMLConfig config = new JsonXMLConfigBuilder().prettyPrint(true).autoArray(true).autoPrimitive(true) .build(); XMLInputFactory reader = XMLInputFactory.newInstance(); JsonXMLOutputFactory writer = new JsonXMLOutputFactory(config); return convert(reader, writer, xml); }
From source file:edu.harvard.i2b2.analysis.queryClient.CRCQueryClient.java
public static OMElement getQueryPayLoad(String str) throws Exception { StringReader strReader = new StringReader(str); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = xif.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(reader); OMElement lineItem = builder.getDocumentElement(); // log.debug("Line item string " + lineItem.toString()); return lineItem; }
From source file:edu.harvard.i2b2.crc.axis2.MessageFactory.java
/** * Function creates Workplace response OMElement from xml string * @param xmlString// ww w .ja v a 2s. c om * @return OMElement * @throws XMLStreamException */ public static OMElement createResponseOMElementFromString(String xmlString) throws I2B2Exception { OMElement returnElement = null; try { StringReader strReader = new StringReader(xmlString); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = xif.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(reader); returnElement = builder.getDocumentElement(); } catch (XMLStreamException e) { log.error("xml stream response PDO to OMElement"); throw new I2B2Exception("XML Stream error ", e); } catch (Exception e) { log.error("Error while converting CRC response PDO to OMElement"); throw new I2B2Exception("Response OMElement creation error ", e); } return returnElement; }
From source file:au.org.ala.bhl.DocumentPaginator.java
public void paginate(String filename, PageHandler handler) { XMLInputFactory factory = XMLInputFactory.newInstance(); try {//from w w w.j a va 2s . c om File f = new File(filename); if (f.length() == 0) { // empty file, can't paginate... return; } XMLStreamReader parser = factory.createXMLStreamReader(new FileInputStream(f), "cp1252"); paginateImpl(parser, handler); } catch (Exception ex) { throw new RuntimeException("Failed to paginate " + filename, ex); } }
From source file:fr.inria.oak.paxquery.pact.operators.unary.NavigationOperator.java
/** * /*from www. j av a 2s . c om*/ * @param record * @param treePattern * @param collector */ public static void navigation(NestedMetadata inputRecordSignature, Record record, int column, NavigationTreePattern navigationTreePattern, Collector<Record> collector) { XMLInputFactory factory = XMLInputFactory.newInstance(); try { StringValue value = record.getField(column, StringValue.class); XMLStreamReader streamReader = factory.createXMLStreamReader(new StringReader(value.getValue())); SingleDocumentExtractor extractor = new SingleDocumentExtractor(navigationTreePattern, streamReader); while (streamReader.hasNext()) { streamReader.next(); if (streamReader.getEventType() == XMLStreamConstants.START_ELEMENT) { extractor.startElement(); } else if (streamReader.getEventType() == XMLStreamConstants.END_ELEMENT) { extractor.endElement(); } else if (streamReader.getEventType() == XMLStreamConstants.CHARACTERS) { extractor.characters(); } if (extractor.getRecords().size() != 0) { Iterator<Record> pactRecordsIterator = extractor.getRecords().iterator(); while (pactRecordsIterator.hasNext()) { Record originalRecord = record.createCopy(); RecordOperations.concatenate(originalRecord, pactRecordsIterator.next()); collector.collect(originalRecord); } extractor.getRecords().clear(); } } } catch (XMLStreamException e) { logger.error("XMLStreamException", e); } }