Search in sources :

Example 61 with Document

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

the class XMLModelExporter method exportModel.

public void exportModel(IArchimateModel model, File outputFile) throws IOException {
    fModel = model;
    // JDOM Document
    Document doc = createDocument();
    // Root Element
    Element rootElement = createRootElement(doc);
    // Persist model
    writeModel(rootElement);
    // Save
    JDOMUtils.write2XMLFile(doc, outputFile);
    // XSD
    if (fIncludeXSD) {
        File file1 = new File(outputFile.getParentFile(), XMLExchangePlugin.ARCHIMATE3_MODEL_XSD);
        XMLExchangePlugin.INSTANCE.copyXSDFile(XMLExchangePlugin.ARCHIMATE3_MODEL_XSD, file1);
        File file2 = new File(outputFile.getParentFile(), XMLExchangePlugin.ARCHIMATE3_VIEW_XSD);
        XMLExchangePlugin.INSTANCE.copyXSDFile(XMLExchangePlugin.ARCHIMATE3_VIEW_XSD, file2);
        File file3 = new File(outputFile.getParentFile(), XMLExchangePlugin.ARCHIMATE3_DIAGRAM_XSD);
        XMLExchangePlugin.INSTANCE.copyXSDFile(XMLExchangePlugin.ARCHIMATE3_DIAGRAM_XSD, file3);
    }
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File)

Example 62 with Document

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

the class ViewpointManager method loadDefaultViewpointsFile.

/**
 * Load viewpoints from XML file
 */
void loadDefaultViewpointsFile() throws IOException, JDOMException {
    // Load localised file from bundle
    // $NON-NLS-1$
    URL url = FileLocator.find(Platform.getBundle(BUNDLE_ID), new Path("$nl$/" + VIEWPOINTS_FILE));
    url = FileLocator.resolve(url);
    Document doc = new SAXBuilder().build(url);
    Element rootElement = doc.getRootElement();
    for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String id = xmlViewpoint.getAttributeValue("id");
        if (id == null || "".equals(id)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            System.err.println("Blank id for viewpoint");
            continue;
        }
        // $NON-NLS-1$
        Element xmlName = xmlViewpoint.getChild("name");
        if (xmlName == null) {
            // $NON-NLS-1$
            System.err.println("No name element for viewpoint");
            continue;
        }
        String name = xmlName.getText();
        if (name == null || "".equals(name)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            System.err.println("Blank name for viewpoint");
            continue;
        }
        Viewpoint vp = new Viewpoint(id, name);
        for (Element xmlConcept : xmlViewpoint.getChildren("concept")) {
            // $NON-NLS-1$
            String conceptName = xmlConcept.getText();
            if (conceptName == null || "".equals(conceptName)) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                System.err.println("Blank concept name for viewpoint");
                continue;
            }
            if (ELEMENTS_MAP.containsKey(conceptName)) {
                addCollection(vp, conceptName);
            } else {
                EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName);
                if (eClass != null) {
                    addConcept(vp, eClass);
                } else {
                    // $NON-NLS-1$
                    System.err.println("Couldn't get eClass: " + conceptName);
                }
            }
        }
        VIEWPOINTS.put(id, vp);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) SAXBuilder(org.jdom2.input.SAXBuilder) EClass(org.eclipse.emf.ecore.EClass) Element(org.jdom2.Element) Document(org.jdom2.Document) URL(java.net.URL)

Example 63 with Document

use of com.google.cloud.language.v1.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 64 with Document

use of com.google.cloud.language.v1.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)

Example 65 with Document

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

the class JDOMUtilsTests method testWrite2XMLFile.

@Test
public void testWrite2XMLFile() throws Exception {
    File tmpFile = TestUtils.createTempFile(".xml");
    Document doc = createDocument();
    JDOMUtils.write2XMLFile(doc, tmpFile);
    assertTrue(tmpFile.exists());
}
Also used : Document(org.jdom2.Document) File(java.io.File) Test(org.junit.Test)

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