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