Search in sources :

Example 61 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.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 62 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.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 63 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.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)

Example 64 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.Document in project goobi-workflow by intranda.

the class MetadataUtils method extractMetadataFromFile.

private static void extractMetadataFromFile(Path metsPath, RestProcess p, Map<String, Map<String, String>> labelMap, SearchRequest req) {
    if (!Files.exists(metsPath)) {
        return;
    }
    Document doc;
    try (InputStream in = Files.newInputStream(metsPath)) {
        doc = builder.build(in);
    } catch (JDOMException | IOException e) {
        log.error(e);
        return;
    }
    for (Element el : authorityMetaXpath.evaluate(doc)) {
        RestMetadata meta = new RestMetadata();
        String name = el.getAttributeValue("name");
        if (req.getWantedFields() != null && !req.getWantedFields().contains(name)) {
            continue;
        }
        String type = el.getAttributeValue("type");
        if ("person".equals(type)) {
            meta.setValue(el.getChildText("displayName", goobiNamespace));
        } else {
            meta.setValue(el.getText());
        }
        meta.setAuthorityID(el.getChildText("authorityID", goobiNamespace));
        meta.setAuthorityURI(el.getChildText("authorityURI", goobiNamespace));
        meta.setAuthorityValue(el.getChildText("authorityValue", goobiNamespace));
        meta.setLabels(labelMap.get(name));
        p.addMetadata(name, meta);
    }
}
Also used : InputStream(java.io.InputStream) Element(org.jdom2.Element) RestMetadata(org.goobi.api.rest.model.RestMetadata) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 65 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.Document in project goobi-workflow by intranda.

the class SRUClient method getResponseObject.

/**
 * <p>
 * Parse an XML String response and populate a response Object.
 * </p>
 *
 * @param xmlData The XML String returned from the search
 * @return SRUResponse An instantiated response object
 */
public SRUResponse getResponseObject(String xmlData) {
    // Parsing
    Document xmlResponse = parseXml(xmlData);
    if (xmlResponse == null) {
        log.error("Can't get results after XML parsing failed.");
        return null;
    }
    // Processing
    SRUResponse response = null;
    try {
        response = new SRUResponse(xmlResponse);
    } catch (JDOMException ex) {
        log.error("Error processing XML response:", ex);
    }
    return response;
}
Also used : Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

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