Search in sources :

Example 16 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.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
    String xmlString = ZipUtils.extractZipEntry(file, ZIP_ENTRY_MANIFEST);
    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 17 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.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);
    // Thumbnails
    if (fIncludeThumbnails) {
        if (fSelectedDiagramModel != null) {
            int i = 1;
            for (IDiagramModel dm : fModel.getDiagramModels()) {
                if (dm == fSelectedDiagramModel) {
                    // $NON-NLS-1$
                    String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + i + ".png";
                    Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
                    elementKeyThumb.setText(keyThumb);
                    root.addContent(elementKeyThumb);
                    break;
                }
                i++;
            }
        }
    }
    return JDOMUtils.write2XMLString(doc);
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 18 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project archi by archimatetool.

the class AbstractTemplate method save.

@Override
public void save() throws IOException {
    if (fFile == null || !fFile.exists()) {
        return;
    }
    // Manifest
    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);
    }
    String manifest = JDOMUtils.write2XMLString(doc);
    // Model
    String model = ZipUtils.extractZipEntry(fFile, TemplateManager.ZIP_ENTRY_MODEL);
    // Start a zip stream
    // $NON-NLS-1$
    File tmpFile = File.createTempFile("architemplate", null);
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpFile));
    ZipOutputStream zOut = new ZipOutputStream(out);
    ZipUtils.addStringToZip(manifest, TemplateManager.ZIP_ENTRY_MANIFEST, zOut);
    ZipUtils.addStringToZip(model, TemplateManager.ZIP_ENTRY_MODEL, zOut);
    // Thumbnails
    Image[] images = getThumbnails();
    int i = 1;
    for (Image image : images) {
        // $NON-NLS-1$
        ZipUtils.addImageToZip(image, TemplateManager.ZIP_ENTRY_THUMBNAILS + i++ + ".png", 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)

Example 19 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project archi by archimatetool.

the class RelationshipsMatrix method loadRelationships.

private void loadRelationships() {
    // URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_FILE);
    URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_FILE);
    // Load the JDOM Document from XML
    Document doc = null;
    try {
        doc = new SAXBuilder().build(url);
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }
    // Iterate through all "source" concepts
    for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_SOURCE)) {
        Element elementSource = (Element) object;
        // Source concept name
        String sourceName = elementSource.getAttributeValue(XML_ATTRIBUTE_CONCEPT);
        if (sourceName == null) {
            continue;
        }
        // Get EClass source from mapping
        EClass source = null;
        // Use "Relationship" as a generic super type
        if (sourceName.equals("Relationship")) {
            // $NON-NLS-1$
            source = IArchimatePackage.eINSTANCE.getArchimateRelationship();
        } else // Else use given class
        {
            source = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(sourceName);
        }
        if (source == null) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Couldn't find source " + sourceName);
            continue;
        }
        // Create a new list of type TargetMatrix
        List<TargetMatrix> matrixList = new ArrayList<TargetMatrix>();
        // Put it in the main matrix map
        matrixMap.put(source, matrixList);
        // Iterate through all child "target" concepts
        for (Object objectChild : elementSource.getChildren(XML_ELEMENT_TARGET)) {
            Element elementTarget = (Element) objectChild;
            // Target concept name
            String targetName = elementTarget.getAttributeValue(XML_ATTRIBUTE_CONCEPT);
            if (targetName == null) {
                continue;
            }
            EClass target = null;
            // Use "Relationship" as a generic super type
            if (targetName.equals("Relationship")) {
                // $NON-NLS-1$
                target = IArchimatePackage.eINSTANCE.getArchimateRelationship();
            } else // Else use given class
            {
                target = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(targetName);
            }
            if (target == null) {
                // $NON-NLS-1$
                System.err.println(getClass() + ": Couldn't find target " + targetName);
                continue;
            }
            // Create a new TargetMatrix and add it to the list
            TargetMatrix matrix = new TargetMatrix();
            matrixList.add(matrix);
            // Set target class
            matrix.targetClass = target;
            // Get relations string
            String relations = elementTarget.getAttributeValue(XML_ATTRIBUTE_RELATIONS);
            if (relations == null) {
                continue;
            }
            // Take each character and add the relationship from the mapping
            for (int i = 0; i < relations.length(); i++) {
                char key = relations.charAt(i);
                EClass relationship = relationsKeyMap.get(key);
                if (relationship != null) {
                    matrix.getRelationships().add(relationship);
                } else {
                    // $NON-NLS-1$
                    System.err.println(getClass() + ": Found unmapped key char: " + key);
                }
            }
        }
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) URL(java.net.URL) EClass(org.eclipse.emf.ecore.EClass)

Example 20 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project archi by archimatetool.

the class RelationshipsMatrix method loadKeyLetters.

private void loadKeyLetters() {
    // URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_KEYS_FILE);
    URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_KEYS_FILE);
    // Load the JDOM Document from XML
    Document doc = null;
    try {
        doc = new SAXBuilder().build(url);
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }
    for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_KEY)) {
        Element elementKey = (Element) object;
        String keyLetter = elementKey.getAttributeValue(XML_ATTRIBUTE_CHAR);
        if (keyLetter == null || keyLetter.length() != 1) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Key letter incorrect: " + keyLetter);
            continue;
        }
        String relationName = elementKey.getAttributeValue(XML_ATTRIBUTE_RELATIONSHIP);
        if (relationName == null) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Relationship name incorrect: " + relationName);
            continue;
        }
        EClass relationship = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(relationName);
        if (relationship == null) {
            // $NON-NLS-1$
            System.err.println(getClass() + ": Couldn't find relationship " + relationName);
            continue;
        }
        relationsKeyMap.put(keyLetter.charAt(0), relationship);
        relationsValueMap.put(relationship, keyLetter.charAt(0));
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) EClass(org.eclipse.emf.ecore.EClass) Element(org.jdom2.Element) Document(org.jdom2.Document) URL(java.net.URL)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18