Example usage for org.jdom2 Document getDocument

List of usage examples for org.jdom2 Document getDocument

Introduction

In this page you can find the example usage for org.jdom2 Document getDocument.

Prototype

@Override
public Document getDocument() 

Source Link

Document

Always returns this Document Instance

Usage

From source file:edu.unc.lib.deposit.normalize.VocabularyEnforcementJob.java

License:Apache License

@Override
public void runJob() {
    Model model = getWritableModel();//from  w  w  w .j  a  v a 2  s  .com

    // Get the list of all objects being ingested in this job
    List<String> resourcePIDs = new ArrayList<>();
    Bag deposit = model.getBag(getDepositPID().getURI());
    walkChildrenDepthFirst(deposit, resourcePIDs, true);

    SAXBuilder sb = new SAXBuilder(new XMLReaderSAX2Factory(false));

    // Vocabulary mappings need to be resolved against the destination since they are not in the hierarchy yet
    PID destinationPID = new PID(getDepositStatus().get(DepositField.containerId.name()));

    for (String resourcePID : resourcePIDs) {
        PID pid = new PID(resourcePID);
        File modsFile = new File(getDescriptionDir(), pid.getUUID() + ".xml");

        // Check if the resource has a description
        if (modsFile.exists()) {
            try {
                Document modsDoc = sb.build(modsFile);

                // Update the MODS document to use approved terms when possible if the vocabularies support remapping
                log.debug("Updating document terms for {} within destination {}", pid, destinationPID);
                boolean modified = updateDocumentTerms(destinationPID, modsDoc.getRootElement());

                // Update the mods document if it was changed
                if (modified) {
                    try (FileOutputStream fos = new FileOutputStream(modsFile)) {
                        new XMLOutputter(Format.getPrettyFormat()).output(modsDoc.getDocument(), fos);
                    }
                }

                // Capture any invalid affiliations as relations
                log.debug("Adding invalid terms for {} within destination {}", pid, destinationPID);
                addInvalidTerms(pid, destinationPID, modsDoc.getRootElement(), model);

            } catch (JDOMException | IOException e) {
                log.error("Failed to parse description file {}", modsFile.getAbsolutePath(), e);
            }
        }
    }
}