Search in sources :

Example 91 with Document

use of com.google.cloud.documentai.v1beta2.Document in project ddf by codice.

the class KmlFeatureToJtsGeometryConverterTest method testConvertKmlDocumentFeature.

@Test
public void testConvertKmlDocumentFeature() {
    InputStream stream = KmlFeatureToJtsGeometryConverterTest.class.getResourceAsStream("/kmlDocument.kml");
    Kml kml = Kml.unmarshal(stream);
    assertThat(kml, notNullValue());
    Document kmlDocument = ((Document) kml.getFeature());
    assertThat(kmlDocument, notNullValue());
    Geometry jtsGeometry = KmlFeatureToJtsGeometryConverter.from(kmlDocument);
    assertThat(jtsGeometry, notNullValue());
    assertFeature(kmlDocument, jtsGeometry);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) InputStream(java.io.InputStream) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Document(de.micromata.opengis.kml.v_2_2_0.Document) Test(org.junit.Test)

Example 92 with Document

use of com.google.cloud.documentai.v1beta2.Document in project jPOS by jpos.

the class Q2 method encrypt.

protected Document encrypt(Document doc) throws GeneralSecurityException, IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(os);
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(doc, writer);
    writer.close();
    byte[] crypt = dodes(os.toByteArray(), Cipher.ENCRYPT_MODE);
    Document secureDoc = new Document();
    Element root = new Element(PROTECTED_QBEAN);
    secureDoc.setRootElement(root);
    Element secureData = new Element("data");
    root.addContent(secureData);
    secureData.setText(ISOUtil.hexString(crypt));
    return secureDoc;
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 93 with Document

use of com.google.cloud.documentai.v1beta2.Document in project jPOS by jpos.

the class Q2 method deployResource.

private void deployResource(String resource) throws IOException, SAXException, JDOMException, GeneralSecurityException, ISOException {
    SAXBuilder builder = new SAXBuilder();
    try (InputStream source = getClass().getClassLoader().getResourceAsStream(resource)) {
        Document doc = builder.build(source);
        deployElement(doc.getRootElement(), resource.substring(DEPLOY_PREFIX.length()), false, true);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 94 with Document

use of com.google.cloud.documentai.v1beta2.Document in project jPOS by jpos.

the class Q2 method deployBundle.

private void deployBundle(File bundle, boolean encrypt) throws JDOMException, IOException, ISOException, GeneralSecurityException {
    SAXBuilder builder = createSAXBuilder();
    Document doc = builder.build(bundle);
    Iterator iter = doc.getRootElement().getChildren().iterator();
    for (int i = 1; iter.hasNext(); i++) {
        Element e = (Element) iter.next();
        deployElement(e, String.format("%02d_%s.xml", i, e.getName()), encrypt, !encrypt);
    // the !encrypt above is tricky and deserves an explanation
    // if we are encrypting a QBean, we want it to stay in the deploy
    // directory for future runs. If on the other hand we are deploying
    // a bundle, we want it to be transient.
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 95 with Document

use of com.google.cloud.documentai.v1beta2.Document in project jPOS by jpos.

the class Q2 method deployElement.

public void deployElement(Element e, String fileName, boolean encrypt, boolean isTransient) throws ISOException, IOException, GeneralSecurityException {
    e = e.clone();
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    Document doc = new Document();
    doc.setRootElement(e);
    File qbean = new File(deployDir, fileName);
    if (isTransient) {
        e.setAttribute("instance", getInstanceId().toString());
        qbean.deleteOnExit();
    }
    if (encrypt) {
        doc = encrypt(doc);
    }
    try (Writer writer = new BufferedWriter(new FileWriter(qbean))) {
        out.output(doc, writer);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)559 Element (org.jdom2.Element)330 Test (org.junit.Test)170 SAXBuilder (org.jdom2.input.SAXBuilder)160 IOException (java.io.IOException)146 JDOMException (org.jdom2.JDOMException)94 File (java.io.File)84 XMLOutputter (org.jdom2.output.XMLOutputter)80 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)34 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)32 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)31 MCRContent (org.mycore.common.content.MCRContent)30 MCRObject (org.mycore.datamodel.metadata.MCRObject)30 MCRException (org.mycore.common.MCRException)28 InputStream (java.io.InputStream)27 StringReader (java.io.StringReader)26 Path (java.nio.file.Path)26 URL (java.net.URL)24