mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
- Set freemind version to the exported map
- Exported map don't useless font nodes.
This commit is contained in:
parent
905e1b8ee5
commit
600bde0e15
@ -37,9 +37,10 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class FreemindExporter
|
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 com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory;
|
||||||
private Map<String, Node> nodesMap = null;
|
private Map<String, Node> nodesMap = null;
|
||||||
|
|
||||||
@ -62,30 +63,27 @@ public class FreemindExporter
|
|||||||
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();
|
final com.wisemapping.xml.freemind.Map freemindMap = freemindObjectFactory.createMap();
|
||||||
|
freemindMap.setVersion(FREE_MIND_VERSION);
|
||||||
|
|
||||||
|
|
||||||
final List<TopicType> topics = mindmapMap.getTopic();
|
final List<TopicType> topics = mindmapMap.getTopic();
|
||||||
|
|
||||||
// Insolated Topic doesn´t exists in Freemind only take the center topic
|
// Insolated Topic doesn´t exists in Freemind only take the center topic
|
||||||
TopicType centerTopic = null;
|
TopicType centerTopic = null;
|
||||||
if (topics.size() >1)
|
if (topics.size() > 1) {
|
||||||
{
|
|
||||||
for (TopicType topic : topics) {
|
for (TopicType topic : topics) {
|
||||||
if (topic.isCentral())
|
if (topic.isCentral()) {
|
||||||
{
|
|
||||||
centerTopic = topic;
|
centerTopic = topic;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
centerTopic = topics.get(0);
|
centerTopic = topics.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Node main = freemindObjectFactory.createNode();
|
final Node main = freemindObjectFactory.createNode();
|
||||||
freemindMap.setNode(main);
|
freemindMap.setNode(main);
|
||||||
if (centerTopic != null)
|
if (centerTopic != null) {
|
||||||
{
|
|
||||||
nodesMap.put(centerTopic.getId(), main);
|
nodesMap.put(centerTopic.getId(), main);
|
||||||
setTopicPropertiesToNode(main, centerTopic);
|
setTopicPropertiesToNode(main, centerTopic);
|
||||||
addNodeFromTopic(centerTopic, main);
|
addNodeFromTopic(centerTopic, main);
|
||||||
@ -110,8 +108,7 @@ public class FreemindExporter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNodeFromTopic(TopicType mainTopic, Node destNode)
|
private void addNodeFromTopic(TopicType mainTopic, Node destNode) {
|
||||||
{
|
|
||||||
final List<TopicType> currentTopic = mainTopic.getTopic();
|
final List<TopicType> currentTopic = mainTopic.getTopic();
|
||||||
|
|
||||||
for (TopicType topicType : currentTopic) {
|
for (TopicType topicType : currentTopic) {
|
||||||
@ -123,14 +120,12 @@ public class FreemindExporter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTopicPropertiesToNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
private void setTopicPropertiesToNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
{
|
|
||||||
freemindNode.setID("ID_" + mindmapTopic.getId());
|
freemindNode.setID("ID_" + mindmapTopic.getId());
|
||||||
freemindNode.setTEXT(mindmapTopic.getText());
|
freemindNode.setTEXT(mindmapTopic.getText());
|
||||||
freemindNode.setBACKGROUNDCOLOR(mindmapTopic.getBgColor());
|
freemindNode.setBACKGROUNDCOLOR(mindmapTopic.getBgColor());
|
||||||
String style = "line"; // default style for freemind
|
String style = "line"; // default style for freemind
|
||||||
if ("rounded rectagle".equals(mindmapTopic.getShape()))
|
if ("rounded rectagle".equals(mindmapTopic.getShape())) {
|
||||||
{
|
|
||||||
style = "bubble";
|
style = "bubble";
|
||||||
}
|
}
|
||||||
freemindNode.setSTYLE(style);
|
freemindNode.setSTYLE(style);
|
||||||
@ -144,10 +139,8 @@ public class FreemindExporter
|
|||||||
freemindNode.setFOLDED(String.valueOf(shrink));
|
freemindNode.setFOLDED(String.valueOf(shrink));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNote(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
private void addNote(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
{
|
if (mindmapTopic.getNote() != null) {
|
||||||
if (mindmapTopic.getNote() != null)
|
|
||||||
{
|
|
||||||
final Hook note = new Hook();
|
final Hook note = new Hook();
|
||||||
String textNote = mindmapTopic.getNote().getText();
|
String textNote = mindmapTopic.getNote().getText();
|
||||||
textNote = textNote.replaceAll("%0A", "\n");
|
textNote = textNote.replaceAll("%0A", "\n");
|
||||||
@ -157,19 +150,15 @@ public class FreemindExporter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLinkNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
private void addLinkNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
{
|
if (mindmapTopic.getLink() != null) {
|
||||||
if (mindmapTopic.getLink() != null)
|
|
||||||
{
|
|
||||||
final String url = mindmapTopic.getLink().getUrl();
|
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)
|
private void addIconNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
{
|
if (mindmapTopic.getIcon() != null) {
|
||||||
if (mindmapTopic.getIcon() != null)
|
|
||||||
{
|
|
||||||
final List<Icon> iconsList = mindmapTopic.getIcon();
|
final List<Icon> iconsList = mindmapTopic.getIcon();
|
||||||
for (Icon icon : iconsList) {
|
for (Icon icon : iconsList) {
|
||||||
final String id = icon.getId();
|
final String id = icon.getId();
|
||||||
@ -181,10 +170,8 @@ public class FreemindExporter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
{
|
if (mindmapTopic.getBrColor() != null) {
|
||||||
if (mindmapTopic.getBrColor() != null)
|
|
||||||
{
|
|
||||||
final Edge edgeNode = freemindObjectFactory.createEdge();
|
final Edge edgeNode = freemindObjectFactory.createEdge();
|
||||||
edgeNode.setCOLOR(mindmapTopic.getBrColor());
|
edgeNode.setCOLOR(mindmapTopic.getBrColor());
|
||||||
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
||||||
@ -196,47 +183,49 @@ public class FreemindExporter
|
|||||||
* eg: Verdana;10;#ffffff;bold;italic;
|
* 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();
|
final String fontStyle = mindmapTopic.getFontStyle();
|
||||||
if (fontStyle!= null && fontStyle.length()!=0)
|
if (fontStyle != null && fontStyle.length() != 0) {
|
||||||
{
|
|
||||||
final Font font = freemindObjectFactory.createFont();
|
final Font font = freemindObjectFactory.createFont();
|
||||||
final String[] part = fontStyle.split(";", 6);
|
final String[] part = fontStyle.split(";", 6);
|
||||||
int countParts = part.length;
|
int countParts = part.length;
|
||||||
|
|
||||||
|
if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) {
|
||||||
|
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
// Font name
|
// Font name
|
||||||
if (idx < countParts && part[idx].length()!=0)
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
{
|
|
||||||
font.setNAME(part[idx]);
|
font.setNAME(part[idx]);
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
// Font size
|
|
||||||
String size = "10"; // default value
|
|
||||||
if (idx < countParts && part[idx].length()!=0)
|
|
||||||
{
|
|
||||||
size = part[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Font size
|
||||||
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
|
String size = part[idx];
|
||||||
font.setSIZE(new BigInteger(size));
|
font.setSIZE(new BigInteger(size));
|
||||||
|
}
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
// Font Color
|
// Font Color
|
||||||
if (idx < countParts && part[idx].length()!=0)
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
{
|
|
||||||
freemindNode.setCOLOR(part[idx]);
|
freemindNode.setCOLOR(part[idx]);
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
if (idx < countParts && part[idx].length()!=0)
|
|
||||||
{
|
// Font Styles
|
||||||
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
font.setBOLD(Boolean.TRUE.toString());
|
font.setBOLD(Boolean.TRUE.toString());
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
if (idx < countParts && part[idx].length()!=0)
|
|
||||||
{
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
font.setITALIC(Boolean.TRUE.toString());
|
font.setITALIC(Boolean.TRUE.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -427,7 +427,10 @@ public class FreemindImporter
|
|||||||
fontStyle.append(bigInteger);
|
fontStyle.append(bigInteger);
|
||||||
fontStyle.append(";");
|
fontStyle.append(";");
|
||||||
String color = node.getCOLOR();
|
String color = node.getCOLOR();
|
||||||
fontStyle.append((color!=null && !color.equals(""))?color:"#000000");
|
if(color!=null && !color.equals(""))
|
||||||
|
{
|
||||||
|
fontStyle.append(color);
|
||||||
|
}
|
||||||
fontStyle.append(";");
|
fontStyle.append(";");
|
||||||
|
|
||||||
boolean hasBold = Boolean.parseBoolean(font.getBOLD());
|
boolean hasBold = Boolean.parseBoolean(font.getBOLD());
|
||||||
@ -444,7 +447,10 @@ public class FreemindImporter
|
|||||||
fontStyle.append(";");
|
fontStyle.append(";");
|
||||||
fontStyle.append(";");
|
fontStyle.append(";");
|
||||||
String color = node.getCOLOR();
|
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(";");
|
fontStyle.append(";");
|
||||||
fontStyle.append(";");
|
fontStyle.append(";");
|
||||||
|
15
wise-webapp/src/test/data/freemind/basic.mm
Normal file
15
wise-webapp/src/test/data/freemind/basic.mm
Normal 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>
|
15
wise-webapp/src/test/data/freemind/basice.mm
Normal file
15
wise-webapp/src/test/data/freemind/basice.mm
Normal 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>
|
@ -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();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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>
|
|
Loading…
Reference in New Issue
Block a user