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);
}
}
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);
}
}
Aggregations