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 0014c647..7856a73c 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 @@ -37,15 +37,16 @@ import java.util.List; import java.util.Map; public class FreemindExporter - implements Exporter -{ + implements Exporter { + private static final String FREE_MIND_VERSION = "0.9.0"; + private static final String EMPTY_FONT_STYLE = ";;;;;"; private com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory; private Map nodesMap = null; public void export(MindMap map, OutputStream outputStream) throws ExportException { try { - export(map.getUnzippedXml().getBytes(),outputStream); + export(map.getUnzippedXml().getBytes(), outputStream); } catch (IOException e) { throw new ExportException(e); } @@ -59,117 +60,105 @@ public class FreemindExporter try { final ByteArrayInputStream stream = new ByteArrayInputStream(xml); - mindmapMap = (com.wisemapping.xml.mindmap.Map) JAXBUtils.getMapObject(stream,"com.wisemapping.xml.mindmap"); + mindmapMap = (com.wisemapping.xml.mindmap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.xml.mindmap"); final com.wisemapping.xml.freemind.Map freemindMap = freemindObjectFactory.createMap(); + freemindMap.setVersion(FREE_MIND_VERSION); + final List topics = mindmapMap.getTopic(); // Insolated Topic doesn´t exists in Freemind only take the center topic TopicType centerTopic = null; - if (topics.size() >1) - { + if (topics.size() > 1) { for (TopicType topic : topics) { - if (topic.isCentral()) - { + if (topic.isCentral()) { centerTopic = topic; break; } } - } - else - { + } else { centerTopic = topics.get(0); } final Node main = freemindObjectFactory.createNode(); freemindMap.setNode(main); - if (centerTopic != null) - { + if (centerTopic != null) { nodesMap.put(centerTopic.getId(), main); - setTopicPropertiesToNode(main,centerTopic); - addNodeFromTopic(centerTopic,main); + setTopicPropertiesToNode(main, centerTopic); + addNodeFromTopic(centerTopic, main); } List relationships = mindmapMap.getRelationship(); - for(RelationshipType relationship : relationships){ + for (RelationshipType relationship : relationships) { Node srcNode = nodesMap.get(relationship.getSrcTopicId()); Arrowlink arrowlink = freemindObjectFactory.createArrowlink(); Node dstNode = nodesMap.get(relationship.getDestTopicId()); arrowlink.setDESTINATION(dstNode.getID()); - if(relationship.isEndArrow()) + if (relationship.isEndArrow()) arrowlink.setENDARROW("Default"); - if(relationship.isStartArrow()) + if (relationship.isStartArrow()) arrowlink.setSTARTARROW("Default"); List cloudOrEdge = srcNode.getArrowlinkOrCloudOrEdge(); cloudOrEdge.add(arrowlink); } - JAXBUtils.saveMap(freemindMap,outputStream,"com.wisemapping.xml.freemind"); - } catch (JAXBException e) { + JAXBUtils.saveMap(freemindMap, outputStream, "com.wisemapping.xml.freemind"); + } catch (JAXBException e) { throw new ExportException(e); } } - private void addNodeFromTopic(TopicType mainTopic, Node destNode) - { + private void addNodeFromTopic(TopicType mainTopic, Node destNode) { final List currentTopic = mainTopic.getTopic(); for (TopicType topicType : currentTopic) { final Node newNode = freemindObjectFactory.createNode(); nodesMap.put(topicType.getId(), newNode); - setTopicPropertiesToNode(newNode,topicType); + setTopicPropertiesToNode(newNode, topicType); destNode.getArrowlinkOrCloudOrEdge().add(newNode); - addNodeFromTopic(topicType,newNode); + addNodeFromTopic(topicType, newNode); } } - private void setTopicPropertiesToNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) - { - freemindNode.setID("ID_"+mindmapTopic.getId()); + private void setTopicPropertiesToNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { + freemindNode.setID("ID_" + mindmapTopic.getId()); freemindNode.setTEXT(mindmapTopic.getText()); freemindNode.setBACKGROUNDCOLOR(mindmapTopic.getBgColor()); String style = "line"; // default style for freemind - if ("rounded rectagle".equals(mindmapTopic.getShape())) - { + if ("rounded rectagle".equals(mindmapTopic.getShape())) { style = "bubble"; } freemindNode.setSTYLE(style); - addIconNode(freemindNode,mindmapTopic); - addLinkNode(freemindNode,mindmapTopic); - addFontNode(freemindNode,mindmapTopic); - addEdgeNode(freemindNode,mindmapTopic); - addNote(freemindNode,mindmapTopic); + addIconNode(freemindNode, mindmapTopic); + addLinkNode(freemindNode, mindmapTopic); + addFontNode(freemindNode, mindmapTopic); + addEdgeNode(freemindNode, mindmapTopic); + addNote(freemindNode, mindmapTopic); Boolean shrink = mindmapTopic.isShrink(); - if(shrink!=null && shrink) + if (shrink != null && shrink) freemindNode.setFOLDED(String.valueOf(shrink)); } - private void addNote(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic) - { - if (mindmapTopic.getNote() != null) - { + private void addNote(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { + if (mindmapTopic.getNote() != null) { final Hook note = new Hook(); String textNote = mindmapTopic.getNote().getText(); - textNote = textNote.replaceAll("%0A","\n"); + textNote = textNote.replaceAll("%0A", "\n"); note.setNAME("accessories/plugins/NodeNote.properties"); note.setText(textNote); freemindNode.getArrowlinkOrCloudOrEdge().add(note); } } - private void addLinkNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic) - { - if (mindmapTopic.getLink() != null) - { + private void addLinkNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { + if (mindmapTopic.getLink() != null) { final String url = mindmapTopic.getLink().getUrl(); - freemindNode.setLINK(url); + freemindNode.setLINK(url); } } - private void addIconNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic) - { - if (mindmapTopic.getIcon() != null) - { + private void addIconNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { + if (mindmapTopic.getIcon() != null) { final List iconsList = mindmapTopic.getIcon(); for (Icon icon : iconsList) { final String id = icon.getId(); @@ -181,12 +170,10 @@ public class FreemindExporter } } - private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic) - { - if (mindmapTopic.getBrColor() != null) - { + private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { + if (mindmapTopic.getBrColor() != null) { final Edge edgeNode = freemindObjectFactory.createEdge(); - edgeNode.setCOLOR(mindmapTopic.getBrColor()); + edgeNode.setCOLOR(mindmapTopic.getBrColor()); freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode); } } @@ -196,47 +183,49 @@ 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(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) { final String fontStyle = mindmapTopic.getFontStyle(); - if (fontStyle!= null && fontStyle.length()!=0) - { + if (fontStyle != null && fontStyle.length() != 0) { final Font font = freemindObjectFactory.createFont(); - final String[] part = fontStyle.split(";",6); + final String[] part = fontStyle.split(";", 6); int countParts = part.length; - int idx=0; - // Font name - if (idx < countParts && part[idx].length()!=0) - { - font.setNAME(part[idx]); - } - idx++; - // Font size - String size = "10"; // default value - if (idx < countParts && part[idx].length()!=0) - { - size = part[idx]; - } - font.setSIZE(new BigInteger(size)); - idx++; + if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) { - // Font Color - if (idx < countParts && part[idx].length()!=0) - { - freemindNode.setCOLOR(part[idx]); + + int idx = 0; + // Font name + if (idx < countParts && part[idx].length() != 0) { + font.setNAME(part[idx]); + } + idx++; + + // Font size + if (idx < countParts && part[idx].length() != 0) { + String size = part[idx]; + font.setSIZE(new BigInteger(size)); + } + idx++; + + // Font Color + if (idx < countParts && part[idx].length() != 0) { + freemindNode.setCOLOR(part[idx]); + } + idx++; + + // Font Styles + if (idx < countParts && part[idx].length() != 0) { + font.setBOLD(Boolean.TRUE.toString()); + } + idx++; + + if (idx < countParts && part[idx].length() != 0) { + font.setITALIC(Boolean.TRUE.toString()); + } + + + freemindNode.getArrowlinkOrCloudOrEdge().add(font); } - idx++; - if (idx < countParts && part[idx].length()!=0) - { - font.setBOLD(Boolean.TRUE.toString()); - } - idx++; - if (idx < countParts && part[idx].length()!=0) - { - font.setITALIC(Boolean.TRUE.toString()); - } - 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 b906d454..036dc68d 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 @@ -427,7 +427,10 @@ public class FreemindImporter fontStyle.append(bigInteger); fontStyle.append(";"); String color = node.getCOLOR(); - fontStyle.append((color!=null && !color.equals(""))?color:"#000000"); + if(color!=null && !color.equals("")) + { + fontStyle.append(color); + } fontStyle.append(";"); boolean hasBold = Boolean.parseBoolean(font.getBOLD()); @@ -444,7 +447,10 @@ public class FreemindImporter fontStyle.append(";"); fontStyle.append(";"); String color = node.getCOLOR(); - fontStyle.append((color!=null && !color.equals(""))?color:"#000000"); + if(color!=null && !color.equals("")) + { + fontStyle.append(color); + } fontStyle.append(";"); fontStyle.append(";"); fontStyle.append(";"); diff --git a/wise-webapp/src/test/data/freemind/basic.mm b/wise-webapp/src/test/data/freemind/basic.mm new file mode 100644 index 00000000..3b629352 --- /dev/null +++ b/wise-webapp/src/test/data/freemind/basic.mm @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/wise-webapp/src/test/data/freemind/basice.mm b/wise-webapp/src/test/data/freemind/basice.mm new file mode 100644 index 00000000..a3f53ab7 --- /dev/null +++ b/wise-webapp/src/test/data/freemind/basice.mm @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wise-webapp/src/test/java/com/wisemapping/test/freemind/FreeMindExportTest.java b/wise-webapp/src/test/java/com/wisemapping/test/freemind/FreeMindExportTest.java new file mode 100644 index 00000000..df20a6b7 --- /dev/null +++ b/wise-webapp/src/test/java/com/wisemapping/test/freemind/FreeMindExportTest.java @@ -0,0 +1,36 @@ +package wisemapping.test.freemind; + +import com.wisemapping.exporter.ExportException; +import com.wisemapping.exporter.freemind.FreemindExporter; +import com.wisemapping.importer.ImportFormat; +import com.wisemapping.importer.Importer; +import com.wisemapping.importer.ImporterException; +import com.wisemapping.importer.ImporterFactory; + +import com.wisemapping.model.MindMap; +import org.testng.annotations.Test; + +import java.io.*; + +public class FreeMindExportTest { + private static final String DATA_DIR_PATH = "wise-webapp/src/test/data/freemind/"; + + @Test + public void exportImportExportTest() throws ImporterException, IOException, ExportException { + + ImporterFactory instance = ImporterFactory.getInstance(); + Importer importer = instance.getImporter(ImportFormat.FREEMIND); + + FileInputStream fileInputStream = new FileInputStream(new File(DATA_DIR_PATH, "basic.mm").getAbsolutePath()); + final MindMap mindMap = importer.importMap("basic", "basic", fileInputStream); + + final FreemindExporter freemindExporter = new FreemindExporter(); + FileOutputStream fos = new FileOutputStream(new File("wise-webapp/src/test/data/freemind/","basice.mm")); + freemindExporter.export(mindMap,fos); + fos.close(); + + + } + + +} diff --git a/wise-webapp/testng.xml b/wise-webapp/testng.xml deleted file mode 100644 index e8193c47..00000000 --- a/wise-webapp/testng.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file