Example usage for org.jdom2.input StAXStreamBuilder buildFragments

List of usage examples for org.jdom2.input StAXStreamBuilder buildFragments

Introduction

In this page you can find the example usage for org.jdom2.input StAXStreamBuilder buildFragments.

Prototype

public List<Content> buildFragments(XMLStreamReader reader, StAXFilter filter) throws JDOMException 

Source Link

Document

Read the entire XMLStreamReader and from it build a list of Content that conforms to the rules in the supplied StAXFilter.

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);// w  ww.  ja  v a2  s  .c o m
        return result;
    }
}