- Set freemind version to the exported map
- Exported map don't useless font nodes.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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(";");
|
||||
|
Reference in New Issue
Block a user