- Set freemind version to the exported map

- Exported map don't useless font nodes.
This commit is contained in:
Paulo Gustavo Veiga 2011-03-12 17:08:01 -03:00
parent 905e1b8ee5
commit 600bde0e15
6 changed files with 152 additions and 105 deletions

View File

@ -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<String, Node> 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<TopicType> 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<RelationshipType> 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<Object> 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<TopicType> 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<Icon> 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);
}
}
}

View File

@ -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(";");

View File

@ -0,0 +1,15 @@
<map version="0.9.0">
<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
<node CREATED="1299957724614" ID="ID_1257555991" MODIFIED="1299957854045" TEXT="This is the root node">
<node CREATED="1299957744918" ID="ID_1422930763" MODIFIED="1299957853173" POSITION="right" TEXT="Child Level 1 Right 1"/>
<node CREATED="1299957780229" ID="ID_144311076" MODIFIED="1299957963408" POSITION="left" TEXT="Child Level 1 Left 1">
<node CREATED="1299957789533" ID="ID_1332317829" MODIFIED="1299957906469" TEXT="Child Level 2 Left 11"/>
<node CREATED="1299957813629" ID="ID_655171350" MODIFIED="1299957910302" TEXT="Child Level 2 Left 12"/>
</node>
<node CREATED="1299957842218" ID="ID_217430375" MODIFIED="1299957850272" POSITION="right" TEXT="Child Level 1 Right 2"/>
<node CREATED="1299957854506" ID="ID_1895272648" MODIFIED="1299957934625" POSITION="left" TEXT="Child Level 1 Left 2">
<node CREATED="1299957875229" ID="ID_1628175442" MODIFIED="1299957927173" TEXT="Child Level 2 Left 21 "/>
<node CREATED="1299957940222" ID="ID_1406492242" MODIFIED="1299957958013" TEXT="Child Level 2 Left 22"/>
</node>
</node>
</map>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<map version="0.9.0">
<node TEXT="This is the root node" STYLE="line" ID="ID_0">
<node TEXT="Child Level 1 Right 1" STYLE="line" ID="ID_1"/>
<node TEXT="Child Level 1 Left 1" STYLE="line" ID="ID_2">
<node TEXT="Child Level 2 Left 11" STYLE="line" ID="ID_3"/>
<node TEXT="Child Level 2 Left 12" STYLE="line" ID="ID_4"/>
</node>
<node TEXT="Child Level 1 Right 2" STYLE="line" ID="ID_5"/>
<node TEXT="Child Level 1 Left 2" STYLE="line" ID="ID_6">
<node TEXT="Child Level 2 Left 21 " STYLE="line" ID="ID_7"/>
<node TEXT="Child Level 2 Left 22" STYLE="line" ID="ID_8"/>
</node>
</node>
</map>

View File

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

View File

@ -1,14 +0,0 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="WiseWebServicesSuite" verbose="1" >
<test name="WiseMapping Web Services Integration API">
<groups>
<run>
<exclude name="wsintegration"/>
</run>
</groups>
<packages>
<package name="com.wisemapping.ws.test" />
</packages>
</test>
</suite>