Search in sources :

Example 61 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class XsltPreparatorMetadata method startExport.

/**
 * This method exports the production metadata for a list of processes as a single file to a given stream.
 *
 * @param processList
 * @param outputStream
 * @param xslt
 */
public void startExport(List<Process> processList, OutputStream outputStream, String xslt) {
    Document answer = new Document();
    Element root = new Element("processes");
    answer.setRootElement(root);
    Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile");
    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.addNamespaceDeclaration(xsi);
    root.setNamespace(xmlns);
    Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd", xsi);
    root.setAttribute(attSchema);
    for (Process p : processList) {
        Document doc = createDocument(p, false);
        Element processRoot = doc.getRootElement();
        processRoot.detach();
        root.addContent(processRoot);
    }
    XMLOutputter outp = new XMLOutputter();
    outp.setFormat(Format.getPrettyFormat());
    try {
        outp.output(answer, outputStream);
    } catch (IOException e) {
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                outputStream = null;
            }
        }
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Process(org.goobi.beans.Process) IOException(java.io.IOException) Document(org.jdom2.Document) DigitalDocument(ugh.dl.DigitalDocument) Namespace(org.jdom2.Namespace)

Example 62 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class XsltPreparatorMetadata method startExport.

/**
 * This method exports the METS 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 {
        this.prefs = process.getRegelsatz().getPreferences();
        Fileformat ff = process.readMetadataFile();
        DigitalDocument document = ff.getDigitalDocument();
        this.metahelper = new MetadatenHelper(prefs, document);
        Document doc = createDocument(process, 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) MetadatenHelper(de.sub.goobi.metadaten.MetadatenHelper) Fileformat(ugh.dl.Fileformat) IOException(java.io.IOException) DigitalDocument(ugh.dl.DigitalDocument) Document(org.jdom2.Document) DigitalDocument(ugh.dl.DigitalDocument) ExportFileException(de.sub.goobi.helper.exceptions.ExportFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 63 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class GeneratePdfFromXsltTest method testXmlLog.

@Test
public void testXmlLog() throws Exception {
    XsltPreparatorDocket xmlExport = new XsltPreparatorDocket();
    assertNotNull(xmlExport);
    File fixture = folder.newFile("log.xml");
    xmlExport.startExport(process, fixture.toPath());
    assertNotNull(fixture);
    SAXBuilder saxBuilder = new SAXBuilder();
    Document document = saxBuilder.build(fixture);
    Element root = document.getRootElement();
    assertEquals("process", root.getName());
    assertEquals(root.getAttributeValue("processID"), "1");
    Element title = root.getChild("title", xmlns);
    assertEquals("testprocess", title.getValue());
    Element properties = root.getChild("properties", xmlns);
    Element prop = properties.getChildren().get(0);
    assertEquals("Test1", prop.getAttributeValue("propertyIdentifier"));
    assertEquals("1", prop.getAttributeValue("value"));
    Element steps = root.getChild("steps", xmlns);
    Element step = steps.getChildren().get(0);
    assertEquals("title", step.getChildText("title", xmlns));
    assertEquals("1", step.getChildText("processingstatus", xmlns));
    Element metadatalist = root.getChild("metadatalist", xmlns);
    Element metadata = metadatalist.getChildren().get(0);
    assertEquals("title", metadata.getAttributeValue("name"));
    assertEquals("value", metadata.getValue());
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ConfigProjectsTest(de.sub.goobi.config.ConfigProjectsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) AbstractTest(de.sub.goobi.AbstractTest) Test(org.junit.Test)

Example 64 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project j-Ecdar by Ecdar.

the class SimpleTransitionSystem method toJson.

public void toJson(String filename) {
    // String file =" <?xml version="1.0" encoding="utf-8"?><!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'><nta><declaration>// Place global declarations here."
    Element nta = new Element("nta");
    Document doc = new Document();
    Element declaration = new Element("declaration");
    nta.addContent(declaration);
    String decString = "";
    for (Channel c : getInputs()) decString += "broadcast chan " + c.getName() + "; ";
    for (Channel c : getOutputs()) decString += "broadcast chan " + c.getName() + "; ";
    declaration.addContent(decString);
    Element aut = new Element("template");
    Element name = new Element("name");
    name.addContent(getName());
    aut.addContent(name);
    Element localDeclaration = new Element("declaration");
    aut.addContent(localDeclaration);
    String localDecString = "";
    for (Clock c : getClocks()) {
        localDecString += "clock " + c.getName() + "; ";
    }
    localDeclaration.addContent(localDecString);
    for (Location l : automaton.getLocations()) {
        Element loc = new Element("location");
        Element locname = new Element("name");
        locname.addContent(l.getName());
        loc.addContent(locname);
        loc.setAttribute("id", l.getName());
        loc.setAttribute("x", String.valueOf(l.getX()));
        loc.setAttribute("y", String.valueOf(l.getY()));
        Element invarLabel = new Element("label");
        invarLabel.setAttribute("kind", "invariant");
        String guardString = "";
        int j = 0;
        for (List<Guard> list : l.getInvariant()) {
            int i = 0;
            String inner = "";
            for (Guard g : list) {
                // System.out.println(g);
                String interm = "";
                String lower = "";
                String upper = "";
                if (g.isStrict()) {
                    lower = g.getClock().getName() + ">" + g.getLowerBound();
                    upper = g.getClock().getName() + "<" + g.getUpperBound();
                } else {
                    lower = g.getClock().getName() + ">=" + g.getLowerBound();
                    upper = g.getClock().getName() + "<=" + g.getUpperBound();
                }
                if (g.getLowerBound() != 0)
                    if (interm.isEmpty())
                        interm += lower;
                    else
                        interm += " && " + lower;
                if (g.getUpperBound() != 2147483647)
                    if (interm.isEmpty())
                        interm += upper;
                    else
                        interm += " && " + upper;
                if (i == 0)
                    inner += interm;
                else
                    inner += " && " + interm;
                if (!inner.isEmpty())
                    i++;
            }
            if (j == 0)
                guardString += inner;
            else
                guardString += " || " + inner;
            if (!guardString.isEmpty())
                j++;
        }
        invarLabel.addContent(guardString);
        if (l.isInconsistent())
            loc.setAttribute("color", "#A66C0F");
        loc.addContent(invarLabel);
        aut.addContent(loc);
    }
    Element init = new Element("init");
    init.setAttribute("ref", automaton.getInitLoc().getName());
    aut.addContent(init);
    for (Edge e : automaton.getEdges()) {
        Element edge = new Element("transition");
        if (getInputs().contains(e.getChannel()))
            edge.setAttribute("controllable", "true");
        else
            edge.setAttribute("controllable", "false");
        Element source = new Element("source");
        source.setAttribute("ref", e.getSource().getName());
        edge.addContent(source);
        Element target = new Element("target");
        target.setAttribute("ref", e.getTarget().getName());
        edge.addContent(target);
        Element synchlabel = new Element("label");
        synchlabel.setAttribute("kind", "synchronisation");
        if (getInputs().contains(e.getChannel()))
            synchlabel.addContent(e.getChannel().getName() + "?");
        else
            synchlabel.addContent(e.getChannel().getName() + "!");
        edge.addContent(synchlabel);
        Element guardlabel = new Element("label");
        guardlabel.setAttribute("kind", "guard");
        String guardString = "";
        int i = 0;
        int j = 0;
        for (List<Guard> disjunction : e.getGuards()) {
            if (j != 0)
                guardString = guardString + " or ";
            i = 0;
            for (Guard g : disjunction) {
                // System.out.println(g);
                String interm = "";
                String lower = "";
                String upper = "";
                if (g.isStrict()) {
                    lower = g.getClock().getName() + ">" + g.getLowerBound();
                    upper = g.getClock().getName() + "<" + g.getUpperBound();
                } else {
                    lower = g.getClock().getName() + ">=" + g.getLowerBound();
                    upper = g.getClock().getName() + "<=" + g.getUpperBound();
                }
                if (g.getLowerBound() != 0)
                    if (interm.isEmpty())
                        interm += lower;
                    else
                        interm += " && " + lower;
                if (g.getUpperBound() != 2147483647)
                    if (interm.isEmpty())
                        interm += upper;
                    else
                        interm += " && " + upper;
                if (i == 0)
                    guardString += interm;
                else
                    guardString += " && " + interm;
                if (!guardString.isEmpty())
                    i++;
            }
            j++;
        }
        guardlabel.addContent(guardString);
        edge.addContent(guardlabel);
        Element updatelabel = new Element("label");
        updatelabel.setAttribute("kind", "assignment");
        String updateString = "";
        i = 0;
        for (Update u : e.getUpdates()) {
            if (i == 0) {
                updateString += u.getClock().getName();
                updateString += " = " + u.getValue();
            } else
                updateString += ", " + u.getClock().getName() + " = " + u.getValue();
            i++;
        }
        updatelabel.addContent(updateString);
        edge.addContent(updatelabel);
        aut.addContent(edge);
    }
    nta.addContent(aut);
    Element sys = new Element("system");
    sys.addContent("system " + getName() + ";");
    nta.addContent(sys);
    doc.setRootElement(nta);
    XMLOutputter outter = new XMLOutputter();
    outter.setFormat(Format.getPrettyFormat());
    try {
        outter.output(doc, new FileWriter(new File(filename)));
    } catch (IOException e) {
        e.printStackTrace();
    }
// automaton.
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Document(org.jdom2.Document) File(java.io.File)

Example 65 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class GoobiScriptExportDatabaseInformation method execute.

@Override
public void execute(GoobiScriptResult gsr) {
    Process p = ProcessManager.getProcessById(gsr.getProcessId());
    try {
        gsr.setProcessTitle(p.getTitel());
        gsr.setResultType(GoobiScriptResultType.RUNNING);
        gsr.updateTimestamp();
        Path dest = null;
        try {
            dest = Paths.get(p.getProcessDataDirectoryIgnoreSwapping(), p.getId() + "_db_export.xml");
        } catch (IOException | InterruptedException | SwapException | DAOException e) {
            log.error(e);
            gsr.setResultMessage("Cannot read process folder " + e.getMessage());
            gsr.setResultType(GoobiScriptResultType.ERROR);
        }
        OutputStream os = null;
        try {
            os = Files.newOutputStream(dest);
        } catch (IOException e) {
            log.error(e);
            gsr.setResultMessage("Cannot write into export file " + e.getMessage());
            gsr.setResultType(GoobiScriptResultType.ERROR);
        }
        try {
            Document doc = new XsltPreparatorDocket().createExtendedDocument(p);
            XMLOutputter outp = new XMLOutputter();
            outp.setFormat(Format.getPrettyFormat());
            outp.output(doc, os);
        } catch (IOException e) {
            log.error(e);
            gsr.setResultMessage("Cannot write into export file " + e.getMessage());
            gsr.setResultType(GoobiScriptResultType.ERROR);
        } finally {
            if (os != null) {
                os.close();
            }
        }
        if (gsr.getResultType() != GoobiScriptResultType.ERROR) {
            gsr.setResultMessage("Export done successfully");
            gsr.setResultType(GoobiScriptResultType.OK);
        }
    } catch (NoSuchMethodError | Exception e) {
        gsr.setResultMessage(e.getMessage());
        gsr.setResultType(GoobiScriptResultType.ERROR);
        gsr.setErrorText(e.getMessage());
        log.error("Exception during the export of database information for id " + p.getId(), e);
    }
    gsr.updateTimestamp();
}
Also used : Path(java.nio.file.Path) XMLOutputter(org.jdom2.output.XMLOutputter) SwapException(de.sub.goobi.helper.exceptions.SwapException) OutputStream(java.io.OutputStream) Process(org.goobi.beans.Process) IOException(java.io.IOException) Document(org.jdom2.Document) DAOException(de.sub.goobi.helper.exceptions.DAOException) SwapException(de.sub.goobi.helper.exceptions.SwapException) IOException(java.io.IOException) DAOException(de.sub.goobi.helper.exceptions.DAOException) XsltPreparatorDocket(io.goobi.workflow.xslt.XsltPreparatorDocket)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 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