> entry : EXPORT_FORMATS.entrySet()) {
Path path;
String checksum;
+
try {
path = Files.createTempFile(DiagramValidator.class.getSimpleName() + "-" + diagramId, "." + entry.getKey());
- ImageExporter.export(diagramPresentationElement, entry.getValue().getKey(), path.toFile());
+ if (entry.getValue().getKey() == ImageExporter.SVG) {
+ MDUtils.exportSVG(path.toFile(), diagramPresentationElement);
+ }
+ else {
+ ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, path.toFile(), false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT);
+ }
try (InputStream inputStream = new FileInputStream(path.toFile())) {
checksum = DigestUtils.md5Hex(inputStream);
}
- } catch (IOException e) {
+ } catch (IOException | TransformerException e) {
e.printStackTrace();
Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation for " + Converters.getElementToHumanNameConverter().apply(diagram) + ". Reason: " + e.getMessage());
break;
diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java
index 70522d6c9..5eea1ef1f 100644
--- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java
+++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java
@@ -23,21 +23,22 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.security.GeneralSecurityException;
/**
* SysML 2 Pilot Implementation
* Copyright (C) 2018 California Institute of Technology ("Caltech")
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
@@ -72,7 +73,7 @@ public void validate() {
try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) {
response = JacksonUtils.parseJsonObject(jsonParser);
}
- } catch (IOException | ServerException | URISyntaxException e) {
+ } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) {
errors = true;
e.printStackTrace();
Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS projects. Project validation aborted. Reason: " + e.getMessage());
diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java
index f0cae40bc..0de8fff73 100644
--- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java
+++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java
@@ -4,18 +4,26 @@
import com.nomagic.magicdraw.core.Project;
import com.nomagic.magicdraw.core.ProjectUtilities;
import com.nomagic.magicdraw.esi.EsiUtils;
+import com.nomagic.magicdraw.export.image.ImageExporter;
import com.nomagic.magicdraw.ui.browser.BrowserTabTree;
import com.nomagic.magicdraw.ui.browser.Node;
import com.nomagic.magicdraw.uml.BaseElement;
import com.nomagic.magicdraw.uml.symbols.DiagramPresentationElement;
import com.nomagic.magicdraw.uml.symbols.PresentationElement;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
+import gov.nasa.jpl.mbee.mdk.docgen.DocGenUtils;
+import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
+import org.apache.batik.util.XMLResourceDescriptor;
+import org.w3c.dom.Document;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import java.awt.event.ActionEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.io.*;
+import java.util.*;
/**
* A collection of utility functions for accessing the MagicDraw (MD)
@@ -23,6 +31,8 @@
*/
public class MDUtils {
+ public static String SVG_ENRICHED_EXPORT_PROPERTY_NAME = "svg.enriched.export";
+
/**
* @return true iff MD was started with the DEVELOPER option at the command
* line.
@@ -181,4 +191,30 @@ public static long getRemoteVersion(Project project) {
}
return Long.valueOf(ProjectUtilities.getVersion(project.getPrimaryProject()).getName());
}
+
+ public static void exportSVG(File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException {
+ String originalSvgEnrichedExportPropertyValue = System.getProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME);
+ System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX)));
+
+ try (InputStream svgInputStream = new FileInputStream(svgFile); Writer svgWriter = new FileWriter(svgFile)) {
+ ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT);
+ String parser = XMLResourceDescriptor.getXMLParserClassName();
+ SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
+ Document svg = f.createDocument(null, svgInputStream);
+ XMLUtil.asList(svg.getElementsByTagName("g")).stream()
+ .filter(g -> g instanceof org.w3c.dom.Element)
+ .map(g -> (org.w3c.dom.Element) g)
+ .filter(g -> Objects.equals(g.getAttribute("class"), "element"))
+ .forEach(g -> g.setAttribute("stroke-width", "0px"));
+ DOMSource source = new DOMSource(svg);
+ StreamResult result = new StreamResult(svgWriter);
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(source, result);
+ } finally {
+ System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, originalSvgEnrichedExportPropertyValue);
+ }
+ }
+
}
diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java
index da58dadb7..644031e9a 100644
--- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java
+++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java
@@ -19,6 +19,7 @@
import java.awt.event.HierarchyListener;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
@@ -52,7 +53,7 @@ public static boolean isTicketSet(Project project) {
return ticket != null && !ticket.isEmpty();
}
- public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException {
+ public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, GeneralSecurityException {
if (!isTicketSet(project)) {
return false;
}
@@ -243,7 +244,7 @@ private static boolean acquireTicket(Project project, String pass) {
String ticket;
try {
ticket = MMSUtils.getCredentialsTicket(project, username, pass, progressStatus);
- } catch (IOException | URISyntaxException | ServerException e) {
+ } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) {
Application.getInstance().getGUILog().log("[ERROR] An error occurred while acquiring credentials. Reason: " + e.getMessage());
e.printStackTrace();
return;
diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java
new file mode 100644
index 000000000..4b6979e56
--- /dev/null
+++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java
@@ -0,0 +1,31 @@
+package gov.nasa.jpl.mbee.mdk.util;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.AbstractList;
+import java.util.Collections;
+import java.util.List;
+import java.util.RandomAccess;
+
+public final class XMLUtil {
+ public static List asList(NodeList n) {
+ return n.getLength() == 0 ? Collections.emptyList() : new NodeListWrapper(n);
+ }
+
+ static final class NodeListWrapper extends AbstractList implements RandomAccess {
+ private final NodeList list;
+
+ NodeListWrapper(NodeList l) {
+ list = l;
+ }
+
+ public Node get(int index) {
+ return list.item(index);
+ }
+
+ public int size() {
+ return list.getLength();
+ }
+ }
+}
\ No newline at end of file