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);
}
}
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);
}
}
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);
}
}
}
}
}
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));
}
}
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());
}
Aggregations