mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 06:07:57 +01:00
Fix export of links in root node.
This commit is contained in:
parent
c74adcbf54
commit
cff3d7cc8a
@ -1,253 +1,256 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright [2011] [wisemapping]
|
* Copyright [2011] [wisemapping]
|
||||||
*
|
*
|
||||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
* "powered by wisemapping" text requirement on every single page;
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the license at
|
* You may obtain a copy of the license at
|
||||||
*
|
*
|
||||||
* http://www.wisemapping.org/license
|
* http://www.wisemapping.org/license
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.wisemapping.exporter.freemind;
|
package com.wisemapping.exporter.freemind;
|
||||||
|
|
||||||
import com.wisemapping.exporter.ExportException;
|
import com.wisemapping.exporter.ExportException;
|
||||||
import com.wisemapping.exporter.Exporter;
|
import com.wisemapping.exporter.Exporter;
|
||||||
import com.wisemapping.importer.freemind.FreemindIconConverter;
|
import com.wisemapping.importer.freemind.FreemindIconConverter;
|
||||||
import com.wisemapping.model.MindMap;
|
import com.wisemapping.model.MindMap;
|
||||||
import com.wisemapping.util.JAXBUtils;
|
import com.wisemapping.util.JAXBUtils;
|
||||||
import com.wisemapping.xml.freemind.*;
|
import com.wisemapping.xml.freemind.*;
|
||||||
import com.wisemapping.xml.mindmap.RelationshipType;
|
import com.wisemapping.xml.mindmap.RelationshipType;
|
||||||
import com.wisemapping.xml.mindmap.TopicType;
|
import com.wisemapping.xml.mindmap.TopicType;
|
||||||
import com.wisemapping.xml.mindmap.Icon;
|
import com.wisemapping.xml.mindmap.Icon;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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 FREE_MIND_VERSION = "0.9.0";
|
||||||
private static final String POSITION_LEFT = "left";
|
private static final String POSITION_LEFT = "left";
|
||||||
private static final String POSITION_RIGHT = "right";
|
private static final String POSITION_RIGHT = "right";
|
||||||
private com.wisemapping.xml.freemind.ObjectFactory objectFactory;
|
private com.wisemapping.xml.freemind.ObjectFactory objectFactory;
|
||||||
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
||||||
|
|
||||||
private Map<String, Node> nodesMap = null;
|
private Map<String, Node> nodesMap = null;
|
||||||
|
|
||||||
public void export(MindMap map, OutputStream outputStream) throws ExportException {
|
public void export(MindMap map, OutputStream outputStream) throws ExportException {
|
||||||
try {
|
try {
|
||||||
export(map.getUnzippedXml().getBytes(), outputStream);
|
export(map.getUnzippedXml().getBytes(), outputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ExportException(e);
|
throw new ExportException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void export(byte[] xml, OutputStream outputStream) throws ExportException {
|
public void export(byte[] xml, OutputStream outputStream) throws ExportException {
|
||||||
|
|
||||||
objectFactory = new com.wisemapping.xml.freemind.ObjectFactory();
|
objectFactory = new com.wisemapping.xml.freemind.ObjectFactory();
|
||||||
nodesMap = new HashMap<String, Node>();
|
nodesMap = new HashMap<String, Node>();
|
||||||
final com.wisemapping.xml.mindmap.Map mindmapMap;
|
final com.wisemapping.xml.mindmap.Map mindmapMap;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ByteArrayInputStream stream = new ByteArrayInputStream(xml);
|
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 = objectFactory.createMap();
|
final com.wisemapping.xml.freemind.Map freemindMap = objectFactory.createMap();
|
||||||
freemindMap.setVersion(FREE_MIND_VERSION);
|
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 = objectFactory.createNode();
|
final Node main = objectFactory.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);
|
||||||
}
|
}
|
||||||
List<RelationshipType> relationships = mindmapMap.getRelationship();
|
List<RelationshipType> relationships = mindmapMap.getRelationship();
|
||||||
for (RelationshipType relationship : relationships) {
|
for (RelationshipType relationship : relationships) {
|
||||||
Node srcNode = nodesMap.get(relationship.getSrcTopicId());
|
Node srcNode = nodesMap.get(relationship.getSrcTopicId());
|
||||||
Arrowlink arrowlink = objectFactory.createArrowlink();
|
Arrowlink arrowlink = objectFactory.createArrowlink();
|
||||||
Node dstNode = nodesMap.get(relationship.getDestTopicId());
|
Node dstNode = nodesMap.get(relationship.getDestTopicId());
|
||||||
arrowlink.setDESTINATION(dstNode.getID());
|
arrowlink.setDESTINATION(dstNode.getID());
|
||||||
if (relationship.isEndArrow())
|
if (relationship.isEndArrow())
|
||||||
arrowlink.setENDARROW("Default");
|
arrowlink.setENDARROW("Default");
|
||||||
if (relationship.isStartArrow())
|
if (relationship.isStartArrow())
|
||||||
arrowlink.setSTARTARROW("Default");
|
arrowlink.setSTARTARROW("Default");
|
||||||
List<Object> cloudOrEdge = srcNode.getArrowlinkOrCloudOrEdge();
|
List<Object> cloudOrEdge = srcNode.getArrowlinkOrCloudOrEdge();
|
||||||
cloudOrEdge.add(arrowlink);
|
cloudOrEdge.add(arrowlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
JAXBUtils.saveMap(freemindMap, outputStream, "com.wisemapping.xml.freemind");
|
JAXBUtils.saveMap(freemindMap, outputStream, "com.wisemapping.xml.freemind");
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
throw new ExportException(e);
|
throw new ExportException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNodeFromTopic(@NotNull final TopicType mainTopic, @NotNull final Node destNode) {
|
private void addNodeFromTopic(@NotNull final TopicType mainTopic, @NotNull final Node destNode) {
|
||||||
final List<TopicType> currentTopic = mainTopic.getTopic();
|
final List<TopicType> currentTopic = mainTopic.getTopic();
|
||||||
|
|
||||||
for (TopicType topicType : currentTopic) {
|
for (TopicType topicType : currentTopic) {
|
||||||
final Node newNode = objectFactory.createNode();
|
final Node newNode = objectFactory.createNode();
|
||||||
nodesMap.put(topicType.getId(), newNode);
|
nodesMap.put(topicType.getId(), newNode);
|
||||||
setTopicPropertiesToNode(newNode, topicType);
|
setTopicPropertiesToNode(newNode, topicType);
|
||||||
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
||||||
addNodeFromTopic(topicType, newNode);
|
addNodeFromTopic(topicType, newNode);
|
||||||
String position = topicType.getPosition();
|
final String position = topicType.getPosition();
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
String xPos = position.split(",")[0];
|
String xPos = position.split(",")[0];
|
||||||
int x = Integer.valueOf(xPos);
|
int x = Integer.valueOf(xPos);
|
||||||
newNode.setPOSITION((x < 0 ? POSITION_LEFT : POSITION_RIGHT));
|
newNode.setPOSITION((x < 0 ? POSITION_LEFT : POSITION_RIGHT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
if (mindmapTopic.getShape() != null && !mindmapTopic.getShape().equals("line")) {
|
if (mindmapTopic.getShape() != null && !mindmapTopic.getShape().equals("line")) {
|
||||||
String style = mindmapTopic.getShape();
|
String style = mindmapTopic.getShape();
|
||||||
if ("rounded rectagle".equals(mindmapTopic.getShape())) {
|
if ("rounded rectagle".equals(mindmapTopic.getShape())) {
|
||||||
style = "bubble";
|
style = "bubble";
|
||||||
}
|
}
|
||||||
freemindNode.setSTYLE(style);
|
freemindNode.setSTYLE(style);
|
||||||
}
|
}
|
||||||
addIconNode(freemindNode, mindmapTopic);
|
addIconNode(freemindNode, mindmapTopic);
|
||||||
addLinkNode(freemindNode, mindmapTopic);
|
|
||||||
addFontNode(freemindNode, mindmapTopic);
|
addLinkNode(freemindNode, mindmapTopic);
|
||||||
addEdgeNode(freemindNode, mindmapTopic);
|
|
||||||
addNote(freemindNode, mindmapTopic);
|
addFontNode(freemindNode, mindmapTopic);
|
||||||
Boolean shrink = mindmapTopic.isShrink();
|
addEdgeNode(freemindNode, mindmapTopic);
|
||||||
if (shrink != null && shrink)
|
addNote(freemindNode, mindmapTopic);
|
||||||
freemindNode.setFOLDED(String.valueOf(shrink));
|
|
||||||
}
|
Boolean shrink = mindmapTopic.isShrink();
|
||||||
|
if (shrink != null && shrink)
|
||||||
private void addNote(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
freemindNode.setFOLDED(String.valueOf(shrink));
|
||||||
if (mindmapTopic.getNote() != null) {
|
}
|
||||||
final Hook note = new Hook();
|
|
||||||
String textNote = mindmapTopic.getNote().getText();
|
private void addNote(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
textNote = textNote.replaceAll("%0A", "\n");
|
if (mindmapTopic.getNote() != null) {
|
||||||
note.setNAME("accessories/plugins/NodeNote.properties");
|
final Hook note = new Hook();
|
||||||
note.setText(textNote);
|
String textNote = mindmapTopic.getNote().getText();
|
||||||
freemindNode.getArrowlinkOrCloudOrEdge().add(note);
|
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) {
|
}
|
||||||
final String url = mindmapTopic.getLink().getUrl();
|
|
||||||
freemindNode.setLINK(url);
|
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);
|
||||||
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) {
|
private void addIconNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
final String id = icon.getId();
|
if (mindmapTopic.getIcon() != null) {
|
||||||
final String freemindIconId = FreemindIconConverter.toFreemindId(id);
|
final List<Icon> iconsList = mindmapTopic.getIcon();
|
||||||
if (freemindIconId != null) {
|
for (Icon icon : iconsList) {
|
||||||
|
final String id = icon.getId();
|
||||||
com.wisemapping.xml.freemind.Icon freemindIcon = new com.wisemapping.xml.freemind.Icon();
|
final String freemindIconId = FreemindIconConverter.toFreemindId(id);
|
||||||
freemindIcon.setBUILTIN(freemindIconId);
|
if (freemindIconId != null) {
|
||||||
freemindNode.getArrowlinkOrCloudOrEdge().add(freemindIcon);
|
|
||||||
}
|
com.wisemapping.xml.freemind.Icon freemindIcon = new com.wisemapping.xml.freemind.Icon();
|
||||||
}
|
freemindIcon.setBUILTIN(freemindIconId);
|
||||||
}
|
freemindNode.getArrowlinkOrCloudOrEdge().add(freemindIcon);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
}
|
||||||
if (mindmapTopic.getBrColor() != null) {
|
}
|
||||||
final Edge edgeNode = objectFactory.createEdge();
|
|
||||||
edgeNode.setCOLOR(mindmapTopic.getBrColor());
|
private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
if (mindmapTopic.getBrColor() != null) {
|
||||||
}
|
final Edge edgeNode = objectFactory.createEdge();
|
||||||
}
|
edgeNode.setCOLOR(mindmapTopic.getBrColor());
|
||||||
|
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
||||||
/*
|
}
|
||||||
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
}
|
||||||
* eg: Verdana;10;#ffffff;bold;italic;
|
|
||||||
*
|
/*
|
||||||
*/
|
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
||||||
private void addFontNode(@NotNull com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
* eg: Verdana;10;#ffffff;bold;italic;
|
||||||
final String fontStyle = mindmapTopic.getFontStyle();
|
*
|
||||||
if (fontStyle != null && fontStyle.length() != 0) {
|
*/
|
||||||
final Font font = objectFactory.createFont();
|
private void addFontNode(@NotNull com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||||
final String[] part = fontStyle.split(";", 6);
|
final String fontStyle = mindmapTopic.getFontStyle();
|
||||||
int countParts = part.length;
|
if (fontStyle != null && fontStyle.length() != 0) {
|
||||||
boolean updated = false;
|
final Font font = objectFactory.createFont();
|
||||||
|
final String[] part = fontStyle.split(";", 6);
|
||||||
if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) {
|
int countParts = part.length;
|
||||||
int idx = 0;
|
boolean updated = false;
|
||||||
|
|
||||||
// Font name
|
if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) {
|
||||||
if (idx < countParts && part[idx].length() != 0) {
|
int idx = 0;
|
||||||
font.setNAME(part[idx]);
|
|
||||||
updated = true;
|
// Font name
|
||||||
}
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
idx++;
|
font.setNAME(part[idx]);
|
||||||
|
updated = true;
|
||||||
// Font size
|
}
|
||||||
if (idx < countParts && part[idx].length() != 0) {
|
idx++;
|
||||||
String size = part[idx];
|
|
||||||
font.setSIZE(new BigInteger(size));
|
// Font size
|
||||||
updated = true;
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
}
|
String size = part[idx];
|
||||||
idx++;
|
font.setSIZE(new BigInteger(size));
|
||||||
|
updated = true;
|
||||||
// Font Color
|
}
|
||||||
if (idx < countParts && part[idx].length() != 0) {
|
idx++;
|
||||||
freemindNode.setCOLOR(part[idx]);
|
|
||||||
}
|
// Font Color
|
||||||
idx++;
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
|
freemindNode.setCOLOR(part[idx]);
|
||||||
// Font Styles
|
}
|
||||||
if (idx < countParts && part[idx].length() != 0) {
|
idx++;
|
||||||
font.setBOLD(Boolean.TRUE.toString());
|
|
||||||
updated = true;
|
// Font Styles
|
||||||
}
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
idx++;
|
font.setBOLD(Boolean.TRUE.toString());
|
||||||
|
updated = true;
|
||||||
if (idx < countParts && part[idx].length() != 0) {
|
}
|
||||||
font.setITALIC(Boolean.TRUE.toString());
|
idx++;
|
||||||
updated = true;
|
|
||||||
}
|
if (idx < countParts && part[idx].length() != 0) {
|
||||||
|
font.setITALIC(Boolean.TRUE.toString());
|
||||||
if (updated) {
|
updated = true;
|
||||||
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
}
|
||||||
}
|
|
||||||
}
|
if (updated) {
|
||||||
}
|
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,473 +1,492 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright [2011] [wisemapping]
|
* Copyright [2011] [wisemapping]
|
||||||
*
|
*
|
||||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
* "powered by wisemapping" text requirement on every single page;
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the license at
|
* You may obtain a copy of the license at
|
||||||
*
|
*
|
||||||
* http://www.wisemapping.org/license
|
* http://www.wisemapping.org/license
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.wisemapping.importer.freemind;
|
package com.wisemapping.importer.freemind;
|
||||||
|
|
||||||
import com.sun.org.apache.xerces.internal.dom.TextImpl;
|
import com.sun.org.apache.xerces.internal.dom.TextImpl;
|
||||||
import com.wisemapping.importer.Importer;
|
import com.wisemapping.importer.Importer;
|
||||||
import com.wisemapping.importer.ImporterException;
|
import com.wisemapping.importer.ImporterException;
|
||||||
import com.wisemapping.model.MindMap;
|
import com.wisemapping.model.MindMap;
|
||||||
import com.wisemapping.model.ShapeStyle;
|
import com.wisemapping.model.ShapeStyle;
|
||||||
import com.wisemapping.model.MindMapNative;
|
import com.wisemapping.model.MindMapNative;
|
||||||
import com.wisemapping.util.JAXBUtils;
|
import com.wisemapping.util.JAXBUtils;
|
||||||
import com.wisemapping.xml.freemind.*;
|
import com.wisemapping.xml.freemind.*;
|
||||||
import com.wisemapping.xml.freemind.Map;
|
import com.wisemapping.xml.freemind.Map;
|
||||||
import com.wisemapping.xml.freemind.Node;
|
import com.wisemapping.xml.freemind.Node;
|
||||||
import com.wisemapping.xml.mindmap.RelationshipType;
|
import com.wisemapping.xml.mindmap.RelationshipType;
|
||||||
import com.wisemapping.xml.mindmap.TopicType;
|
import com.wisemapping.xml.mindmap.TopicType;
|
||||||
import com.wisemapping.xml.mindmap.Link;
|
import com.wisemapping.xml.mindmap.Link;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.w3c.dom.*;
|
import org.w3c.dom.*;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
public class FreemindImporter
|
public class FreemindImporter
|
||||||
implements Importer {
|
implements Importer {
|
||||||
|
|
||||||
private com.wisemapping.xml.mindmap.ObjectFactory mindmapObjectFactory;
|
private com.wisemapping.xml.mindmap.ObjectFactory mindmapObjectFactory;
|
||||||
private static final String POSITION_LEFT = "left";
|
private static final String POSITION_LEFT = "left";
|
||||||
private static final String BOLD = "bold";
|
private static final String BOLD = "bold";
|
||||||
private static final String ITALIC = "italic";
|
private static final String ITALIC = "italic";
|
||||||
private static final String EMPTY_NOTE = "";
|
private static final String EMPTY_NOTE = "";
|
||||||
private java.util.Map<String, TopicType> nodesMap = null;
|
private java.util.Map<String, TopicType> nodesMap = null;
|
||||||
private List<RelationshipType> relationships = null;
|
private List<RelationshipType> relationships = null;
|
||||||
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
||||||
|
|
||||||
private int currentId;
|
private int currentId;
|
||||||
|
|
||||||
public MindMap importMap(String mapName, String description, InputStream input) throws ImporterException {
|
public MindMap importMap(String mapName, String description, InputStream input) throws ImporterException {
|
||||||
|
|
||||||
final MindMap map;
|
final MindMap map;
|
||||||
mindmapObjectFactory = new com.wisemapping.xml.mindmap.ObjectFactory();
|
mindmapObjectFactory = new com.wisemapping.xml.mindmap.ObjectFactory();
|
||||||
try {
|
try {
|
||||||
final Map freemindMap = (Map) JAXBUtils.getMapObject(input, "com.wisemapping.xml.freemind");
|
final Map freemindMap = (Map) JAXBUtils.getMapObject(input, "com.wisemapping.xml.freemind");
|
||||||
|
|
||||||
final com.wisemapping.xml.mindmap.Map mindmapMap = mindmapObjectFactory.createMap();
|
final com.wisemapping.xml.mindmap.Map mindmapMap = mindmapObjectFactory.createMap();
|
||||||
mindmapMap.setVersion("pela");
|
mindmapMap.setVersion("pela");
|
||||||
currentId = 0;
|
currentId = 0;
|
||||||
|
|
||||||
final Node centralNode = freemindMap.getNode();
|
final Node centralNode = freemindMap.getNode();
|
||||||
final TopicType centralTopic = mindmapObjectFactory.createTopicType();
|
final TopicType centralTopic = mindmapObjectFactory.createTopicType();
|
||||||
centralTopic.setId(String.valueOf(currentId++));
|
centralTopic.setId(String.valueOf(currentId++));
|
||||||
centralTopic.setCentral(true);
|
centralTopic.setCentral(true);
|
||||||
|
|
||||||
setNodePropertiesToTopic(centralTopic, centralNode);
|
setNodePropertiesToTopic(centralTopic, centralNode);
|
||||||
centralTopic.setShape(ShapeStyle.ELIPSE.getStyle());
|
centralTopic.setShape(ShapeStyle.ELIPSE.getStyle());
|
||||||
mindmapMap.getTopic().add(centralTopic);
|
mindmapMap.getTopic().add(centralTopic);
|
||||||
mindmapMap.setName(mapName);
|
mindmapMap.setName(mapName);
|
||||||
nodesMap = new HashMap<String, TopicType>();
|
|
||||||
relationships = new ArrayList<RelationshipType>();
|
nodesMap = new HashMap<String, TopicType>();
|
||||||
nodesMap.put(centralNode.getID(), centralTopic);
|
relationships = new ArrayList<RelationshipType>();
|
||||||
addTopicFromNode(centralNode, centralTopic);
|
nodesMap.put(centralNode.getID(), centralTopic);
|
||||||
fixCentralTopicChildOrder(centralTopic);
|
addTopicFromNode(centralNode, centralTopic);
|
||||||
|
fixCentralTopicChildOrder(centralTopic);
|
||||||
addRelationships(mindmapMap);
|
|
||||||
|
addRelationships(mindmapMap);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
JAXBUtils.saveMap(mindmapMap, out, "com.wisemapping.xml.mindmap");
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
JAXBUtils.saveMap(mindmapMap, out, "com.wisemapping.xml.mindmap");
|
||||||
map = new MindMap();
|
|
||||||
map.setNativeXml(new String(out.toByteArray(), Charset.forName("UTF-8")));
|
map = new MindMap();
|
||||||
map.setTitle(mapName);
|
map.setNativeXml(new String(out.toByteArray(), Charset.forName("UTF-8")));
|
||||||
map.setDescription(description);
|
map.setTitle(mapName);
|
||||||
map.setNativeBrowser(new MindMapNative());
|
map.setDescription(description);
|
||||||
|
map.setNativeBrowser(new MindMapNative());
|
||||||
} catch (JAXBException e) {
|
|
||||||
throw new ImporterException(e);
|
} catch (JAXBException e) {
|
||||||
} catch (IOException e) {
|
throw new ImporterException(e);
|
||||||
throw new ImporterException(e);
|
} catch (IOException e) {
|
||||||
}
|
throw new ImporterException(e);
|
||||||
|
}
|
||||||
return map;
|
|
||||||
}
|
return map;
|
||||||
|
}
|
||||||
private void addRelationships(com.wisemapping.xml.mindmap.Map mindmapMap) {
|
|
||||||
List<RelationshipType> mapRelationships = mindmapMap.getRelationship();
|
private void addRelationships(com.wisemapping.xml.mindmap.Map mindmapMap) {
|
||||||
for (RelationshipType relationship : relationships) {
|
List<RelationshipType> mapRelationships = mindmapMap.getRelationship();
|
||||||
relationship.setId(String.valueOf(currentId++));
|
for (RelationshipType relationship : relationships) {
|
||||||
|
relationship.setId(String.valueOf(currentId++));
|
||||||
fixRelationshipControlPoints(relationship);
|
|
||||||
|
fixRelationshipControlPoints(relationship);
|
||||||
//Fix dest ID
|
|
||||||
String destId = relationship.getDestTopicId();
|
//Fix dest ID
|
||||||
TopicType destTopic = nodesMap.get(destId);
|
String destId = relationship.getDestTopicId();
|
||||||
relationship.setDestTopicId(destTopic.getId());
|
TopicType destTopic = nodesMap.get(destId);
|
||||||
//Fix src ID
|
relationship.setDestTopicId(destTopic.getId());
|
||||||
String srcId = relationship.getSrcTopicId();
|
//Fix src ID
|
||||||
TopicType srcTopic = nodesMap.get(srcId);
|
String srcId = relationship.getSrcTopicId();
|
||||||
relationship.setSrcTopicId(srcTopic.getId());
|
TopicType srcTopic = nodesMap.get(srcId);
|
||||||
|
relationship.setSrcTopicId(srcTopic.getId());
|
||||||
mapRelationships.add(relationship);
|
|
||||||
}
|
mapRelationships.add(relationship);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void fixRelationshipControlPoints(RelationshipType relationship) {
|
|
||||||
//Both relationship node's ids should be freemind ones at this point.
|
private void fixRelationshipControlPoints(RelationshipType relationship) {
|
||||||
TopicType srcTopic = nodesMap.get(relationship.getSrcTopicId());
|
//Both relationship node's ids should be freemind ones at this point.
|
||||||
TopicType destTopicType = nodesMap.get(relationship.getDestTopicId());
|
TopicType srcTopic = nodesMap.get(relationship.getSrcTopicId());
|
||||||
|
TopicType destTopicType = nodesMap.get(relationship.getDestTopicId());
|
||||||
//Fix x coord
|
|
||||||
if (isOnLeftSide(srcTopic)) {
|
//Fix x coord
|
||||||
String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(",");
|
if (isOnLeftSide(srcTopic)) {
|
||||||
int x = Integer.valueOf(srcCtrlPoint[0]) * -1;
|
String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(",");
|
||||||
relationship.setSrcCtrlPoint(x + "," + srcCtrlPoint[1]);
|
int x = Integer.valueOf(srcCtrlPoint[0]) * -1;
|
||||||
}
|
relationship.setSrcCtrlPoint(x + "," + srcCtrlPoint[1]);
|
||||||
if (isOnLeftSide(destTopicType)) {
|
}
|
||||||
String[] destCtrlPoint = relationship.getDestCtrlPoint().split(",");
|
if (isOnLeftSide(destTopicType)) {
|
||||||
int x = Integer.valueOf(destCtrlPoint[0]) * -1;
|
String[] destCtrlPoint = relationship.getDestCtrlPoint().split(",");
|
||||||
relationship.setDestCtrlPoint(x + "," + destCtrlPoint[1]);
|
int x = Integer.valueOf(destCtrlPoint[0]) * -1;
|
||||||
}
|
relationship.setDestCtrlPoint(x + "," + destCtrlPoint[1]);
|
||||||
|
}
|
||||||
//Fix y coord
|
|
||||||
if (srcTopic.getOrder() % 2 != 0) { //Odd order.
|
//Fix y coord
|
||||||
String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(",");
|
if (srcTopic.getOrder() % 2 != 0) { //Odd order.
|
||||||
int y = Integer.valueOf(srcCtrlPoint[1]) * -1;
|
String[] srcCtrlPoint = relationship.getSrcCtrlPoint().split(",");
|
||||||
relationship.setSrcCtrlPoint(srcCtrlPoint[0] + "," + y);
|
int y = Integer.valueOf(srcCtrlPoint[1]) * -1;
|
||||||
}
|
relationship.setSrcCtrlPoint(srcCtrlPoint[0] + "," + y);
|
||||||
if (destTopicType.getOrder() % 2 != 0) { //Odd order.
|
}
|
||||||
String[] destCtrlPoint = relationship.getDestCtrlPoint().split(",");
|
if (destTopicType.getOrder() % 2 != 0) { //Odd order.
|
||||||
int y = Integer.valueOf(destCtrlPoint[1]) * -1;
|
String[] destCtrlPoint = relationship.getDestCtrlPoint().split(",");
|
||||||
relationship.setDestCtrlPoint(destCtrlPoint[0] + "," + y);
|
int y = Integer.valueOf(destCtrlPoint[1]) * -1;
|
||||||
}
|
relationship.setDestCtrlPoint(destCtrlPoint[0] + "," + y);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
private void fixCentralTopicChildOrder(TopicType centralTopic) {
|
|
||||||
List<TopicType> topics = centralTopic.getTopic();
|
private void fixCentralTopicChildOrder(TopicType centralTopic) {
|
||||||
List<TopicType> leftTopics = new ArrayList<TopicType>();
|
List<TopicType> topics = centralTopic.getTopic();
|
||||||
List<TopicType> rightTopics = new ArrayList<TopicType>();
|
List<TopicType> leftTopics = new ArrayList<TopicType>();
|
||||||
|
List<TopicType> rightTopics = new ArrayList<TopicType>();
|
||||||
for (TopicType topic : topics) {
|
|
||||||
if (isOnLeftSide(topic)) {
|
for (TopicType topic : topics) {
|
||||||
leftTopics.add(topic);
|
if (isOnLeftSide(topic)) {
|
||||||
} else {
|
leftTopics.add(topic);
|
||||||
rightTopics.add(topic);
|
} else {
|
||||||
}
|
rightTopics.add(topic);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (leftTopics.size() > 0) {
|
|
||||||
int size = leftTopics.size();
|
if (leftTopics.size() > 0) {
|
||||||
int index = 0;
|
int size = leftTopics.size();
|
||||||
int center = size / 2;
|
int index = 0;
|
||||||
if (size % 2 == 0) { //Even number, then place middle point in 1 index
|
int center = size / 2;
|
||||||
index = 1;
|
if (size % 2 == 0) { //Even number, then place middle point in 1 index
|
||||||
center--;
|
index = 1;
|
||||||
}
|
center--;
|
||||||
int index2 = index;
|
}
|
||||||
|
int index2 = index;
|
||||||
leftTopics.get(center).setOrder(index);
|
|
||||||
for (int i = center - 1; i >= 0; i--) {
|
leftTopics.get(center).setOrder(index);
|
||||||
if (index == 0) {
|
for (int i = center - 1; i >= 0; i--) {
|
||||||
index++;
|
if (index == 0) {
|
||||||
} else {
|
index++;
|
||||||
index += 2;
|
} else {
|
||||||
}
|
index += 2;
|
||||||
leftTopics.get(i).setOrder(index);
|
}
|
||||||
}
|
leftTopics.get(i).setOrder(index);
|
||||||
index = index2;
|
}
|
||||||
for (int i = center + 1; i < size; i++) {
|
index = index2;
|
||||||
if (index == 1) {
|
for (int i = center + 1; i < size; i++) {
|
||||||
index++;
|
if (index == 1) {
|
||||||
} else {
|
index++;
|
||||||
index += 2;
|
} else {
|
||||||
}
|
index += 2;
|
||||||
leftTopics.get(i).setOrder(index);
|
}
|
||||||
}
|
leftTopics.get(i).setOrder(index);
|
||||||
}
|
}
|
||||||
if (rightTopics.size() > 0) {
|
}
|
||||||
int size = rightTopics.size();
|
if (rightTopics.size() > 0) {
|
||||||
int index = 0;
|
int size = rightTopics.size();
|
||||||
int center = size / 2;
|
int index = 0;
|
||||||
if (size % 2 == 0) { //Even number, then place middle point in 1 index
|
int center = size / 2;
|
||||||
index = 1;
|
if (size % 2 == 0) { //Even number, then place middle point in 1 index
|
||||||
center--;
|
index = 1;
|
||||||
}
|
center--;
|
||||||
int index2 = index;
|
}
|
||||||
rightTopics.get(center).setOrder(index);
|
int index2 = index;
|
||||||
for (int i = center - 1; i >= 0; i--) {
|
rightTopics.get(center).setOrder(index);
|
||||||
if (index == 0) {
|
for (int i = center - 1; i >= 0; i--) {
|
||||||
index++;
|
if (index == 0) {
|
||||||
} else {
|
index++;
|
||||||
index += 2;
|
} else {
|
||||||
}
|
index += 2;
|
||||||
rightTopics.get(i).setOrder(index);
|
}
|
||||||
}
|
rightTopics.get(i).setOrder(index);
|
||||||
index = index2;
|
}
|
||||||
for (int i = center + 1; i < size; i++) {
|
index = index2;
|
||||||
if (index == 1) {
|
for (int i = center + 1; i < size; i++) {
|
||||||
index++;
|
if (index == 1) {
|
||||||
} else {
|
index++;
|
||||||
index += 2;
|
} else {
|
||||||
}
|
index += 2;
|
||||||
rightTopics.get(i).setOrder(index);
|
}
|
||||||
}
|
rightTopics.get(i).setOrder(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private boolean isOnLeftSide(TopicType topic) {
|
|
||||||
String[] position = topic.getPosition().split(",");
|
private boolean isOnLeftSide(TopicType topic) {
|
||||||
int x = Integer.parseInt(position[0]);
|
String[] position = topic.getPosition().split(",");
|
||||||
return x < 0;
|
int x = Integer.parseInt(position[0]);
|
||||||
}
|
return x < 0;
|
||||||
|
}
|
||||||
private void addTopicFromNode(Node mainNode, TopicType topic) {
|
|
||||||
final List<Object> freemindNodes = mainNode.getArrowlinkOrCloudOrEdge();
|
private void addTopicFromNode(@NotNull Node mainNode, @NotNull TopicType topic) {
|
||||||
TopicType currentTopic = topic;
|
final List<Object> freemindNodes = mainNode.getArrowlinkOrCloudOrEdge();
|
||||||
int order = 0;
|
TopicType currentTopic = topic;
|
||||||
for (Object freemindNode : freemindNodes) {
|
int order = 0;
|
||||||
|
for (Object freemindNode : freemindNodes) {
|
||||||
if (freemindNode instanceof Node) {
|
|
||||||
final Node node = (Node) freemindNode;
|
if (freemindNode instanceof Node) {
|
||||||
TopicType newTopic = mindmapObjectFactory.createTopicType();
|
final Node node = (Node) freemindNode;
|
||||||
newTopic.setId(String.valueOf(currentId++));
|
TopicType newTopic = mindmapObjectFactory.createTopicType();
|
||||||
nodesMap.put(node.getID(), newTopic); //Lets use freemind id temporarily. This will be fixed when adding relationship to the map.
|
newTopic.setId(String.valueOf(currentId++));
|
||||||
newTopic.setOrder(order++);
|
nodesMap.put(node.getID(), newTopic); //Lets use freemind id temporarily. This will be fixed when adding relationship to the map.
|
||||||
String url = node.getLINK();
|
newTopic.setOrder(order++);
|
||||||
if (url != null) {
|
|
||||||
final Link link = new Link();
|
// Is there any link ?
|
||||||
link.setUrl(url);
|
final String url = node.getLINK();
|
||||||
newTopic.setLink(link);
|
if (url != null) {
|
||||||
}
|
final Link link = new Link();
|
||||||
if (POSITION_LEFT.equals(mainNode.getPOSITION())) {
|
link.setUrl(url);
|
||||||
node.setPOSITION(POSITION_LEFT);
|
newTopic.setLink(link);
|
||||||
}
|
}
|
||||||
setNodePropertiesToTopic(newTopic, node);
|
|
||||||
addTopicFromNode(node, newTopic);
|
if (POSITION_LEFT.equals(mainNode.getPOSITION())) {
|
||||||
if (!newTopic.equals(topic)) {
|
node.setPOSITION(POSITION_LEFT);
|
||||||
topic.getTopic().add(newTopic);
|
}
|
||||||
}
|
|
||||||
currentTopic = newTopic;
|
setNodePropertiesToTopic(newTopic, node);
|
||||||
} else if (freemindNode instanceof Font) {
|
addTopicFromNode(node, newTopic);
|
||||||
final Font font = (Font) freemindNode;
|
if (!newTopic.equals(topic)) {
|
||||||
final String fontStyle = generateFontStyle(mainNode, font);
|
topic.getTopic().add(newTopic);
|
||||||
if (fontStyle!=null) {
|
}
|
||||||
currentTopic.setFontStyle(fontStyle);
|
currentTopic = newTopic;
|
||||||
}
|
|
||||||
} else if (freemindNode instanceof Edge) {
|
} else if (freemindNode instanceof Font) {
|
||||||
final Edge edge = (Edge) freemindNode;
|
final Font font = (Font) freemindNode;
|
||||||
currentTopic.setBrColor(edge.getCOLOR());
|
final String fontStyle = generateFontStyle(mainNode, font);
|
||||||
} else if (freemindNode instanceof Icon) {
|
if (fontStyle != null) {
|
||||||
final Icon freemindIcon = (Icon) freemindNode;
|
currentTopic.setFontStyle(fontStyle);
|
||||||
|
}
|
||||||
String iconId = freemindIcon.getBUILTIN();
|
} else if (freemindNode instanceof Edge) {
|
||||||
final String wiseIconId = FreemindIconConverter.toWiseId(iconId);
|
final Edge edge = (Edge) freemindNode;
|
||||||
if (wiseIconId != null) {
|
currentTopic.setBrColor(edge.getCOLOR());
|
||||||
final com.wisemapping.xml.mindmap.Icon mindmapIcon = new com.wisemapping.xml.mindmap.Icon();
|
} else if (freemindNode instanceof Icon) {
|
||||||
mindmapIcon.setId(wiseIconId);
|
final Icon freemindIcon = (Icon) freemindNode;
|
||||||
currentTopic.getIcon().add(mindmapIcon);
|
|
||||||
}
|
String iconId = freemindIcon.getBUILTIN();
|
||||||
|
final String wiseIconId = FreemindIconConverter.toWiseId(iconId);
|
||||||
} else if (freemindNode instanceof Hook) {
|
if (wiseIconId != null) {
|
||||||
final Hook hook = (Hook) freemindNode;
|
final com.wisemapping.xml.mindmap.Icon mindmapIcon = new com.wisemapping.xml.mindmap.Icon();
|
||||||
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
|
mindmapIcon.setId(wiseIconId);
|
||||||
String textNote = hook.getText();
|
currentTopic.getIcon().add(mindmapIcon);
|
||||||
if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook
|
}
|
||||||
{
|
|
||||||
textNote = EMPTY_NOTE;
|
} else if (freemindNode instanceof Hook) {
|
||||||
mindmapNote.setText(textNote);
|
final Hook hook = (Hook) freemindNode;
|
||||||
currentTopic.setNote(mindmapNote);
|
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
|
||||||
}
|
String textNote = hook.getText();
|
||||||
} else if (freemindNode instanceof Richcontent) {
|
if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook
|
||||||
final Richcontent content = (Richcontent) freemindNode;
|
{
|
||||||
final String type = content.getTYPE();
|
textNote = EMPTY_NOTE;
|
||||||
|
mindmapNote.setText(textNote);
|
||||||
if (type.equals("NODE")) {
|
currentTopic.setNote(mindmapNote);
|
||||||
String text = getText(content);
|
}
|
||||||
text = text.replaceAll("\n", "");
|
} else if (freemindNode instanceof Richcontent) {
|
||||||
text = text.trim();
|
final Richcontent content = (Richcontent) freemindNode;
|
||||||
currentTopic.setText(text);
|
final String type = content.getTYPE();
|
||||||
} else {
|
|
||||||
String text = getRichContent(content);
|
if (type.equals("NODE")) {
|
||||||
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
|
String text = getText(content);
|
||||||
text = text != null ? text.replaceAll("\n", "%0A") : EMPTY_NOTE;
|
text = text.replaceAll("\n", "");
|
||||||
mindmapNote.setText(text);
|
text = text.trim();
|
||||||
currentTopic.setNote(mindmapNote);
|
currentTopic.setText(text);
|
||||||
|
} else {
|
||||||
}
|
String text = getRichContent(content);
|
||||||
} else if (freemindNode instanceof Arrowlink) {
|
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
|
||||||
final Arrowlink arrow = (Arrowlink) freemindNode;
|
text = text != null ? text.replaceAll("\n", "%0A") : EMPTY_NOTE;
|
||||||
RelationshipType relationship = mindmapObjectFactory.createRelationshipType();
|
mindmapNote.setText(text);
|
||||||
String destId = arrow.getDESTINATION();
|
currentTopic.setNote(mindmapNote);
|
||||||
relationship.setSrcTopicId(mainNode.getID());
|
|
||||||
relationship.setDestTopicId(destId);
|
}
|
||||||
String[] inclination = arrow.getENDINCLINATION().split(";");
|
} else if (freemindNode instanceof Arrowlink) {
|
||||||
relationship.setDestCtrlPoint(inclination[0] + "," + inclination[1]);
|
final Arrowlink arrow = (Arrowlink) freemindNode;
|
||||||
inclination = arrow.getSTARTINCLINATION().split(";");
|
RelationshipType relationship = mindmapObjectFactory.createRelationshipType();
|
||||||
relationship.setSrcCtrlPoint(inclination[0] + "," + inclination[1]);
|
String destId = arrow.getDESTINATION();
|
||||||
//relationship.setCtrlPointRelative(true);
|
relationship.setSrcTopicId(mainNode.getID());
|
||||||
relationship.setEndArrow(!arrow.getENDARROW().toLowerCase().equals("none"));
|
relationship.setDestTopicId(destId);
|
||||||
relationship.setStartArrow(!arrow.getSTARTARROW().toLowerCase().equals("none"));
|
String[] inclination = arrow.getENDINCLINATION().split(";");
|
||||||
relationship.setLineType("3");
|
relationship.setDestCtrlPoint(inclination[0] + "," + inclination[1]);
|
||||||
relationships.add(relationship);
|
inclination = arrow.getSTARTINCLINATION().split(";");
|
||||||
}
|
relationship.setSrcCtrlPoint(inclination[0] + "," + inclination[1]);
|
||||||
}
|
//relationship.setCtrlPointRelative(true);
|
||||||
}
|
relationship.setEndArrow(!arrow.getENDARROW().toLowerCase().equals("none"));
|
||||||
|
relationship.setStartArrow(!arrow.getSTARTARROW().toLowerCase().equals("none"));
|
||||||
private String getRichContent(Richcontent content) {
|
relationship.setLineType("3");
|
||||||
String result = null;
|
relationships.add(relationship);
|
||||||
List<Element> elementList = content.getHtml().getAny();
|
}
|
||||||
|
}
|
||||||
Element body = null;
|
}
|
||||||
for (Element elem : elementList) {
|
|
||||||
if (elem.getNodeName().equals("body")) {
|
private String getRichContent(Richcontent content) {
|
||||||
body = elem;
|
String result = null;
|
||||||
break;
|
List<Element> elementList = content.getHtml().getAny();
|
||||||
}
|
|
||||||
}
|
Element body = null;
|
||||||
if (body != null) {
|
for (Element elem : elementList) {
|
||||||
result = body.getTextContent();
|
if (elem.getNodeName().equals("body")) {
|
||||||
}
|
body = elem;
|
||||||
return result;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private String getText(Richcontent content) {
|
if (body != null) {
|
||||||
String result = "";
|
result = body.getTextContent();
|
||||||
List<Element> elementList = content.getHtml().getAny();
|
}
|
||||||
|
return result;
|
||||||
Element body = null;
|
}
|
||||||
for (Element elem : elementList) {
|
|
||||||
if (elem.getNodeName().equals("body")) {
|
private String getText(Richcontent content) {
|
||||||
body = elem;
|
String result = "";
|
||||||
break;
|
List<Element> elementList = content.getHtml().getAny();
|
||||||
}
|
|
||||||
}
|
Element body = null;
|
||||||
if (body != null) {
|
for (Element elem : elementList) {
|
||||||
String textNode = buildTextFromChildren(body);
|
if (elem.getNodeName().equals("body")) {
|
||||||
if (textNode != null)
|
body = elem;
|
||||||
result = textNode.trim();
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
if (body != null) {
|
||||||
}
|
String textNode = buildTextFromChildren(body);
|
||||||
|
if (textNode != null)
|
||||||
private String buildTextFromChildren(org.w3c.dom.Node body) {
|
result = textNode.trim();
|
||||||
StringBuilder text = new StringBuilder();
|
|
||||||
NodeList childNodes = body.getChildNodes();
|
}
|
||||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
return result;
|
||||||
org.w3c.dom.Node child = childNodes.item(i);
|
}
|
||||||
if (child instanceof TextImpl) {
|
|
||||||
text.append(" ");
|
private String buildTextFromChildren(org.w3c.dom.Node body) {
|
||||||
text.append(child.getTextContent());
|
StringBuilder text = new StringBuilder();
|
||||||
} else {
|
NodeList childNodes = body.getChildNodes();
|
||||||
String textElem = buildTextFromChildren(child);
|
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||||
if (textElem != null && !textElem.equals("")) {
|
org.w3c.dom.Node child = childNodes.item(i);
|
||||||
text.append(textElem);
|
if (child instanceof TextImpl) {
|
||||||
}
|
text.append(" ");
|
||||||
}
|
text.append(child.getTextContent());
|
||||||
}
|
} else {
|
||||||
return text.toString();
|
String textElem = buildTextFromChildren(child);
|
||||||
}
|
if (textElem != null && !textElem.equals("")) {
|
||||||
|
text.append(textElem);
|
||||||
private void setNodePropertiesToTopic(com.wisemapping.xml.mindmap.TopicType mindmapTopic, com.wisemapping.xml.freemind.Node freemindNode) {
|
}
|
||||||
mindmapTopic.setText(freemindNode.getTEXT());
|
}
|
||||||
mindmapTopic.setBgColor(freemindNode.getBACKGROUNDCOLOR());
|
}
|
||||||
|
return text.toString();
|
||||||
final String shape = getShapeFormFromNode(freemindNode);
|
}
|
||||||
mindmapTopic.setShape(shape);
|
|
||||||
int pos = 1;
|
private void setNodePropertiesToTopic(@NotNull com.wisemapping.xml.mindmap.TopicType wiseTopic, @NotNull com.wisemapping.xml.freemind.Node freemindNode) {
|
||||||
if (POSITION_LEFT.equals(freemindNode.getPOSITION())) {
|
wiseTopic.setText(freemindNode.getTEXT());
|
||||||
pos = -1;
|
wiseTopic.setBgColor(freemindNode.getBACKGROUNDCOLOR());
|
||||||
}
|
|
||||||
Integer orderPosition = mindmapTopic.getOrder() != null ? mindmapTopic.getOrder() : 0;
|
final String shape = getShapeFormFromNode(freemindNode);
|
||||||
int position = pos * 200 + (orderPosition + 1) * 10;
|
wiseTopic.setShape(shape);
|
||||||
|
int pos = 1;
|
||||||
mindmapTopic.setPosition(position + "," + 200 * orderPosition);
|
if (POSITION_LEFT.equals(freemindNode.getPOSITION())) {
|
||||||
final String fontStyle = generateFontStyle(freemindNode, null);
|
pos = -1;
|
||||||
if (fontStyle!=null) {
|
}
|
||||||
mindmapTopic.setFontStyle(fontStyle);
|
Integer orderPosition = wiseTopic.getOrder() != null ? wiseTopic.getOrder() : 0;
|
||||||
}
|
int position = pos * 200 + (orderPosition + 1) * 10;
|
||||||
Boolean folded = Boolean.valueOf(freemindNode.getFOLDED());
|
|
||||||
if (folded) {
|
wiseTopic.setPosition(position + "," + 200 * orderPosition);
|
||||||
mindmapTopic.setShrink(folded);
|
final String fontStyle = generateFontStyle(freemindNode, null);
|
||||||
}
|
if (fontStyle != null) {
|
||||||
}
|
wiseTopic.setFontStyle(fontStyle);
|
||||||
|
}
|
||||||
private @Nullable String generateFontStyle(@NotNull Node node, @Nullable Font font) {
|
|
||||||
/*
|
// Is there any link ?
|
||||||
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
final String url = freemindNode.getLINK();
|
||||||
* eg: Verdana;10;#ffffff;bold;italic;
|
if (url != null) {
|
||||||
*
|
final Link link = new Link();
|
||||||
*/
|
link.setUrl(url);
|
||||||
|
wiseTopic.setLink(link);
|
||||||
// Font name ...
|
}
|
||||||
final StringBuilder fontStyle = new StringBuilder();
|
|
||||||
if (font != null) {
|
final Boolean folded = Boolean.valueOf(freemindNode.getFOLDED());
|
||||||
fontStyle.append(fixFontName(font));
|
if (folded) {
|
||||||
}
|
wiseTopic.setShrink(folded);
|
||||||
fontStyle.append(";");
|
}
|
||||||
|
|
||||||
// Size ...
|
|
||||||
if (font != null) {
|
}
|
||||||
final BigInteger bigInteger = (font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(8) : font.getSIZE();
|
|
||||||
fontStyle.append(bigInteger);
|
private
|
||||||
}
|
@Nullable
|
||||||
fontStyle.append(";");
|
String generateFontStyle(@NotNull Node node, @Nullable Font font) {
|
||||||
|
/*
|
||||||
// Color ...
|
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
||||||
final String color = node.getCOLOR();
|
* eg: Verdana;10;#ffffff;bold;italic;
|
||||||
if (color != null && !color.equals("")) {
|
*
|
||||||
fontStyle.append(color);
|
*/
|
||||||
}
|
|
||||||
fontStyle.append(";");
|
// Font name ...
|
||||||
|
final StringBuilder fontStyle = new StringBuilder();
|
||||||
// Bold ...
|
if (font != null) {
|
||||||
if (font != null) {
|
fontStyle.append(fixFontName(font));
|
||||||
boolean hasBold = Boolean.parseBoolean(font.getBOLD());
|
}
|
||||||
fontStyle.append(hasBold ? BOLD : "");
|
fontStyle.append(";");
|
||||||
}
|
|
||||||
fontStyle.append(";");
|
// Size ...
|
||||||
|
if (font != null) {
|
||||||
// Italic ...
|
final BigInteger bigInteger = (font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(8) : font.getSIZE();
|
||||||
if (font != null) {
|
fontStyle.append(bigInteger);
|
||||||
boolean hasItalic = Boolean.parseBoolean(font.getITALIC());
|
}
|
||||||
fontStyle.append(hasItalic ? ITALIC : "");
|
fontStyle.append(";");
|
||||||
}
|
|
||||||
fontStyle.append(";");
|
// Color ...
|
||||||
|
final String color = node.getCOLOR();
|
||||||
final String result = fontStyle.toString();
|
if (color != null && !color.equals("")) {
|
||||||
return result.equals(EMPTY_FONT_STYLE) ? null : result;
|
fontStyle.append(color);
|
||||||
}
|
}
|
||||||
|
fontStyle.append(";");
|
||||||
private
|
|
||||||
@NotNull
|
// Bold ...
|
||||||
String fixFontName(@NotNull Font font) {
|
if (font != null) {
|
||||||
String result = com.wisemapping.model.Font.ARIAL.getFontName(); // Default Font
|
boolean hasBold = Boolean.parseBoolean(font.getBOLD());
|
||||||
if (com.wisemapping.model.Font.isValidFont(font.getNAME())) {
|
fontStyle.append(hasBold ? BOLD : "");
|
||||||
result = font.getNAME();
|
}
|
||||||
}
|
fontStyle.append(";");
|
||||||
return result;
|
|
||||||
}
|
// Italic ...
|
||||||
|
if (font != null) {
|
||||||
private String getShapeFormFromNode(Node node) {
|
boolean hasItalic = Boolean.parseBoolean(font.getITALIC());
|
||||||
String shape = node.getSTYLE();
|
fontStyle.append(hasItalic ? ITALIC : "");
|
||||||
// In freemind a node without style is a line
|
}
|
||||||
if ("bubble".equals(shape)) {
|
fontStyle.append(";");
|
||||||
shape = ShapeStyle.ROUNDED_RETAGLE.getStyle();
|
|
||||||
} else {
|
final String result = fontStyle.toString();
|
||||||
shape = ShapeStyle.LINE.getStyle();
|
return result.equals(EMPTY_FONT_STYLE) ? null : result;
|
||||||
}
|
}
|
||||||
return shape;
|
|
||||||
}
|
private
|
||||||
}
|
@NotNull
|
||||||
|
String fixFontName(@NotNull Font font) {
|
||||||
|
String result = com.wisemapping.model.Font.ARIAL.getFontName(); // Default Font
|
||||||
|
if (com.wisemapping.model.Font.isValidFont(font.getNAME())) {
|
||||||
|
result = font.getNAME();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getShapeFormFromNode(Node node) {
|
||||||
|
String shape = node.getSTYLE();
|
||||||
|
// In freemind a node without style is a line
|
||||||
|
if ("bubble".equals(shape)) {
|
||||||
|
shape = ShapeStyle.ROUNDED_RETAGLE.getStyle();
|
||||||
|
} else {
|
||||||
|
shape = ShapeStyle.LINE.getStyle();
|
||||||
|
}
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
<map version="0.9.0">
|
<map version="0.9.0">
|
||||||
<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
|
<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
|
||||||
<node CREATED="1301250606816" ID="ID_189563190" LINK="http://www.google.com" MODIFIED="1301250665708" TEXT="Node Links"/>
|
<node CREATED="1301250606816" ID="ID_189563190" LINK="http://www.google.com" MODIFIED="1301265199448" TEXT="Node Links">
|
||||||
|
<icon BUILTIN="closed"/>
|
||||||
|
<node CREATED="1301265119915" FOLDED="true" ID="ID_955581041" LINK="http://www.bing.com" MODIFIED="1301265556534" POSITION="right" TEXT="Link Topic">
|
||||||
|
<icon BUILTIN="info"/>
|
||||||
|
<node CREATED="1301265126777" ID="ID_1127858248" LINK="http://bing.com" MODIFIED="1301265269136" TEXT="Link Topic Topic">
|
||||||
|
<icon BUILTIN="messagebox_warning"/>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
</map>
|
</map>
|
||||||
|
@ -1 +1 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><map version="0.9.0"><node TEXT="Node Links" STYLE="elipse" ID="ID_0"/></map>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><map version="0.9.0"><node TEXT="Node Links" STYLE="elipse" LINK="http://www.google.com" ID="ID_0"><icon BUILTIN="closed"/><node TEXT="Link Topic" POSITION="right" LINK="http://www.bing.com" ID="ID_1" FOLDED="true"><icon BUILTIN="info"/><node TEXT="Link Topic Topic" POSITION="right" LINK="http://bing.com" ID="ID_2"><icon BUILTIN="messagebox_warning"/></node></node></node></map>
|
Loading…
Reference in New Issue
Block a user