diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/freemind/FreemindExporter.java b/wise-webapp/src/main/java/com/wisemapping/exporter/freemind/FreemindExporter.java index 45bed69a..f1aebd1b 100755 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/freemind/FreemindExporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/freemind/FreemindExporter.java @@ -42,10 +42,11 @@ public class FreemindExporter implements Exporter { private static final String FREE_MIND_VERSION = "0.9.0"; - private static final String EMPTY_FONT_STYLE = ";;;;;"; private static final String POSITION_LEFT = "left"; private static final String POSITION_RIGHT = "right"; - private com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory; + private com.wisemapping.xml.freemind.ObjectFactory objectFactory; + private static final String EMPTY_FONT_STYLE = ";;;;;"; + private Map nodesMap = null; public void export(MindMap map, OutputStream outputStream) throws ExportException { @@ -58,7 +59,7 @@ public class FreemindExporter public void export(byte[] xml, OutputStream outputStream) throws ExportException { - freemindObjectFactory = new com.wisemapping.xml.freemind.ObjectFactory(); + objectFactory = new com.wisemapping.xml.freemind.ObjectFactory(); nodesMap = new HashMap(); final com.wisemapping.xml.mindmap.Map mindmapMap; @@ -66,7 +67,7 @@ public class FreemindExporter final ByteArrayInputStream stream = new ByteArrayInputStream(xml); mindmapMap = (com.wisemapping.xml.mindmap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.xml.mindmap"); - final com.wisemapping.xml.freemind.Map freemindMap = freemindObjectFactory.createMap(); + final com.wisemapping.xml.freemind.Map freemindMap = objectFactory.createMap(); freemindMap.setVersion(FREE_MIND_VERSION); @@ -85,7 +86,7 @@ public class FreemindExporter centerTopic = topics.get(0); } - final Node main = freemindObjectFactory.createNode(); + final Node main = objectFactory.createNode(); freemindMap.setNode(main); if (centerTopic != null) { nodesMap.put(centerTopic.getId(), main); @@ -95,7 +96,7 @@ public class FreemindExporter List relationships = mindmapMap.getRelationship(); for (RelationshipType relationship : relationships) { Node srcNode = nodesMap.get(relationship.getSrcTopicId()); - Arrowlink arrowlink = freemindObjectFactory.createArrowlink(); + Arrowlink arrowlink = objectFactory.createArrowlink(); Node dstNode = nodesMap.get(relationship.getDestTopicId()); arrowlink.setDESTINATION(dstNode.getID()); if (relationship.isEndArrow()) @@ -116,7 +117,7 @@ public class FreemindExporter final List currentTopic = mainTopic.getTopic(); for (TopicType topicType : currentTopic) { - final Node newNode = freemindObjectFactory.createNode(); + final Node newNode = objectFactory.createNode(); nodesMap.put(topicType.getId(), newNode); setTopicPropertiesToNode(newNode, topicType); destNode.getArrowlinkOrCloudOrEdge().add(newNode); @@ -188,7 +189,7 @@ public class FreemindExporter private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { if (mindmapTopic.getBrColor() != null) { - final Edge edgeNode = freemindObjectFactory.createEdge(); + final Edge edgeNode = objectFactory.createEdge(); edgeNode.setCOLOR(mindmapTopic.getBrColor()); freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode); } @@ -199,20 +200,21 @@ public class FreemindExporter * eg: Verdana;10;#ffffff;bold;italic; * */ - private void addFontNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { + private void addFontNode(@NotNull com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { final String fontStyle = mindmapTopic.getFontStyle(); if (fontStyle != null && fontStyle.length() != 0) { - final Font font = freemindObjectFactory.createFont(); + final Font font = objectFactory.createFont(); final String[] part = fontStyle.split(";", 6); int countParts = part.length; + boolean updated = false; if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) { - - int idx = 0; + // Font name if (idx < countParts && part[idx].length() != 0) { font.setNAME(part[idx]); + updated = true; } idx++; @@ -220,6 +222,7 @@ public class FreemindExporter if (idx < countParts && part[idx].length() != 0) { String size = part[idx]; font.setSIZE(new BigInteger(size)); + updated = true; } idx++; @@ -232,15 +235,18 @@ public class FreemindExporter // Font Styles if (idx < countParts && part[idx].length() != 0) { font.setBOLD(Boolean.TRUE.toString()); + updated = true; } idx++; if (idx < countParts && part[idx].length() != 0) { font.setITALIC(Boolean.TRUE.toString()); + updated = true; } - - freemindNode.getArrowlinkOrCloudOrEdge().add(font); + if (updated) { + freemindNode.getArrowlinkOrCloudOrEdge().add(font); + } } } } diff --git a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java index b3ef0a18..126c73af 100755 --- a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java @@ -32,6 +32,7 @@ import com.wisemapping.xml.mindmap.RelationshipType; import com.wisemapping.xml.mindmap.TopicType; import com.wisemapping.xml.mindmap.Link; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.*; import javax.xml.bind.JAXBException; @@ -52,6 +53,8 @@ public class FreemindImporter private static final String EMPTY_NOTE = ""; private java.util.Map nodesMap = null; private List relationships = null; + private static final String EMPTY_FONT_STYLE = ";;;;;"; + private int currentId; public MindMap importMap(String mapName, String description, InputStream input) throws ImporterException { @@ -259,7 +262,7 @@ public class FreemindImporter } else if (freemindNode instanceof Font) { final Font font = (Font) freemindNode; final String fontStyle = generateFontStyle(mainNode, font); - if (!fontStyle.isEmpty()) { + if (fontStyle!=null) { currentTopic.setFontStyle(fontStyle); } } else if (freemindNode instanceof Edge) { @@ -391,8 +394,8 @@ public class FreemindImporter int position = pos * 200 + (orderPosition + 1) * 10; mindmapTopic.setPosition(position + "," + 200 * orderPosition); - String fontStyle = generateFontStyle(freemindNode, null); - if (!fontStyle.isEmpty()) { + final String fontStyle = generateFontStyle(freemindNode, null); + if (fontStyle!=null) { mindmapTopic.setFontStyle(fontStyle); } Boolean folded = Boolean.valueOf(freemindNode.getFOLDED()); @@ -401,39 +404,55 @@ public class FreemindImporter } } - private String generateFontStyle(Node node, Font font) { + private @Nullable String generateFontStyle(@NotNull Node node, @Nullable Font font) { /* * MindmapFont format : fontName ; size ; color ; bold; italic; * eg: Verdana;10;#ffffff;bold;italic; * */ + + // Font name ... final StringBuilder fontStyle = new StringBuilder(); if (font != null) { fontStyle.append(fixFontName(font)); - fontStyle.append(";"); - BigInteger bigInteger = (font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(8) : font.getSIZE(); + } + fontStyle.append(";"); + + // Size ... + if (font != null) { + final BigInteger bigInteger = (font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(8) : font.getSIZE(); fontStyle.append(bigInteger); - fontStyle.append(";"); - String color = node.getCOLOR(); - if (color != null && !color.equals("")) { - fontStyle.append(color); - } - fontStyle.append(";"); + } + fontStyle.append(";"); + // Color ... + final String color = node.getCOLOR(); + if (color != null && !color.equals("")) { + fontStyle.append(color); + } + fontStyle.append(";"); + + // Bold ... + if (font != null) { boolean hasBold = Boolean.parseBoolean(font.getBOLD()); - fontStyle.append(hasBold ? BOLD : ""); - fontStyle.append(";"); + } + fontStyle.append(";"); + // Italic ... + if (font != null) { boolean hasItalic = Boolean.parseBoolean(font.getITALIC()); fontStyle.append(hasItalic ? ITALIC : ""); - fontStyle.append(";"); } + fontStyle.append(";"); - return fontStyle.toString(); + final String result = fontStyle.toString(); + return result.equals(EMPTY_FONT_STYLE) ? null : result; } - private @NotNull String fixFontName(@NotNull Font font) { + private + @NotNull + String fixFontName(@NotNull Font font) { String result = com.wisemapping.model.Font.ARIAL.getFontName(); // Default Font if (com.wisemapping.model.Font.isValidFont(font.getNAME())) { result = font.getNAME(); diff --git a/wise-webapp/src/test/data/freemind/node-styles.mm b/wise-webapp/src/test/data/freemind/node-styles.mm new file mode 100644 index 00000000..72d00dc5 --- /dev/null +++ b/wise-webapp/src/test/data/freemind/node-styles.mm @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wise-webapp/src/test/data/freemind/node-styles.mmr b/wise-webapp/src/test/data/freemind/node-styles.mmr new file mode 100644 index 00000000..9a700c04 --- /dev/null +++ b/wise-webapp/src/test/data/freemind/node-styles.mmr @@ -0,0 +1 @@ + \ No newline at end of file