Search in sources :

Example 1 with AltoChange

use of org.goobi.beans.AltoChange in project goobi-workflow by intranda.

the class Metadaten method saveAlto.

public void saveAlto() {
    AltoChange[] changes = new Gson().fromJson(this.altoChanges, AltoChange[].class);
    try {
        AltoSaver.saveAltoChanges(getCurrentAltoPath(), changes);
        this.loadJsonAlto();
        FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, Helper.getTranslation("savedAlto"), null);
        FacesContext.getCurrentInstance().addMessage("altoChanges", fm);
    } catch (JDOMException | IOException | SwapException | DAOException | InterruptedException e) {
        // TODO Auto-generated catch block
        log.error(e);
        FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, Helper.getTranslation("errorSavingAlto"), null);
        FacesContext.getCurrentInstance().addMessage("altoChanges", fm);
    }
}
Also used : DAOException(de.sub.goobi.helper.exceptions.DAOException) SwapException(de.sub.goobi.helper.exceptions.SwapException) Gson(com.google.gson.Gson) AltoChange(org.goobi.beans.AltoChange) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with AltoChange

use of org.goobi.beans.AltoChange in project goobi-workflow by intranda.

the class AltoSaver method saveAltoChanges.

public static void saveAltoChanges(Path altoFile, AltoChange[] changes) throws JDOMException, IOException {
    if (changes == null || changes.length == 0) {
        return;
    }
    Document doc = sax.build(altoFile.toFile());
    Namespace namespace = Namespace.getNamespace("alto", doc.getRootElement().getNamespaceURI());
    for (AltoChange change : changes) {
        String xpath = String.format("//alto:String[@ID='%s']", change.getWordId());
        XPathExpression<Element> compXpath = xFactory.compile(xpath, Filters.element(), null, namespace);
        Element stringEl = compXpath.evaluateFirst(doc);
        if (stringEl != null) {
            stringEl.setAttribute("CONTENT", change.getValue());
        }
    }
    try (OutputStream out = Files.newOutputStream(altoFile)) {
        XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
        xmlOut.output(doc, out);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) OutputStream(java.io.OutputStream) AltoChange(org.goobi.beans.AltoChange) Document(org.jdom2.Document) Namespace(org.jdom2.Namespace)

Aggregations

AltoChange (org.goobi.beans.AltoChange)2 Gson (com.google.gson.Gson)1 DAOException (de.sub.goobi.helper.exceptions.DAOException)1 SwapException (de.sub.goobi.helper.exceptions.SwapException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 FacesMessage (javax.faces.application.FacesMessage)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1 Namespace (org.jdom2.Namespace)1 XMLOutputter (org.jdom2.output.XMLOutputter)1