Search in sources :

Example 51 with Document

use of com.google.cloud.dialogflow.v2beta1.Document in project goobi-workflow by intranda.

the class ProzesskopieForm method initializePossibleDigitalCollections.

private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();
    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext(); ) {
            Element projekt = iter.next();
            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext(); ) {
                    Element col = it2.next();
                    if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }
                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext(); ) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.prozessKopie.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext(); ) {
                            Element col = it2.next();
                            if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }
                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }
    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }
    if (isSingleChoiceCollection()) {
        this.digitalCollections.add(getDigitalCollectionIfSingleChoice());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) DigitalDocument(ugh.dl.DigitalDocument) JDOMException(org.jdom2.JDOMException)

Example 52 with Document

use of com.google.cloud.dialogflow.v2beta1.Document in project goobi-workflow by intranda.

the class HelperSchritte method extractAuthorityMetadata.

public static void extractAuthorityMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) {
    XPathFactory xFactory = XPathFactory.instance();
    XPathExpression<Element> authorityMetaXpath = xFactory.compile("//mets:xmlData/mods:mods/mods:extension/goobi:goobi/goobi:metadata[goobi:authorityValue]", Filters.element(), null, mods, mets, goobiNamespace);
    SAXBuilder builder = new SAXBuilder();
    Document doc;
    try {
        doc = builder.build(metadataFile.toString());
    } catch (JDOMException | IOException e1) {
        return;
    }
    for (Element meta : authorityMetaXpath.evaluate(doc)) {
        String name = meta.getAttributeValue("name");
        if (name == null) {
            continue;
        } else {
            String key = name + "_authority";
            List<String> values = metadataPairs.get(key);
            if (values == null) {
                values = new ArrayList<>();
                metadataPairs.put(key, values);
            }
            values.add(meta.getChildText("authorityValue", goobiNamespace));
        }
    }
}
Also used : XPathFactory(org.jdom2.xpath.XPathFactory) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) JsonElement(com.google.gson.JsonElement) IOException(java.io.IOException) Document(org.jdom2.Document) DigitalDocument(ugh.dl.DigitalDocument) JDOMException(org.jdom2.JDOMException)

Example 53 with Document

use of com.google.cloud.dialogflow.v2beta1.Document in project goobi-workflow by intranda.

the class PluginInstaller method parsePlugin.

private static PluginInstallInfo parsePlugin(Path pluginFolder) throws JDOMException, IOException {
    // TODO: error checking...
    Document pluginPomDocument = parsePomXml(pluginFolder, "pom.xml");
    String name = extractPluginName(pluginPomDocument, pluginFolder);
    String type = extractPluginTypeFromName(name);
    String pluginVersion = pluginVersionXpath.evaluateFirst(pluginPomDocument).getTextTrim();
    Element goobiVersionEle = goobiVersionXpath.evaluateFirst(pluginPomDocument);
    if (goobiVersionEle == null) {
        goobiVersionEle = secondGoobiVersionXpath.evaluateFirst(pluginPomDocument);
    }
    String goobiVersion = goobiVersionEle.getTextTrim();
    List<PluginVersion> versions = Collections.singletonList(new PluginVersion(null, null, goobiVersion, goobiVersion, pluginVersion));
    return new PluginInstallInfo(0, name, type, null, null, versions);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 54 with Document

use of com.google.cloud.dialogflow.v2beta1.Document in project goobi-workflow by intranda.

the class PluginInstaller method parsePomXml.

private static Document parsePomXml(Path pluginFolder, String pomFilePath) throws JDOMException, IOException {
    SAXBuilder saxBuilder = new SAXBuilder();
    Path pomPath = pluginFolder.resolve(pomFilePath);
    Document pluginPomDocument = saxBuilder.build(pomPath.toFile());
    return pluginPomDocument;
}
Also used : Path(java.nio.file.Path) SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 55 with Document

use of com.google.cloud.dialogflow.v2beta1.Document in project goobi-workflow by intranda.

the class XsltPreparatorDocket method startExport.

/**
 * This method exports the production metadata as xml to a given stream.
 *
 * @param process the process to export
 * @param os the OutputStream to write the contents to
 * @throws IOException
 * @throws ExportFileException
 */
@Override
public void startExport(Process process, OutputStream os, String xslt) throws IOException {
    try {
        Document doc = createDocument(process, true, true);
        XMLOutputter outp = new XMLOutputter();
        outp.setFormat(Format.getPrettyFormat());
        outp.output(doc, os);
        os.close();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) IOException(java.io.IOException) Document(org.jdom2.Document) JaxenException(org.jaxen.JaxenException) JDOMException(org.jdom2.JDOMException) DAOException(de.sub.goobi.helper.exceptions.DAOException) SwapException(de.sub.goobi.helper.exceptions.SwapException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) XSLTransformException(org.jdom2.transform.XSLTransformException) ExportFileException(de.sub.goobi.helper.exceptions.ExportFileException) IOException(java.io.IOException)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)342 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)57 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39