List of usage examples for org.jdom2.input StAXStreamBuilder StAXStreamBuilder
StAXStreamBuilder
From source file:edu.unc.lib.dl.cdr.services.rest.DepositController.java
License:Apache License
@RequestMapping(value = { "{uuid}/events" }, method = RequestMethod.GET)
public @ResponseBody Document getEvents(@PathVariable String uuid) throws Exception {
LOG.debug("getEvents( {} )", uuid);
Jedis jedis = getJedisPool().getResource();
String bagDirectory = jedis.hget(RedisWorkerConstants.DEPOSIT_STATUS_PREFIX + uuid,
RedisWorkerConstants.DepositField.directory.name());
getJedisPool().returnResource(jedis);
File bagFile = new File(bagDirectory);
if (!bagFile.exists())
return null;
File eventsFile = new File(bagDirectory, DepositConstants.EVENTS_FILE);
if (!eventsFile.exists())
return null;
Element events = new Element("events", JDOMNamespaceUtil.PREMIS_V2_NS);
Document result = new Document(events);
XMLInputFactory factory = XMLInputFactory.newInstance();
try (FileInputStream fis = new FileInputStream(eventsFile)) {
XMLStreamReader reader = factory.createXMLStreamReader(fis);
StAXStreamBuilder builder = new StAXStreamBuilder();
List<Content> list = builder.buildFragments(reader, new DefaultStAXFilter());
events.addContent(list);/* w w w . jav a 2s. com*/
return result;
}
}
From source file:org.kdp.word.utils.JDOMUtils.java
License:Apache License
public static Document parse(JDOMFactory factory, File inputfile) { try {/*from w w w . ja v a 2 s.co m*/ XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(inputfile)); StAXStreamBuilder staxBuilder = new StAXStreamBuilder(); staxBuilder.setFactory(factory); return staxBuilder.build(reader); } catch (FileNotFoundException | XMLStreamException | JDOMException ex) { throw new IllegalStateException("Cannot parse XML: " + inputfile, ex); } }