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