Example usage for org.jdom2.input.stax DefaultStAXFilter DefaultStAXFilter

List of usage examples for org.jdom2.input.stax DefaultStAXFilter DefaultStAXFilter

Introduction

In this page you can find the example usage for org.jdom2.input.stax DefaultStAXFilter DefaultStAXFilter.

Prototype

DefaultStAXFilter

Source Link

Usage

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);//from ww  w.j  a va  2 s .  co m
        return result;
    }
}