Search in sources :

Example 66 with Document

use of com.google.cloud.language.v1.Document in project archi by archimatetool.

the class JDOMUtilsTests method testReadXMLFile_File.

@Test
public void testReadXMLFile_File() throws Exception {
    File file = new File(TESTDATA_FOLDER, "imsmanifest.xml");
    Document doc = JDOMUtils.readXMLFile(file);
    assertNotNull(doc);
    assertTrue(doc.hasRootElement());
}
Also used : Document(org.jdom2.Document) File(java.io.File) Test(org.junit.Test)

Example 67 with Document

use of com.google.cloud.language.v1.Document in project archi by archimatetool.

the class SaveCanvasAsTemplateWizard method createManifest.

private String createManifest() throws IOException {
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);
    // Type
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE, CanvasModelTemplate.XML_CANVAS_TEMPLATE_ATTRIBUTE_TYPE_MODEL);
    // Timestamp
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP, Long.toString(System.currentTimeMillis()));
    // Name
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(fTemplateName);
    root.addContent(elementName);
    // Description
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(fTemplateDescription);
    root.addContent(elementDescription);
    // Thumbnail
    if (fIncludeThumbnail) {
        // $NON-NLS-1$
        String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + "1.png";
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        elementKeyThumb.setText(keyThumb);
        root.addContent(elementKeyThumb);
    }
    return JDOMUtils.write2XMLString(doc);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 68 with Document

use of com.google.cloud.language.v1.Document in project archi by archimatetool.

the class ArchimateTemplateManager method isValidTemplateFile.

@Override
protected boolean isValidTemplateFile(File file) throws IOException {
    if (file == null || !file.exists()) {
        return false;
    }
    // Ensure the template is of the right kind
    // $NON-NLS-1$
    String xmlString = ZipUtils.extractZipEntry(file, ZIP_ENTRY_MANIFEST, Charset.forName("UTF-8"));
    if (xmlString == null) {
        return false;
    }
    // If the attribute doesn't exist it was from an older version (before 2.1)
    try {
        Document doc = JDOMUtils.readXMLString(xmlString);
        Element root = doc.getRootElement();
        Attribute attType = root.getAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE);
        if (attType != null) {
            return ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL.equals(attType.getValue());
        }
    } catch (JDOMException ex) {
        return false;
    }
    return true;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 69 with Document

use of com.google.cloud.language.v1.Document in project archi by archimatetool.

the class SaveArchimateModelAsTemplateWizard method createManifest.

private String createManifest() throws IOException {
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);
    // Type
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE, ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL);
    // Timestamp
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP, Long.toString(System.currentTimeMillis()));
    // Name
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(fTemplateName);
    root.addContent(elementName);
    // Description
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(fTemplateDescription);
    root.addContent(elementDescription);
    // Key thumbnail
    if (fIncludeThumbnails) {
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        // $NON-NLS-1$
        elementKeyThumb.setText(TemplateManager.ZIP_ENTRY_THUMBNAILS + "1.png");
        root.addContent(elementKeyThumb);
    }
    return JDOMUtils.write2XMLString(doc);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 70 with Document

use of com.google.cloud.language.v1.Document in project archi by archimatetool.

the class AbstractTemplate method save.

@Override
public void save() throws IOException {
    if (fFile == null || !fFile.exists()) {
        return;
    }
    // Create Manifest as JDOM
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(getName());
    root.addContent(elementName);
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(getDescription());
    root.addContent(elementDescription);
    if (fKeyThumbnailPath != null) {
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        elementKeyThumb.setText(fKeyThumbnailPath);
        root.addContent(elementKeyThumb);
    }
    // Open a zip stream
    File tmpFile = File.createTempFile("architemplate", null);
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpFile));
    ZipOutputStream zOut = new ZipOutputStream(out);
    // Add Manifest
    String manifest = JDOMUtils.write2XMLString(doc);
    ZipUtils.addStringToZip(manifest, TemplateManager.ZIP_ENTRY_MANIFEST, zOut, Charset.forName("UTF-8"));
    // Add Model
    // Save to temporary file rather than string because the actual encoding can either be ANSI or UTF-8 depending on content
    File modelFile = ZipUtils.extractZipEntry(fFile, TemplateManager.ZIP_ENTRY_MODEL, File.createTempFile("archi", null));
    ZipUtils.addFileToZip(modelFile, TemplateManager.ZIP_ENTRY_MODEL, zOut);
    modelFile.delete();
    // Thumbnails
    for (int i = 0; i < getThumbnailCount(); i++) {
        Image image = getThumbnail(i);
        if (image != null) {
            ZipUtils.addImageToZip(image, getThumbnailEntryName(i), zOut, SWT.IMAGE_PNG, null);
        }
    }
    zOut.flush();
    zOut.close();
    // Delete and copy
    fFile.delete();
    FileUtils.copyFile(tmpFile, fFile, false);
    tmpFile.delete();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Element(org.jdom2.Element) FileOutputStream(java.io.FileOutputStream) Document(org.jdom2.Document) Image(org.eclipse.swt.graphics.Image) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

Document (org.jdom2.Document)402 Element (org.jdom2.Element)249 Test (org.junit.Test)108 SAXBuilder (org.jdom2.input.SAXBuilder)94 IOException (java.io.IOException)73 File (java.io.File)57 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 ArrayList (java.util.ArrayList)24 DocType (org.jdom2.DocType)24 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 Document (com.google.cloud.language.v1.Document)21 MCRException (org.mycore.common.MCRException)21 HashMap (java.util.HashMap)20 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 InputStream (java.io.InputStream)18