From be4cebf64bc001a5aeb9c22f494436394cecb5ec Mon Sep 17 00:00:00 2001 From: Pablo Luna Date: Tue, 11 Jan 2011 15:28:31 -0300 Subject: [PATCH] Freemind Import/Export, supporting relationship lines --- .../exporter/freemind/FreemindExporter.java | 28 +++++++++--- .../importer/freemind/FreemindImporter.java | 43 +++++++++++++++++-- 2 files changed, 63 insertions(+), 8 deletions(-) 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 725413ed..43c21bf8 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 @@ -23,10 +23,8 @@ import com.wisemapping.exporter.ExportException; import com.wisemapping.exporter.Exporter; import com.wisemapping.model.MindMap; import com.wisemapping.util.JAXBUtils; -import com.wisemapping.xml.freemind.Font; -import com.wisemapping.xml.freemind.Node; -import com.wisemapping.xml.freemind.Edge; -import com.wisemapping.xml.freemind.Hook; +import com.wisemapping.xml.freemind.*; +import com.wisemapping.xml.mindmap.RelationshipType; import com.wisemapping.xml.mindmap.TopicType; import com.wisemapping.xml.mindmap.Icon; @@ -35,13 +33,16 @@ import java.io.IOException; import java.io.OutputStream; import java.io.ByteArrayInputStream; import java.math.BigInteger; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class FreemindExporter implements Exporter { private com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory; + private Map nodesMap = null; public void export(MindMap map, OutputStream outputStream) throws ExportException { try { @@ -54,6 +55,7 @@ public class FreemindExporter public void export(byte[] xml, OutputStream outputStream) throws ExportException { freemindObjectFactory = new com.wisemapping.xml.freemind.ObjectFactory(); + nodesMap = new HashMap(); final com.wisemapping.xml.mindmap.Map mindmapMap; try { @@ -85,9 +87,21 @@ public class FreemindExporter freemindMap.setNode(main); if (centerTopic != null) { + nodesMap.put(centerTopic.getId(), main); setTopicPropertiesToNode(main,centerTopic); addNodeFromTopic(centerTopic,main); } + List relationships = mindmapMap.getRelationship(); + 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()) + arrowlink.setENDARROW("Default"); + List cloudOrEdge = srcNode.getArrowlinkOrCloudOrEdge(); + cloudOrEdge.add(arrowlink); + } JAXBUtils.saveMap(freemindMap,outputStream,"com.wisemapping.xml.freemind"); } catch (JAXBException e) { @@ -101,6 +115,7 @@ public class FreemindExporter for (TopicType topicType : currentTopic) { final Node newNode = freemindObjectFactory.createNode(); + nodesMap.put(topicType.getId(), newNode); setTopicPropertiesToNode(newNode,topicType); destNode.getArrowlinkOrCloudOrEdge().add(newNode); addNodeFromTopic(topicType,newNode); @@ -109,6 +124,7 @@ public class FreemindExporter 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 @@ -122,7 +138,9 @@ public class FreemindExporter addFontNode(freemindNode,mindmapTopic); addEdgeNode(freemindNode,mindmapTopic); addNote(freemindNode,mindmapTopic); - + Boolean shrink = mindmapTopic.isShrink(); + if(shrink!=null && shrink) + freemindNode.setFOLDED(String.valueOf(shrink)); } private void addNote(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic) 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 b0f38914..1fb13773 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 @@ -27,7 +27,9 @@ import com.wisemapping.model.ShapeStyle; import com.wisemapping.model.MindMapNative; import com.wisemapping.util.JAXBUtils; import com.wisemapping.xml.freemind.*; +import com.wisemapping.xml.freemind.Map; import com.wisemapping.xml.freemind.Node; +import com.wisemapping.xml.mindmap.RelationshipType; import com.wisemapping.xml.mindmap.TopicType; import com.wisemapping.xml.mindmap.Link; import org.w3c.dom.*; @@ -36,8 +38,7 @@ import javax.xml.bind.JAXBException; import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.math.BigInteger; public class FreemindImporter @@ -49,6 +50,9 @@ public class FreemindImporter private static final String BOLD = "bold"; private static final String ITALIC = "italic"; private static final String EMPTY_NOTE = ""; + private java.util.Map nodesMap = null; + private List relationships = null; + private int currentId; public MindMap importMap(String mapName,String description,InputStream input) throws ImporterException { @@ -58,19 +62,25 @@ public class FreemindImporter final Map freemindMap = (Map) JAXBUtils.getMapObject(input,"com.wisemapping.xml.freemind"); final com.wisemapping.xml.mindmap.Map mindmapMap = mindmapObjectFactory.createMap(); + mindmapMap.setVersion("pela"); + currentId=0; final Node centralNode = freemindMap.getNode(); final TopicType centralTopic = mindmapObjectFactory.createTopicType(); + centralTopic.setId(String.valueOf(currentId++)); centralTopic.setCentral(true); setNodePropertiesToTopic(centralTopic,centralNode); centralTopic.setShape(ShapeStyle.ELIPSE.getStyle()); mindmapMap.getTopic().add(centralTopic); mindmapMap.setName(mapName); - + nodesMap = new HashMap(); + relationships = new ArrayList(); addTopicFromNode(centralNode,centralTopic); fixCentralTopicChildOrder(centralTopic); + addRelationships(mindmapMap); + ByteArrayOutputStream out = new ByteArrayOutputStream(); JAXBUtils.saveMap(mindmapMap,out,"com.wisemapping.xml.mindmap"); @@ -89,6 +99,17 @@ public class FreemindImporter return map; } + private void addRelationships(com.wisemapping.xml.mindmap.Map mindmapMap) { + List mapRelationships = mindmapMap.getRelationship(); + for(RelationshipType relationship : relationships){ + relationship.setId(String.valueOf(currentId++)); + String destId = relationship.getDestTopicId(); + TopicType destTopic = nodesMap.get(destId); + relationship.setDestTopicId(destTopic.getId()); + mapRelationships.add(relationship); + } + } + private void fixCentralTopicChildOrder(TopicType centralTopic){ List topics = centralTopic.getTopic(); List leftTopics = new ArrayList(); @@ -178,6 +199,8 @@ public class FreemindImporter { final Node node = (Node) freemindNode; TopicType newTopic = mindmapObjectFactory.createTopicType(); + newTopic.setId(String.valueOf(currentId++)); + nodesMap.put(node.getID(), newTopic); //Lets use freemind id temporarily. This will be fixed when adding relationship to the map. newTopic.setOrder(order++); String url = node.getLINK(); if (url != null) @@ -245,6 +268,20 @@ public class FreemindImporter } } + else if (freemindNode instanceof Arrowlink){ + final Arrowlink arrow = (Arrowlink) freemindNode; + RelationshipType relationship = mindmapObjectFactory.createRelationshipType(); + String destId = arrow.getDESTINATION(); + relationship.setSrcTopicId(currentTopic.getId()); + relationship.setDestTopicId(destId); + /*String[] inclination = arrow.getENDINCLINATION().split(";"); + relationship.setDestCtrlPoint(inclination[0]+","+inclination[1]); + inclination = arrow.getSTARTINCLINATION().split(";"); + relationship.setSrcCtrlPoint(inclination[0]+","+inclination[1]);*/ + relationship.setEndArrow(!arrow.getENDARROW().equals("None")); + relationship.setLineType("3"); + relationships.add(relationship); + } } }