mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-24 23:17:56 +01:00
Remove JAXB, now supporting any version of JAVA
This commit is contained in:
parent
758e18dffc
commit
307d8ea2b8
5
pom.xml
5
pom.xml
@ -79,11 +79,6 @@
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.10</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jvnet.jaxb2.maven2</groupId>
|
||||
<artifactId>maven-jaxb2-plugin</artifactId>
|
||||
<version>0.14.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>yuicompressor-maven-plugin</artifactId>
|
||||
|
@ -258,11 +258,6 @@
|
||||
<version>2.10.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- jsoup HTML parser library @ http://jsoup.org/ -->
|
||||
<groupId>org.jsoup</groupId>
|
||||
@ -512,48 +507,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jvnet.jaxb2.maven2</groupId>
|
||||
<artifactId>maven-jaxb2-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>mindmap-generate</id>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<schemaDirectory>src/main/resources/</schemaDirectory>
|
||||
<schemaIncludes>
|
||||
<include>mindmap.xsd</include>
|
||||
</schemaIncludes>
|
||||
<bindingDirectory>src/main/resources/</bindingDirectory>
|
||||
<bindingIncludes>
|
||||
<include>mindmap.xjb</include>
|
||||
</bindingIncludes>
|
||||
<generatePackage>com.wisemapping.jaxb.wisemap</generatePackage>
|
||||
<generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>freemind-generate</id>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<schemaDirectory>src/main/resources/</schemaDirectory>
|
||||
<schemaIncludes>
|
||||
<include>freemind_0.9.0.xsd</include>
|
||||
</schemaIncludes>
|
||||
<bindingDirectory>src/main/resources/</bindingDirectory>
|
||||
<bindingIncludes>
|
||||
<include>freemind_0.9.0.xjb</include>
|
||||
</bindingIncludes>
|
||||
<generatePackage>com.wisemapping.jaxb.freemind</generatePackage>
|
||||
<generateDirectory>${project.build.directory}/generated-sources/xjc2</generateDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
public class ExportException
|
||||
extends Exception
|
||||
{
|
||||
public ExportException(Throwable e)
|
||||
{
|
||||
super(e);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface Exporter {
|
||||
void export(@NotNull byte[] xml, @NotNull OutputStream outputStream) throws ExportException;
|
||||
void export(Mindmap map, OutputStream outputStream) throws ExportException;
|
||||
}
|
@ -1,375 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
|
||||
import com.wisemapping.importer.VersionNumber;
|
||||
import com.wisemapping.importer.freemind.FreemindConstant;
|
||||
import com.wisemapping.importer.freemind.FreemindIconConverter;
|
||||
import com.wisemapping.jaxb.freemind.*;
|
||||
import com.wisemapping.jaxb.wisemap.Icon;
|
||||
import com.wisemapping.jaxb.wisemap.Note;
|
||||
import com.wisemapping.jaxb.wisemap.RelationshipType;
|
||||
import com.wisemapping.jaxb.wisemap.TopicType;
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import com.wisemapping.model.ShapeStyle;
|
||||
import com.wisemapping.util.JAXBUtils;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FreemindExporter
|
||||
implements Exporter {
|
||||
|
||||
|
||||
private com.wisemapping.jaxb.freemind.ObjectFactory objectFactory;
|
||||
private Map<String, Node> nodesMap = null;
|
||||
private VersionNumber version = FreemindConstant.SUPPORTED_FREEMIND_VERSION;
|
||||
|
||||
public void export(Mindmap map, OutputStream outputStream) throws ExportException {
|
||||
export(map.getUnzipXml(), outputStream);
|
||||
}
|
||||
|
||||
public void export(@NotNull byte[] xml, @NotNull OutputStream outputStream) throws ExportException {
|
||||
|
||||
objectFactory = new com.wisemapping.jaxb.freemind.ObjectFactory();
|
||||
nodesMap = new HashMap<>();
|
||||
final com.wisemapping.jaxb.wisemap.Map mindmapMap;
|
||||
|
||||
try {
|
||||
final ByteArrayInputStream stream = new ByteArrayInputStream(xml);
|
||||
mindmapMap = (com.wisemapping.jaxb.wisemap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.jaxb.wisemap");
|
||||
|
||||
final com.wisemapping.jaxb.freemind.Map freemindMap = objectFactory.createMap();
|
||||
freemindMap.setVersion(this.getVersionNumber());
|
||||
|
||||
final List<TopicType> topics = mindmapMap.getTopic();
|
||||
|
||||
// Isolated Topic does not exist in Freemind only take the center topic
|
||||
TopicType centerTopic = null;
|
||||
if (topics.size() > 1) {
|
||||
for (TopicType topic : topics) {
|
||||
if (topic.isCentral() != null && topic.isCentral()) {
|
||||
centerTopic = topic;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
centerTopic = topics.get(0);
|
||||
}
|
||||
|
||||
final Node main = objectFactory.createNode();
|
||||
freemindMap.setNode(main);
|
||||
if (centerTopic != null) {
|
||||
nodesMap.put(centerTopic.getId(), main);
|
||||
setTopicPropertiesToNode(main, centerTopic, true);
|
||||
addNodeFromTopic(centerTopic, main);
|
||||
}
|
||||
|
||||
final List<RelationshipType> relationships = mindmapMap.getRelationship();
|
||||
for (RelationshipType relationship : relationships) {
|
||||
// FIXME:invert srcNode and dstNode to correct a bug in the wise mind map representation
|
||||
Node srcNode = nodesMap.get(relationship.getDestTopicId());
|
||||
Node dstNode = nodesMap.get(relationship.getSrcTopicId());
|
||||
|
||||
|
||||
// Workaround for nodes without relationship associated ...
|
||||
if (srcNode != null && dstNode != null) {
|
||||
|
||||
Arrowlink arrowlink = objectFactory.createArrowlink();
|
||||
|
||||
arrowlink.setDESTINATION(dstNode.getID());
|
||||
if (relationship.isEndArrow() != null && relationship.isEndArrow())
|
||||
arrowlink.setENDARROW("Default");
|
||||
|
||||
if (relationship.isStartArrow() != null && relationship.isStartArrow())
|
||||
arrowlink.setSTARTARROW("Default");
|
||||
|
||||
List<Object> cloudOrEdge = srcNode.getArrowlinkOrCloudOrEdge();
|
||||
cloudOrEdge.add(arrowlink);
|
||||
}
|
||||
}
|
||||
|
||||
JAXBUtils.saveMap(freemindMap, outputStream);
|
||||
} catch (JAXBException | SAXException | IOException | ParserConfigurationException e) {
|
||||
throw new ExportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNodeFromTopic(@NotNull final TopicType mainTopic, @NotNull final Node destNode) throws IOException, SAXException, ParserConfigurationException {
|
||||
final List<TopicType> currentTopic = mainTopic.getTopic();
|
||||
|
||||
Collections.sort(currentTopic, new VerticalPositionComparator());
|
||||
for (TopicType topicType : currentTopic) {
|
||||
final Node newNode = objectFactory.createNode();
|
||||
nodesMap.put(topicType.getId(), newNode);
|
||||
|
||||
setTopicPropertiesToNode(newNode, topicType, false);
|
||||
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
||||
|
||||
addNodeFromTopic(topicType, newNode);
|
||||
|
||||
final String position = topicType.getPosition();
|
||||
if (position != null) {
|
||||
String xPos = position.split(",")[0];
|
||||
int x = Integer.valueOf(xPos);
|
||||
newNode.setPOSITION((x < 0 ? FreemindConstant.POSITION_LEFT : FreemindConstant.POSITION_RIGHT));
|
||||
} else {
|
||||
newNode.setPOSITION(FreemindConstant.POSITION_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setTopicPropertiesToNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, @NotNull com.wisemapping.jaxb.wisemap.TopicType mindmapTopic, boolean isRoot) throws IOException, SAXException, ParserConfigurationException {
|
||||
freemindNode.setID("ID_" + mindmapTopic.getId());
|
||||
|
||||
String text = mindmapTopic.getTextAttr();
|
||||
if (text == null || text.isEmpty()) {
|
||||
text = mindmapTopic.getText();
|
||||
}
|
||||
|
||||
// Formated text have a different representation ....
|
||||
if (text != null) {
|
||||
if (!text.contains("\n")) {
|
||||
freemindNode.setTEXT(text);
|
||||
} else {
|
||||
final Richcontent richcontent = buildRichContent(text, "NODE");
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(richcontent);
|
||||
}
|
||||
}
|
||||
|
||||
String wiseShape = mindmapTopic.getShape();
|
||||
if (wiseShape != null && !ShapeStyle.LINE.equals(ShapeStyle.fromValue(wiseShape))) {
|
||||
freemindNode.setBACKGROUNDCOLOR(this.rgbToHex(mindmapTopic.getBgColor()));
|
||||
}
|
||||
final String shape = mindmapTopic.getShape();
|
||||
if (shape != null && !shape.isEmpty()) {
|
||||
if (isRoot && !ShapeStyle.ROUNDED_RECTANGLE.getStyle().endsWith(shape) || !isRoot && !ShapeStyle.LINE.getStyle().endsWith(shape)) {
|
||||
|
||||
String style = shape;
|
||||
if (ShapeStyle.ROUNDED_RECTANGLE.getStyle().equals(shape) || ShapeStyle.ELLIPSE.getStyle().equals(shape)) {
|
||||
style = "bubble";
|
||||
}
|
||||
freemindNode.setSTYLE(style);
|
||||
}
|
||||
} else if (!isRoot) {
|
||||
String style = "fork";
|
||||
freemindNode.setSTYLE(style);
|
||||
}
|
||||
|
||||
addIconNode(freemindNode, mindmapTopic);
|
||||
addLinkNode(freemindNode, mindmapTopic);
|
||||
addFontNode(freemindNode, mindmapTopic);
|
||||
addEdgeNode(freemindNode, mindmapTopic);
|
||||
addNote(freemindNode, mindmapTopic);
|
||||
|
||||
Boolean shrink = mindmapTopic.isShrink();
|
||||
if (shrink != null && shrink)
|
||||
freemindNode.setFOLDED(String.valueOf(shrink));
|
||||
|
||||
}
|
||||
|
||||
private Richcontent buildRichContent(final String text, final String type) throws ParserConfigurationException, SAXException, IOException {
|
||||
final Richcontent richcontent = objectFactory.createRichcontent();
|
||||
richcontent.setTYPE(type);
|
||||
|
||||
final StringBuilder htmlContent = new StringBuilder("<html><head></head><body>");
|
||||
for (String line : text.split("\n")) {
|
||||
line = StringEscapeUtils.escapeXml(line);
|
||||
htmlContent.append("<p>").append(line.trim()).append("</p>");
|
||||
}
|
||||
htmlContent.append("</body></html>");
|
||||
|
||||
DocumentBuilder db = getInstanceBuilder();
|
||||
byte[] bytes = htmlContent.toString().getBytes(StandardCharsets.UTF_8);
|
||||
Document document = db.parse(new ByteArrayInputStream(bytes), "UTF-8");
|
||||
richcontent.setHtml(document.getDocumentElement());
|
||||
return richcontent;
|
||||
}
|
||||
|
||||
private DocumentBuilder getInstanceBuilder() throws ParserConfigurationException {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
return dbf.newDocumentBuilder();
|
||||
}
|
||||
|
||||
private void addNote(com.wisemapping.jaxb.freemind.Node fnode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) throws IOException, SAXException, ParserConfigurationException {
|
||||
final Note note = mindmapTopic.getNote();
|
||||
if (note != null) {
|
||||
final String noteStr = note.getValue() != null ? note.getValue() : note.getTextAttr();
|
||||
if (noteStr != null) {
|
||||
final Richcontent richcontent = buildRichContent(noteStr, "NOTE");
|
||||
fnode.getArrowlinkOrCloudOrEdge().add(richcontent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addLinkNode(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) {
|
||||
if (mindmapTopic.getLink() != null) {
|
||||
final String url = mindmapTopic.getLink().getUrl();
|
||||
freemindNode.setLINK(url);
|
||||
}
|
||||
}
|
||||
|
||||
private void addIconNode(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) {
|
||||
if (mindmapTopic.getIcon() != null) {
|
||||
final List<Icon> iconsList = mindmapTopic.getIcon();
|
||||
for (Icon icon : iconsList) {
|
||||
final String id = icon.getId();
|
||||
final String freemindIconId = FreemindIconConverter.toFreemindId(id);
|
||||
if (freemindIconId != null) {
|
||||
|
||||
com.wisemapping.jaxb.freemind.Icon freemindIcon = new com.wisemapping.jaxb.freemind.Icon();
|
||||
freemindIcon.setBUILTIN(freemindIconId);
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(freemindIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addEdgeNode(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) {
|
||||
if (mindmapTopic.getBrColor() != null) {
|
||||
final Edge edgeNode = objectFactory.createEdge();
|
||||
edgeNode.setCOLOR(this.rgbToHex(mindmapTopic.getBrColor()));
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
||||
* eg: Verdana;10;#ffffff;bold;italic;
|
||||
*/
|
||||
private void addFontNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) {
|
||||
final String fontStyle = mindmapTopic.getFontStyle();
|
||||
if (fontStyle != null && fontStyle.length() != 0) {
|
||||
final Font font = objectFactory.createFont();
|
||||
final String[] part = fontStyle.split(";", 6);
|
||||
int countParts = part.length;
|
||||
boolean fontNodeNeeded = false;
|
||||
|
||||
if (!fontStyle.endsWith(FreemindConstant.EMPTY_FONT_STYLE)) {
|
||||
int idx = 0;
|
||||
|
||||
// Font name
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
font.setNAME(part[idx]);
|
||||
fontNodeNeeded = true;
|
||||
}
|
||||
idx++;
|
||||
|
||||
// Font size
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
final String size = part[idx];
|
||||
if (size != null && !size.isEmpty()) {
|
||||
int wiseSize = Integer.parseInt(size);
|
||||
Integer freeSize = wiseToFreeFontSize.get(wiseSize);
|
||||
if(freeSize!=null){
|
||||
font.setSIZE(BigInteger.valueOf(freeSize));
|
||||
fontNodeNeeded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
|
||||
// Font Color
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
freemindNode.setCOLOR(this.rgbToHex(part[idx]));
|
||||
}
|
||||
idx++;
|
||||
|
||||
// Font Styles
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
font.setBOLD(Boolean.TRUE.toString());
|
||||
fontNodeNeeded = true;
|
||||
}
|
||||
idx++;
|
||||
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
font.setITALIC(Boolean.TRUE.toString());
|
||||
fontNodeNeeded = true;
|
||||
}
|
||||
|
||||
if (fontNodeNeeded) {
|
||||
// font size should be set if freemind node has font properties note
|
||||
if (font.getSIZE() == null) {
|
||||
font.setSIZE(BigInteger.valueOf(wiseToFreeFontSize.get(8)));
|
||||
}
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Freemind size goes from 10 to 28
|
||||
// WiseMapping:
|
||||
// 6 Small
|
||||
// 8 Normal
|
||||
// 10 Large
|
||||
// 15 Huge
|
||||
static private final Map<Integer, Integer> wiseToFreeFontSize = new HashMap<Integer, Integer>();
|
||||
|
||||
static {
|
||||
wiseToFreeFontSize.put(6, 10);
|
||||
wiseToFreeFontSize.put(8, 12);
|
||||
wiseToFreeFontSize.put(10, 18);
|
||||
wiseToFreeFontSize.put(15, 24);
|
||||
}
|
||||
|
||||
private String rgbToHex(String color) {
|
||||
String result = color;
|
||||
if (color != null) {
|
||||
boolean isRGB = Pattern.matches("^rgb\\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}\\)$", color);
|
||||
if (isRGB) {
|
||||
String[] rgb = color.substring(4, color.length() - 1).split(",");
|
||||
Integer r = Integer.valueOf(rgb[0].trim());
|
||||
Integer g = Integer.valueOf(rgb[1].trim());
|
||||
Integer b = Integer.valueOf(rgb[2].trim());
|
||||
result = String.format("#%02x%02x%02x", r, g, b);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public VersionNumber getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(VersionNumber version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getVersionNumber() {
|
||||
return this.getVersion().getVersion();
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
import com.wisemapping.jaxb.wisemap.TopicType;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class VerticalPositionComparator implements Comparator<TopicType> {
|
||||
|
||||
@Override
|
||||
public int compare(TopicType o1, TopicType o2) {
|
||||
final String myPosition = o1.getPosition();
|
||||
final String otherPosition = o2.getPosition();
|
||||
int result;
|
||||
if (otherPosition == null) {
|
||||
result = -1;
|
||||
} else if (myPosition == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
int myPositionY = Integer.parseInt(myPosition.split(",")[1]);
|
||||
int otherPositionY = Integer.parseInt(otherPosition.split(",")[1]);
|
||||
result = myPositionY - otherPositionY;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer;
|
||||
|
||||
public enum ImportFormat {
|
||||
FREEMIND()
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer;
|
||||
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface Importer {
|
||||
Mindmap importMap(@NotNull String mapName, @NotNull String description, @NotNull InputStream input) throws ImporterException;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ImporterException
|
||||
extends Exception
|
||||
{
|
||||
public ImporterException(@NotNull String str)
|
||||
{
|
||||
super(str);
|
||||
}
|
||||
public ImporterException(@NotNull Throwable exc)
|
||||
{
|
||||
super(exc);
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer;
|
||||
|
||||
import com.wisemapping.importer.freemind.FreemindImporter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ImporterFactory
|
||||
{
|
||||
|
||||
private static ImporterFactory instance = null;
|
||||
|
||||
private ImporterFactory() {}
|
||||
|
||||
public static ImporterFactory getInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new ImporterFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Importer getImporter(@NotNull ImportFormat format)
|
||||
throws ImporterException
|
||||
{
|
||||
Importer importer;
|
||||
switch (format)
|
||||
{
|
||||
case FREEMIND:
|
||||
importer = new FreemindImporter();
|
||||
break;
|
||||
default:
|
||||
throw new ImporterException("Invalid format type:" + format);
|
||||
}
|
||||
|
||||
return importer;
|
||||
}
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer;
|
||||
|
||||
import org.apache.xml.serialize.OutputFormat;
|
||||
import org.apache.xml.serialize.XMLSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class JaxbCDATAMarshaller {
|
||||
|
||||
public static XMLSerializer createMindmapXMLSerializer(@NotNull OutputStream out) {
|
||||
// configure an OutputFormat to handle CDATA
|
||||
OutputFormat of = new OutputFormat();
|
||||
|
||||
// specify which of your elements you want to be handled as CDATA.
|
||||
// The use of the '^' between the namespaceURI and the localname
|
||||
// seems to be an implementation detail of the xerces code.
|
||||
// When processing xml that doesn't use namespaces, simply omit the
|
||||
// namespace prefix as shown in the third CDataElement below.
|
||||
of.setCDataElements(
|
||||
new String[]{"^text","^note"}); //
|
||||
|
||||
// set any other options you'd like
|
||||
// of.setPreserveSpace(true);
|
||||
of.setIndenting(true);
|
||||
of.setEncoding("UTF-8");
|
||||
|
||||
// create the serializer
|
||||
XMLSerializer result = new XMLSerializer(of) {
|
||||
@Override
|
||||
public void startElement(String s, String s1, String s2, Attributes attributes) throws SAXException {
|
||||
super.startElement(s, s1, s2, new SortedAttributesDecorator(attributes));
|
||||
}
|
||||
};
|
||||
result.setOutputByteStream(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class SortedAttributesDecorator implements Attributes {
|
||||
|
||||
final Map<Integer, Integer> sortedToUnsorted = new HashMap<Integer, Integer>();
|
||||
final Map<Integer, Integer> unsortedToSorted = new HashMap<Integer, Integer>();
|
||||
|
||||
private final Attributes delegated;
|
||||
|
||||
SortedAttributesDecorator(final Attributes delegated) {
|
||||
this.delegated = delegated;
|
||||
int length = this.getLength();
|
||||
|
||||
// Sort by local part ...
|
||||
final Map<String, Integer> sortedMap = new TreeMap<String, Integer>();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final String localName = delegated.getLocalName(i);
|
||||
sortedMap.put(localName, i);
|
||||
}
|
||||
|
||||
Set<String> keySet = sortedMap.keySet();
|
||||
int sortedIndex = 0;
|
||||
for (String key : keySet) {
|
||||
final Integer unsortedIndex = sortedMap.get(key);
|
||||
sortedToUnsorted.put(sortedIndex, unsortedIndex);
|
||||
unsortedToSorted.put(unsortedIndex, sortedIndex);
|
||||
sortedIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return delegated.getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getURI(int index) {
|
||||
return delegated.getURI(sortedToUnsorted.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalName(int index) {
|
||||
return delegated.getLocalName(sortedToUnsorted.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQName(int index) {
|
||||
return delegated.getQName(sortedToUnsorted.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(int index) {
|
||||
return delegated.getType(sortedToUnsorted.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(int index) {
|
||||
return delegated.getValue(sortedToUnsorted.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex(String uri, String localName) {
|
||||
int unsorted = delegated.getIndex(uri, localName);
|
||||
return unsortedToSorted.get(unsorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex(String qName) {
|
||||
int unsorted = delegated.getIndex(qName);
|
||||
return unsortedToSorted.get(unsorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(String uri, String localName) {
|
||||
return delegated.getType(uri, localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(String qName) {
|
||||
return delegated.getType(qName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String uri, String localName) {
|
||||
return delegated.getValue(uri, localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String qName) {
|
||||
return delegated.getValue(qName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class VersionNumber
|
||||
implements Comparable<VersionNumber> {
|
||||
|
||||
protected String version_d;
|
||||
|
||||
//~ Constructors .........................................................................................
|
||||
|
||||
public VersionNumber(final String version) {
|
||||
version_d = version;
|
||||
}
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
/**
|
||||
* Answers whether the receiver is greater then the given version number.
|
||||
*
|
||||
* @param versionNumber the version number to compare to
|
||||
* @return true if the receiver has a greater version number, false otherwise
|
||||
*/
|
||||
public boolean isGreaterThan(final VersionNumber versionNumber) {
|
||||
return this.compareTo(versionNumber) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers whether the receiver is smaller then the given version number.
|
||||
*
|
||||
* @param versionNumber the version number to compare to
|
||||
* @return true if the receiver has a smaller version number, false otherwise
|
||||
*/
|
||||
public boolean isSmallerThan(final VersionNumber versionNumber) {
|
||||
return this.compareTo(versionNumber) < 0;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version_d;
|
||||
}
|
||||
|
||||
|
||||
public int compareTo(@NotNull final VersionNumber otherObject) {
|
||||
if (this.equals(otherObject)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final StringTokenizer ownTokenizer = this.getTokenizer();
|
||||
final StringTokenizer otherTokenizer = otherObject.getTokenizer();
|
||||
|
||||
while (ownTokenizer.hasMoreTokens()) {
|
||||
final int ownNumber;
|
||||
final int otherNumber;
|
||||
|
||||
try {
|
||||
ownNumber = Integer.parseInt(ownTokenizer.nextToken());
|
||||
otherNumber = Integer.parseInt(otherTokenizer.nextToken());
|
||||
} catch (NoSuchElementException nseex) {
|
||||
// only possible if we have more tokens than the other version -
|
||||
// if we get to this point then we are always greater
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ownNumber > otherNumber) {
|
||||
return 1;
|
||||
} else if (ownNumber < otherNumber) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// if other version still has tokens then it is greater than me!
|
||||
otherTokenizer.nextToken();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof VersionNumber)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final VersionNumber versionNumber = (VersionNumber) o;
|
||||
|
||||
return !(version_d != null ? !version_d.equals(versionNumber.version_d)
|
||||
: versionNumber.version_d != null);
|
||||
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (version_d != null ? version_d.hashCode() : 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private StringTokenizer getTokenizer() {
|
||||
return new StringTokenizer(this.getVersion(), ".");
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.wisemapping.importer.freemind;
|
||||
|
||||
import com.wisemapping.importer.VersionNumber;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public interface FreemindConstant {
|
||||
|
||||
String LAST_SUPPORTED_FREEMIND_VERSION = "1.0.1";
|
||||
VersionNumber SUPPORTED_FREEMIND_VERSION = new VersionNumber(LAST_SUPPORTED_FREEMIND_VERSION);
|
||||
String CODE_VERSION = "tango";
|
||||
|
||||
int SECOND_LEVEL_TOPIC_HEIGHT = 25;
|
||||
int ROOT_LEVEL_TOPIC_HEIGHT = SECOND_LEVEL_TOPIC_HEIGHT;
|
||||
int CENTRAL_TO_TOPIC_DISTANCE = 200;
|
||||
int TOPIC_TO_TOPIC_DISTANCE = 90;
|
||||
|
||||
int FONT_SIZE_HUGE = 15;
|
||||
int FONT_SIZE_LARGE = 10;
|
||||
int FONT_SIZE_NORMAL = 8;
|
||||
int FONT_SIZE_SMALL = 6;
|
||||
|
||||
String NODE_TYPE = "NODE";
|
||||
String BOLD = "bold";
|
||||
String ITALIC = "italic";
|
||||
String EMPTY_FONT_STYLE = ";;;;;";
|
||||
String EMPTY_NOTE = "";
|
||||
|
||||
String POSITION_LEFT = "left";
|
||||
String POSITION_RIGHT = "right";
|
||||
|
||||
Charset UTF_8_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer.freemind;
|
||||
|
||||
import com.wisemapping.model.IconFamily;
|
||||
import com.wisemapping.model.MindmapIcon;
|
||||
import com.wisemapping.model.MindmapIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
final public class FreemindIconConverter {
|
||||
|
||||
|
||||
private final static Map<String, MindmapIcon> freeIdToIcon = new TreeMap<String, MindmapIcon>();
|
||||
private final static Map<MindmapIcon, String> iconToFreeId = new TreeMap<MindmapIcon, String>();
|
||||
|
||||
private FreemindIconConverter() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String toWiseId(@NotNull String iconId) {
|
||||
final MindmapIcon result = freeIdToIcon.get(iconId);
|
||||
return result != null ? result.getId() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String toFreemindId(@NotNull String iconId) {
|
||||
String result = iconToFreeId.get(MindmapIcons.findById(iconId));
|
||||
return result != null ? result : iconId;
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
|
||||
// By default, do a default mapping of all. The overwrite.
|
||||
IconFamily[] families = IconFamily.values();
|
||||
for (IconFamily family : families) {
|
||||
final List<MindmapIcon> images = MindmapIcons.getIconByFamily(family);
|
||||
for (MindmapIcon mindmapIcon : images) {
|
||||
iconToFreeId.put(mindmapIcon, mindmapIcon.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Now overwrite that are different ...
|
||||
final List<MindmapIcon> bulletsImages = MindmapIcons.getIconByFamily(IconFamily.BULLET);
|
||||
for (int i = 0; i < bulletsImages.size(); i++) {
|
||||
final MindmapIcon icon = bulletsImages.get(i);
|
||||
iconToFreeId.put(icon, "full-" + i);
|
||||
}
|
||||
|
||||
// Generic mapping ...
|
||||
iconToFreeId.put(MindmapIcons.BULB_LIGHT_ON, "idea");
|
||||
iconToFreeId.put(MindmapIcons.TICK_TICK, "button_ok");
|
||||
iconToFreeId.put(MindmapIcons.TICK_CROSS, "button_cancel");
|
||||
|
||||
// Map arrow icons ...
|
||||
iconToFreeId.put(MindmapIcons.ARROW_RIGHT, "back");
|
||||
iconToFreeId.put(MindmapIcons.ARROW_LEFT, "forward");
|
||||
iconToFreeId.put(MindmapIcons.ONOFF_DELETE, "closed");
|
||||
|
||||
// Map smile icons ...
|
||||
iconToFreeId.put(MindmapIcons.FACE_PLAIN, "smiley-neutral");
|
||||
iconToFreeId.put(MindmapIcons.FACE_SMILE, "ksmiletris");
|
||||
iconToFreeId.put(MindmapIcons.FACE_SURPRISE, "smiley-oh");
|
||||
iconToFreeId.put(MindmapIcons.FACE_SAD, "smiley_bad");
|
||||
|
||||
// Objects mappings
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_KEY, "password");
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_PHONE, "kaddressbook");
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_STAR, "bookmark");
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_MAGNIFIER, "xmag");
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_CLIP, "attach");
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_MUSIC, "knotify");
|
||||
iconToFreeId.put(MindmapIcons.OBJECT_HOUSE, "gohome");
|
||||
iconToFreeId.put(MindmapIcons.ONOFF_STATUS_ONLINE, "licq");
|
||||
|
||||
// Sign mapping ...
|
||||
iconToFreeId.put(MindmapIcons.SIGN_WARNING, "messagebox_warning");
|
||||
iconToFreeId.put(MindmapIcons.SIGN_STOP, "stop-sign");
|
||||
|
||||
|
||||
// Mail mappings
|
||||
iconToFreeId.put(MindmapIcons.MAIL_ENVELOP, "Mail");
|
||||
iconToFreeId.put(MindmapIcons.MAIL_MAILBOX, "korn");
|
||||
|
||||
// Maps Flag familly Icons ...
|
||||
final List<MindmapIcon> flagImages = MindmapIcons.getIconByFamily(IconFamily.FLAG);
|
||||
for (MindmapIcon flagImage : flagImages) {
|
||||
iconToFreeId.put(flagImage, "flag-" + flagImage.getName());
|
||||
}
|
||||
|
||||
|
||||
final Set<MindmapIcon> mindmapIcons = iconToFreeId.keySet();
|
||||
for (MindmapIcon mindmapIcon : mindmapIcons) {
|
||||
freeIdToIcon.put(iconToFreeId.get(mindmapIcon), mindmapIcon);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,616 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.importer.freemind;
|
||||
|
||||
import com.wisemapping.importer.Importer;
|
||||
import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.importer.VersionNumber;
|
||||
import com.wisemapping.jaxb.freemind.*;
|
||||
import com.wisemapping.jaxb.wisemap.Link;
|
||||
import com.wisemapping.jaxb.wisemap.RelationshipType;
|
||||
import com.wisemapping.jaxb.wisemap.TopicType;
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import com.wisemapping.model.ShapeStyle;
|
||||
import com.wisemapping.util.JAXBUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FreemindImporter
|
||||
implements Importer {
|
||||
final private Logger logger = Logger.getLogger(FreemindImporter.class);
|
||||
|
||||
private com.wisemapping.jaxb.wisemap.ObjectFactory mindmapObjectFactory;
|
||||
private java.util.Map<String, TopicType> nodesMap = null;
|
||||
private List<RelationshipType> relationships = null;
|
||||
|
||||
private int currentId;
|
||||
|
||||
public static void main(String[] argv) {
|
||||
|
||||
|
||||
// Now, calculate the order it belongs to ...
|
||||
// 3 = -100 0
|
||||
// 1 = -50 1
|
||||
// 0 = 0 2
|
||||
// 2 = 50 3
|
||||
// 4 = 100 4
|
||||
|
||||
int total = 2;
|
||||
int center = (total - 1) / 2;
|
||||
|
||||
|
||||
for (int i = 0; i < total; i++) {
|
||||
|
||||
int result = i - center + ((total % 2 == 0) ? 0 : 1);
|
||||
if (result > 0) {
|
||||
result = (result - 1) * 2;
|
||||
} else {
|
||||
result = (result * -2) + 1;
|
||||
}
|
||||
|
||||
System.out.println(i + "->" + result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Mindmap importMap(@NotNull String mapName, @NotNull String description, @NotNull InputStream input) throws ImporterException {
|
||||
|
||||
final Mindmap result = new Mindmap();
|
||||
nodesMap = new HashMap<String, TopicType>();
|
||||
relationships = new ArrayList<RelationshipType>();
|
||||
mindmapObjectFactory = new com.wisemapping.jaxb.wisemap.ObjectFactory();
|
||||
|
||||
try {
|
||||
String wiseXml;
|
||||
final Map freemindMap = (Map) JAXBUtils.getMapObject(input, "com.wisemapping.jaxb.freemind");
|
||||
|
||||
final String version = freemindMap.getVersion();
|
||||
if (version == null || version.startsWith("freeplane")) {
|
||||
throw new ImporterException("You seems to be be trying to import a Freeplane map. FreePlane is not supported format.");
|
||||
} else {
|
||||
final VersionNumber mapVersion = new VersionNumber(version);
|
||||
if (mapVersion.isGreaterThan(FreemindConstant.SUPPORTED_FREEMIND_VERSION)) {
|
||||
throw new ImporterException("FreeMind version " + mapVersion.getVersion() + " is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
final com.wisemapping.jaxb.wisemap.Map mindmapMap = mindmapObjectFactory.createMap();
|
||||
mindmapMap.setVersion(FreemindConstant.CODE_VERSION);
|
||||
currentId = 0;
|
||||
|
||||
final Node freeNode = freemindMap.getNode();
|
||||
final TopicType wiseTopic = mindmapObjectFactory.createTopicType();
|
||||
wiseTopic.setId(String.valueOf(currentId++));
|
||||
wiseTopic.setCentral(true);
|
||||
wiseTopic.setPosition("0,0");
|
||||
|
||||
convertNodeProperties(freeNode, wiseTopic);
|
||||
|
||||
wiseTopic.setShape(ShapeStyle.ROUNDED_RECTANGLE.getStyle());
|
||||
mindmapMap.getTopic().add(wiseTopic);
|
||||
mindmapMap.setName(mapName);
|
||||
|
||||
nodesMap.put(freeNode.getID(), wiseTopic);
|
||||
|
||||
convertChildNodes(freeNode, wiseTopic, 1);
|
||||
addRelationships(mindmapMap);
|
||||
|
||||
JAXBUtils.saveMap(mindmapMap, baos);
|
||||
wiseXml = baos.toString(FreemindConstant.UTF_8_CHARSET);
|
||||
result.setXmlStr(wiseXml);
|
||||
result.setTitle(mapName);
|
||||
result.setDescription(description);
|
||||
|
||||
} catch (JAXBException | TransformerException e) {
|
||||
logger.debug(e);
|
||||
throw new ImporterException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addRelationships(@NotNull com.wisemapping.jaxb.wisemap.Map mindmapMap) {
|
||||
List<RelationshipType> mapRelationships = mindmapMap.getRelationship();
|
||||
for (RelationshipType relationship : relationships) {
|
||||
relationship.setId(String.valueOf(currentId++));
|
||||
|
||||
fixRelationshipControlPoints(relationship);
|
||||
|
||||
//Fix dest ID
|
||||
String destId = relationship.getDestTopicId();
|
||||
TopicType destTopic = nodesMap.get(destId);
|
||||
relationship.setDestTopicId(destTopic.getId());
|
||||
//Fix src ID
|
||||
String srcId = relationship.getSrcTopicId();
|
||||
TopicType srcTopic = nodesMap.get(srcId);
|
||||
relationship.setSrcTopicId(srcTopic.getId());
|
||||
|
||||
mapRelationships.add(relationship);
|
||||
}
|
||||
}
|
||||
|
||||
private void fixRelationshipControlPoints(@NotNull RelationshipType rel) {
|
||||
//Both relationship node's ids should be freemind ones at this point.
|
||||
TopicType srcTopic = nodesMap.get(rel.getSrcTopicId());
|
||||
TopicType destTopicType = nodesMap.get(rel.getDestTopicId());
|
||||
|
||||
//Fix x coord
|
||||
final String srcCtrlPoint = rel.getSrcCtrlPoint();
|
||||
if (srcCtrlPoint != null) {
|
||||
final Coord srcCtrlCoord = Coord.parse(srcCtrlPoint);
|
||||
|
||||
if (Coord.parse(srcTopic.getPosition()).isOnLeftSide()) {
|
||||
int x = srcCtrlCoord.x * -1;
|
||||
rel.setSrcCtrlPoint(x + "," + srcCtrlCoord.y);
|
||||
|
||||
//Fix coord
|
||||
if (srcTopic.getOrder() != null && srcTopic.getOrder() % 2 != 0) { //Odd order.
|
||||
int y = srcCtrlCoord.y * -1;
|
||||
rel.setSrcCtrlPoint(srcCtrlCoord.x + "," + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
final String destCtrlPoint = rel.getDestCtrlPoint();
|
||||
if (destCtrlPoint != null) {
|
||||
final Coord destCtrlCoord = Coord.parse(destCtrlPoint);
|
||||
|
||||
|
||||
if (Coord.parse(destTopicType.getPosition()).isOnLeftSide()) {
|
||||
int x = destCtrlCoord.x * -1;
|
||||
rel.setDestCtrlPoint(x + "," + destCtrlCoord.y);
|
||||
}
|
||||
|
||||
|
||||
if (destTopicType.getOrder() != null && destTopicType.getOrder() % 2 != 0) { //Odd order.
|
||||
int y = destCtrlCoord.y * -1;
|
||||
rel.setDestCtrlPoint(destCtrlCoord.x + "," + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void convertChildNodes(@NotNull Node freeParent, @NotNull TopicType wiseParent, final int depth) throws TransformerException {
|
||||
final List<Object> freeChilden = freeParent.getArrowlinkOrCloudOrEdge();
|
||||
TopicType currentWiseTopic = wiseParent;
|
||||
|
||||
int order = 0;
|
||||
int firstLevelRightOrder = 0;
|
||||
int firstLevelLeftOrder = 1;
|
||||
for (Object element : freeChilden) {
|
||||
|
||||
if (element instanceof Node) {
|
||||
final Node freeChild = (Node) element;
|
||||
final TopicType wiseChild = mindmapObjectFactory.createTopicType();
|
||||
|
||||
// Set an incremental id ...
|
||||
wiseChild.setId(String.valueOf(currentId++));
|
||||
|
||||
// Lets use freemind id temporarily. This will be fixed when adding relationship to the map.
|
||||
nodesMap.put(freeChild.getID(), wiseChild);
|
||||
|
||||
// Set node order ...
|
||||
int norder;
|
||||
if (depth != 1) {
|
||||
norder = order++;
|
||||
} else {
|
||||
if (freeChild.getPOSITION() != null && freeChild.getPOSITION().equals(FreemindConstant.POSITION_LEFT)) {
|
||||
norder = firstLevelLeftOrder;
|
||||
firstLevelLeftOrder = firstLevelLeftOrder + 2;
|
||||
} else {
|
||||
norder = firstLevelRightOrder;
|
||||
firstLevelRightOrder = firstLevelRightOrder + 2;
|
||||
}
|
||||
}
|
||||
wiseChild.setOrder(norder);
|
||||
|
||||
// Convert node position
|
||||
int childrenCountSameSide = getChildrenCountSameSide(freeChilden, freeChild);
|
||||
final String position = convertPosition(wiseParent, freeChild, depth, norder, childrenCountSameSide);
|
||||
wiseChild.setPosition(position);
|
||||
|
||||
// Convert the rest of the node properties ...
|
||||
convertNodeProperties(freeChild, wiseChild);
|
||||
|
||||
convertChildNodes(freeChild, wiseChild, depth + 1);
|
||||
|
||||
if (!wiseChild.equals(wiseParent)) {
|
||||
wiseParent.getTopic().add(wiseChild);
|
||||
}
|
||||
currentWiseTopic = wiseChild;
|
||||
|
||||
} else if (element instanceof Font) {
|
||||
final Font font = (Font) element;
|
||||
final String fontStyle = generateFontStyle(freeParent, font);
|
||||
if (fontStyle != null) {
|
||||
currentWiseTopic.setFontStyle(fontStyle);
|
||||
}
|
||||
} else if (element instanceof Edge) {
|
||||
final Edge edge = (Edge) element;
|
||||
currentWiseTopic.setBrColor(edge.getCOLOR());
|
||||
} else if (element instanceof Icon) {
|
||||
final Icon freemindIcon = (Icon) element;
|
||||
|
||||
String iconId = freemindIcon.getBUILTIN();
|
||||
final String wiseIconId = FreemindIconConverter.toWiseId(iconId);
|
||||
if (wiseIconId != null) {
|
||||
final com.wisemapping.jaxb.wisemap.Icon mindmapIcon = new com.wisemapping.jaxb.wisemap.Icon();
|
||||
mindmapIcon.setId(wiseIconId);
|
||||
currentWiseTopic.getIcon().add(mindmapIcon);
|
||||
}
|
||||
|
||||
} else if (element instanceof Hook) {
|
||||
final Hook hook = (Hook) element;
|
||||
final com.wisemapping.jaxb.wisemap.Note mindmapNote = new com.wisemapping.jaxb.wisemap.Note();
|
||||
String textNote = hook.getText();
|
||||
if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook
|
||||
{
|
||||
textNote = FreemindConstant.EMPTY_NOTE;
|
||||
mindmapNote.setValue(textNote);
|
||||
currentWiseTopic.setNote(mindmapNote);
|
||||
}
|
||||
} else if (element instanceof Richcontent) {
|
||||
final Richcontent content = (Richcontent) element;
|
||||
final String type = content.getTYPE();
|
||||
|
||||
if (type.equals(FreemindConstant.NODE_TYPE)) {
|
||||
String text = html2text(content);
|
||||
currentWiseTopic.setText(text);
|
||||
} else {
|
||||
String text = html2text(content);
|
||||
final com.wisemapping.jaxb.wisemap.Note mindmapNote = new com.wisemapping.jaxb.wisemap.Note();
|
||||
text = text != null ? text : FreemindConstant.EMPTY_NOTE;
|
||||
mindmapNote.setValue(text);
|
||||
currentWiseTopic.setNote(mindmapNote);
|
||||
|
||||
}
|
||||
} else if (element instanceof Arrowlink) {
|
||||
final Arrowlink arrow = (Arrowlink) element;
|
||||
RelationshipType relt = mindmapObjectFactory.createRelationshipType();
|
||||
String destId = arrow.getDESTINATION();
|
||||
// FIXME: invert srcTopic and dstTopic to correct a bug in the wise mind map representation
|
||||
relt.setSrcTopicId(destId);
|
||||
relt.setDestTopicId(freeParent.getID());
|
||||
final String endinclination = arrow.getENDINCLINATION();
|
||||
if (endinclination != null) {
|
||||
String[] inclination = endinclination.split(";");
|
||||
relt.setDestCtrlPoint(inclination[0] + "," + inclination[1]);
|
||||
}
|
||||
final String startinclination = arrow.getSTARTINCLINATION();
|
||||
if (startinclination != null) {
|
||||
String[] inclination = startinclination.split(";");
|
||||
relt.setSrcCtrlPoint(inclination[0] + "," + inclination[1]);
|
||||
}
|
||||
|
||||
final String endarrow = arrow.getENDARROW();
|
||||
if (endarrow != null) {
|
||||
relt.setEndArrow(!endarrow.equalsIgnoreCase("none"));
|
||||
}
|
||||
|
||||
final String startarrow = arrow.getSTARTARROW();
|
||||
if (startarrow != null) {
|
||||
relt.setStartArrow(!startarrow.equalsIgnoreCase("none"));
|
||||
}
|
||||
relt.setLineType("3");
|
||||
relationships.add(relt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getChildrenCountSameSide(@NotNull List<Object> freeChildren, Node freeChild) {
|
||||
int result = 0;
|
||||
String childSide = freeChild.getPOSITION();
|
||||
if (childSide == null) {
|
||||
childSide = FreemindConstant.POSITION_RIGHT;
|
||||
}
|
||||
|
||||
// Count all the nodes of the same side ...
|
||||
for (Object child : freeChildren) {
|
||||
if (child instanceof Node) {
|
||||
Node node = (Node) child;
|
||||
|
||||
String side = node.getPOSITION();
|
||||
if (side == null) {
|
||||
side = FreemindConstant.POSITION_RIGHT;
|
||||
}
|
||||
if (childSide.equals(side)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Position is (x,y).
|
||||
* x values greater than 0 are right axis
|
||||
* x values lower than 0 are left axis
|
||||
*/
|
||||
private
|
||||
@NotNull
|
||||
String convertPosition(@NotNull TopicType wiseParent, @NotNull Node freeChild, final int depth, int order, int childrenCount) {
|
||||
|
||||
// Which side must be the node be positioned ?
|
||||
|
||||
// Calculate X ...
|
||||
|
||||
// Problem on setting X position:
|
||||
// Text Size is not taken into account ...
|
||||
int x = FreemindConstant.CENTRAL_TO_TOPIC_DISTANCE + ((depth - 1) * FreemindConstant.TOPIC_TO_TOPIC_DISTANCE);
|
||||
if (depth == 1) {
|
||||
|
||||
final String side = freeChild.getPOSITION();
|
||||
x = x * (side != null && FreemindConstant.POSITION_LEFT.equals(side) ? -1 : 1);
|
||||
} else {
|
||||
final Coord coord = Coord.parse(wiseParent.getPosition());
|
||||
x = x * (coord.isOnLeftSide() ? -1 : 1);
|
||||
}
|
||||
|
||||
|
||||
// Calculate y ...
|
||||
int y;
|
||||
if (depth == 1) {
|
||||
|
||||
// pair order numbers represent nodes at the right
|
||||
// odd order numbers represent nodes at the left
|
||||
if (order % 2 == 0) {
|
||||
int multiplier = ((order + 1) - childrenCount) * 2;
|
||||
y = multiplier * FreemindConstant.ROOT_LEVEL_TOPIC_HEIGHT;
|
||||
} else {
|
||||
int multiplier = (order - childrenCount) * 2;
|
||||
y = multiplier * FreemindConstant.ROOT_LEVEL_TOPIC_HEIGHT;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Problem: What happen if the node is more tall than what is defined here.
|
||||
Coord coord = Coord.parse(wiseParent.getPosition());
|
||||
int parentY = coord.y;
|
||||
y = parentY - ((childrenCount / 2) * FreemindConstant.SECOND_LEVEL_TOPIC_HEIGHT - (order * FreemindConstant.SECOND_LEVEL_TOPIC_HEIGHT));
|
||||
|
||||
|
||||
}
|
||||
return x + "," + y;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Position is (x,y).
|
||||
* x values greater than 0 are right axis
|
||||
* x values lower than 0 are left axis
|
||||
*/
|
||||
// private
|
||||
// @NotNull
|
||||
// String convertPosition(@NotNull TopicType wiseParent, @NotNull Node freeChild, final int depth, int order) {
|
||||
//
|
||||
// // Which side must be the node be positioned ?
|
||||
// String result = freeChild.getWcoords();
|
||||
// if (result == null) {
|
||||
// BigInteger vgap = freeChild.getVSHIFT();
|
||||
// BigInteger hgap = freeChild.getHGAP();
|
||||
//
|
||||
// if (hgap == null) {
|
||||
// hgap = BigInteger.valueOf(0L);
|
||||
// }
|
||||
//
|
||||
// if (vgap == null) {
|
||||
// vgap = BigInteger.valueOf(HALF_ROOT_TOPICS_SEPARATION * order);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// final String[] position = wiseParent.getPosition().split(",");
|
||||
// BigInteger fix = BigInteger.valueOf(1L);
|
||||
// if ((freeChild.getPOSITION() != null && POSITION_LEFT.equals(freeChild.getPOSITION().toLowerCase()))
|
||||
// || freeChild.getPOSITION() == null && isOnLeftSide(wiseParent)) {
|
||||
// fix = BigInteger.valueOf(-1L);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// BigInteger firstLevelDistance = BigInteger.valueOf(0L);
|
||||
// BigInteger defaultXDistance = BigInteger.valueOf(200L);
|
||||
// if (depth == 1) {
|
||||
// firstLevelDistance = BigInteger.valueOf(200L);
|
||||
// defaultXDistance = BigInteger.valueOf(0L);
|
||||
// }
|
||||
//
|
||||
// BigInteger x = BigInteger.valueOf(Integer.valueOf(position[0])).add(hgap.multiply(fix).add(firstLevelDistance.multiply(fix)).add(defaultXDistance.multiply(fix)));
|
||||
// BigInteger y = BigInteger.valueOf(Integer.valueOf(position[1])).add(vgap);
|
||||
// result = x.toString() + "," + y.toString();
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@NotNull
|
||||
private String html2text(@NotNull Richcontent content) throws TransformerException {
|
||||
final Element html = (Element) content.getHtml();
|
||||
|
||||
// Convert any to HTML piece ...
|
||||
TransformerFactory transFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transFactory.newTransformer();
|
||||
StringWriter buffer = new StringWriter();
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
transformer.transform(new DOMSource(html), new StreamResult(buffer));
|
||||
|
||||
// Keep return lines in place ...
|
||||
final Document document = Jsoup.parse(buffer.toString());
|
||||
document.select("br").append("\\n");
|
||||
document.select("p").prepend("\\n");
|
||||
document.select("div").prepend("\\n");
|
||||
return document.text().replaceAll("\\\\n", "\n").trim();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void convertNodeProperties(@NotNull com.wisemapping.jaxb.freemind.Node freeNode, @NotNull com.wisemapping.jaxb.wisemap.TopicType wiseTopic) {
|
||||
final String text = freeNode.getTEXT();
|
||||
wiseTopic.setText(text);
|
||||
|
||||
// Background color ...
|
||||
final String bgcolor = freeNode.getBACKGROUNDCOLOR();
|
||||
wiseTopic.setBgColor(bgcolor);
|
||||
|
||||
|
||||
final String shape = getShapeFormFromNode(freeNode);
|
||||
wiseTopic.setShape(shape);
|
||||
|
||||
// Check for styles ...
|
||||
final String fontStyle = generateFontStyle(freeNode, null);
|
||||
if (fontStyle != null) {
|
||||
wiseTopic.setFontStyle(fontStyle);
|
||||
}
|
||||
|
||||
// Is there any link ?
|
||||
final String url = freeNode.getLINK();
|
||||
if (url != null) {
|
||||
final Link link = new Link();
|
||||
link.setUrl(url);
|
||||
wiseTopic.setLink(link);
|
||||
}
|
||||
|
||||
final Boolean folded = Boolean.valueOf(freeNode.getFOLDED());
|
||||
wiseTopic.setShrink(folded);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private String generateFontStyle(@NotNull Node node, @Nullable Font font) {
|
||||
/*
|
||||
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
||||
* eg: Verdana;10;#ffffff;bold;italic;
|
||||
*
|
||||
*/
|
||||
|
||||
// Font name ...
|
||||
final StringBuilder fontStyle = new StringBuilder();
|
||||
if (font != null) {
|
||||
fontStyle.append(fixFontName(font));
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Freemind size goes from 10 to 28
|
||||
// WiseMapping:
|
||||
// 6 Small
|
||||
// 8 Normal
|
||||
// 10 Large
|
||||
// 15 Huge
|
||||
if (font != null) {
|
||||
final int fontSize = ((font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(FreemindConstant.FONT_SIZE_NORMAL) : font.getSIZE()).intValue();
|
||||
int wiseFontSize = FreemindConstant.FONT_SIZE_SMALL;
|
||||
if (fontSize >= 24) {
|
||||
wiseFontSize = FreemindConstant.FONT_SIZE_HUGE;
|
||||
} else if (fontSize >= 16) {
|
||||
wiseFontSize = FreemindConstant.FONT_SIZE_LARGE;
|
||||
} else if (fontSize >= 12) {
|
||||
wiseFontSize = FreemindConstant.FONT_SIZE_NORMAL;
|
||||
}
|
||||
fontStyle.append(wiseFontSize);
|
||||
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Color ...
|
||||
final String color = node.getCOLOR();
|
||||
if (color != null && !color.equals("")) {
|
||||
fontStyle.append(color);
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Bold ...
|
||||
if (font != null) {
|
||||
boolean hasBold = Boolean.parseBoolean(font.getBOLD());
|
||||
fontStyle.append(hasBold ? FreemindConstant.BOLD : "");
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Italic ...
|
||||
if (font != null) {
|
||||
boolean hasItalic = Boolean.parseBoolean(font.getITALIC());
|
||||
fontStyle.append(hasItalic ? FreemindConstant.ITALIC : "");
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
final String result = fontStyle.toString();
|
||||
return result.equals(FreemindConstant.EMPTY_FONT_STYLE) ? null : result;
|
||||
}
|
||||
|
||||
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
|
||||
@NotNull
|
||||
String getShapeFormFromNode(@NotNull Node node) {
|
||||
String result = node.getSTYLE();
|
||||
// In freemind a node without style is a line
|
||||
if ("bubble".equals(result)) {
|
||||
result = ShapeStyle.ROUNDED_RECTANGLE.getStyle();
|
||||
} else {
|
||||
if (node.getBACKGROUNDCOLOR() != null) {
|
||||
// This the node has background color defined. It's better to change the default shape.
|
||||
result = ShapeStyle.RECTANGLE.getStyle();
|
||||
} else {
|
||||
result = ShapeStyle.LINE.getStyle();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static private class Coord {
|
||||
private final int y;
|
||||
private final int x;
|
||||
|
||||
private Coord(@NotNull String pos) {
|
||||
final String[] split = pos.split(",");
|
||||
x = Integer.parseInt(split[0]);
|
||||
y = Integer.parseInt(split[1]);
|
||||
}
|
||||
|
||||
public static Coord parse(@NotNull String position) {
|
||||
return new Coord(position);
|
||||
}
|
||||
|
||||
private boolean isOnLeftSide() {
|
||||
return x < 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,10 +19,6 @@
|
||||
package com.wisemapping.rest;
|
||||
|
||||
import com.wisemapping.exceptions.*;
|
||||
import com.wisemapping.importer.ImportFormat;
|
||||
import com.wisemapping.importer.Importer;
|
||||
import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.importer.ImporterFactory;
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.rest.model.*;
|
||||
import com.wisemapping.security.Utils;
|
||||
@ -549,27 +545,6 @@ public class MindmapController extends BaseController {
|
||||
response.setHeader("ResourceId", Integer.toString(delegated.getId()));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps", consumes = {"application/freemind"})
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createMapFromFreemind(@RequestBody byte[] freemindXml, @RequestParam(required = true) String title, @RequestParam(required = false) String description, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {
|
||||
|
||||
// Convert map ...
|
||||
final Mindmap mindMap;
|
||||
try {
|
||||
final Importer importer = ImporterFactory.getInstance().getImporter(ImportFormat.FREEMIND);
|
||||
final ByteArrayInputStream stream = new ByteArrayInputStream(freemindXml);
|
||||
mindMap = importer.importMap(title, "", stream);
|
||||
} catch (ImporterException e) {
|
||||
// @Todo: This should be an illegal argument exception. Review the all the other cases.
|
||||
throw buildValidationException("xml", "The selected file does not seems to be a valid Freemind or WiseMapping file. Contact support in case the problem persists.");
|
||||
} catch (Throwable e) {
|
||||
throw new ImportUnexpectedException(e, freemindXml);
|
||||
}
|
||||
|
||||
// Save new map ...
|
||||
createMap(new RestMindmap(mindMap, null), response, title, description);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"},produces = {"application/xml", "application/json","text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createDuplicate(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {
|
||||
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.rest.view;
|
||||
|
||||
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.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImportTransformationView extends AbstractView {
|
||||
|
||||
private final String contentType;
|
||||
private final Importer importer;
|
||||
|
||||
public ImportTransformationView(@NotNull final String contentType) throws ImporterException {
|
||||
ImporterFactory exporterFactory = ImporterFactory.getInstance();
|
||||
importer = exporterFactory.getImporter(ImportFormat.FREEMIND);
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(@NotNull Map<String, Object> viewMap, @NotNull HttpServletRequest request, @NotNull final HttpServletResponse response) throws Exception {
|
||||
final String content = (String) viewMap.get("content");
|
||||
final String filename = (String) viewMap.get("filename");
|
||||
|
||||
// Convert to map ...
|
||||
final InputStream is = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||
final Mindmap mindMap = importer.importMap("filename", "filename", is);
|
||||
|
||||
// Set file name...:http://stackoverflow.com/questions/5325322/java-servlet-download-filename-special-characters/13359949#13359949
|
||||
final String fileName = (filename != null ? filename : "map") + "." + "xwise";
|
||||
setContentDisposition(request, response, fileName);
|
||||
|
||||
// Write the conversion content ...
|
||||
final ServletOutputStream outputStream = response.getOutputStream();
|
||||
outputStream.print(mindMap.getXmlStr());
|
||||
}
|
||||
|
||||
private void setContentDisposition(HttpServletRequest request, HttpServletResponse response, String fileName) {
|
||||
final String userAgent = request.getHeader("user-agent");
|
||||
String disposition = fileName;
|
||||
boolean isInternetExplorer = (userAgent.contains("MSIE"));
|
||||
try {
|
||||
byte[] fileNameBytes = fileName.getBytes((isInternetExplorer) ? ("windows-1250") : ("utf-8"));
|
||||
String dispositionFileName = "";
|
||||
for (byte b : fileNameBytes) {
|
||||
dispositionFileName += (char) (b & 0xff);
|
||||
}
|
||||
disposition = "attachment; filename=\"" + dispositionFileName + "\"";
|
||||
} catch (UnsupportedEncodingException ence) {
|
||||
// ... handle exception ...
|
||||
}
|
||||
response.setHeader("Content-disposition", disposition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.util;
|
||||
|
||||
import com.wisemapping.importer.JaxbCDATAMarshaller;
|
||||
import org.apache.xml.serialize.XMLSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JAXBUtils {
|
||||
|
||||
private final static Map<String, JAXBContext> context = new HashMap<String, JAXBContext>();
|
||||
|
||||
public static Object getMapObject(@NotNull InputStream is, @NotNull final String pakage) throws JAXBException {
|
||||
|
||||
final JAXBContext context = getInstance(pakage);
|
||||
final Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
|
||||
return unmarshaller.unmarshal(reader);
|
||||
}
|
||||
|
||||
private static JAXBContext getInstance(@NotNull String pakage) throws JAXBException {
|
||||
|
||||
JAXBContext result = context.get(pakage);
|
||||
if (result == null) {
|
||||
synchronized (context) {
|
||||
result = JAXBContext.newInstance(pakage);
|
||||
context.put(pakage, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static void saveMap(@NotNull com.wisemapping.jaxb.wisemap.Map obj, @NotNull OutputStream out) throws JAXBException {
|
||||
|
||||
final JAXBContext context = getInstance("com.wisemapping.jaxb.wisemap");
|
||||
final Marshaller marshaller = context.createMarshaller();
|
||||
|
||||
// get an Apache XMLSerializer configured to generate CDATA
|
||||
XMLSerializer serializer = JaxbCDATAMarshaller.createMindmapXMLSerializer(out);
|
||||
|
||||
try {
|
||||
// marshal using the Apache XMLSerializer
|
||||
marshaller.marshal(obj, serializer.asContentHandler());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveMap(@NotNull com.wisemapping.jaxb.freemind.Map map, @NotNull OutputStream out) throws JAXBException {
|
||||
|
||||
final JAXBContext context = getInstance("com.wisemapping.jaxb.freemind");
|
||||
final Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, "ASCII");
|
||||
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
marshaller.marshal(map, out);
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package com.wisemapping.test.export;
|
||||
|
||||
import com.wisemapping.exporter.ExportException;
|
||||
import com.wisemapping.exporter.FreemindExporter;
|
||||
import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@Test
|
||||
public class ExportFreemindTest {
|
||||
private static final String DATA_DIR_PATH = "src/test/resources/data/export/";
|
||||
private static final String ENC_UTF_8 = "UTF-8";
|
||||
private static final String ENC_LATIN1 = "iso-8859-1";
|
||||
|
||||
|
||||
@Test(dataProvider = "Data-Provider-Function")
|
||||
public void exportImportExportTest(@NotNull final File wisemap, @NotNull final File recFile) throws ImporterException, IOException, ExportException {
|
||||
|
||||
final Mindmap mindmap = load(wisemap);
|
||||
|
||||
final FreemindExporter freemindExporter = new FreemindExporter();
|
||||
if (recFile.exists()) {
|
||||
// Compare rec and file ...
|
||||
final String recContent = FileUtils.readFileToString(recFile, ENC_UTF_8);
|
||||
|
||||
// Export mile content ...
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
freemindExporter.export(mindmap, bos);
|
||||
final String exportContent = bos.toString(ENC_LATIN1);
|
||||
|
||||
Assert.assertEquals(exportContent, recContent);
|
||||
|
||||
} else {
|
||||
final OutputStream fos = new FileOutputStream(recFile);
|
||||
freemindExporter.export(mindmap, fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Mindmap load(@NotNull File wisemap) throws IOException {
|
||||
final byte[] recContent = FileUtils.readFileToByteArray(wisemap);
|
||||
final Mindmap result = new Mindmap();
|
||||
result.setUnzipXml(recContent);
|
||||
return result;
|
||||
}
|
||||
|
||||
//This function will provide the parameter data
|
||||
@DataProvider(name = "Data-Provider-Function")
|
||||
public Object[][] parameterIntTestProvider() {
|
||||
|
||||
final File dataDir = new File(DATA_DIR_PATH);
|
||||
final File[] freeMindFiles = dataDir.listFiles(new FilenameFilter() {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".wxml");
|
||||
}
|
||||
});
|
||||
|
||||
final Object[][] result = new Object[freeMindFiles.length][2];
|
||||
for (int i = 0; i < freeMindFiles.length; i++) {
|
||||
File freeMindFile = freeMindFiles[i];
|
||||
final String name = freeMindFile.getName();
|
||||
result[i] = new Object[]{freeMindFile, new File(DATA_DIR_PATH, name.substring(0, name.lastIndexOf(".")) + ".mm")};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package com.wisemapping.test.importer;
|
||||
|
||||
import com.wisemapping.exporter.ExportException;
|
||||
import com.wisemapping.exporter.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.apache.commons.io.FileUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Test
|
||||
public class FreeMindImportExportTest {
|
||||
private static final String DATA_DIR_PATH = "src/test/resources/data/freemind/";
|
||||
private static final String UTF_8 = "UTF-8";
|
||||
final private Importer importer;
|
||||
final private FreemindExporter exporter;
|
||||
|
||||
public FreeMindImportExportTest() throws ImporterException {
|
||||
ImporterFactory exporterFactory = ImporterFactory.getInstance();
|
||||
importer = exporterFactory.getImporter(ImportFormat.FREEMIND);
|
||||
exporter = new FreemindExporter();
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProvider = "Data-Provider-Function")
|
||||
public void exportImportTest(@NotNull final File freeMindFile, @NotNull final File wiseFile, @NotNull final File freeRecFile) throws ImporterException, IOException, ExportException {
|
||||
final FileInputStream fileInputStream = new FileInputStream(freeMindFile.getAbsolutePath());
|
||||
final Mindmap mindMap = importer.importMap("basic", "basic", fileInputStream);
|
||||
|
||||
|
||||
// Compare mindmap output ...
|
||||
if (wiseFile.exists()) {
|
||||
// Compare rec and file ...
|
||||
// Load rec file co
|
||||
final String recContent = FileUtils.readFileToString(wiseFile, UTF_8);
|
||||
|
||||
// Export mile content ...
|
||||
Assert.assertEquals(mindMap.getXmlStr(), recContent);
|
||||
|
||||
} else {
|
||||
final FileOutputStream fos = new FileOutputStream(wiseFile);
|
||||
fos.write(mindMap.getXmlStr().getBytes(StandardCharsets.UTF_8));
|
||||
fos.close();
|
||||
}
|
||||
|
||||
// Compare freemind output ...
|
||||
if (freeRecFile.exists()) {
|
||||
// Compare rec and file ...
|
||||
// Load rec file co
|
||||
final String recContent = FileUtils.readFileToString(freeRecFile, UTF_8);
|
||||
|
||||
// Export content ...
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
exporter.export(mindMap, bos);
|
||||
|
||||
Assert.assertEquals(bos.toString(StandardCharsets.UTF_8), recContent);
|
||||
|
||||
} else {
|
||||
final FileOutputStream fos = new FileOutputStream(freeRecFile);
|
||||
exporter.export(mindMap, fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
|
||||
//This function will provide the parameter data
|
||||
@DataProvider(name = "Data-Provider-Function")
|
||||
public Object[][] parameterIntTestProvider() {
|
||||
|
||||
final String testNameToRun = System.getProperty("wise.test.name");
|
||||
|
||||
final File dataDir = new File(DATA_DIR_PATH);
|
||||
final File[] freeMindFiles = dataDir.listFiles(new FilenameFilter() {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".mm") && (testNameToRun == null || name.startsWith(testNameToRun));
|
||||
}
|
||||
});
|
||||
|
||||
final Object[][] result = new Object[freeMindFiles.length][2];
|
||||
for (int i = 0; i < freeMindFiles.length; i++) {
|
||||
File freeMindFile = freeMindFiles[i];
|
||||
final String name = freeMindFile.getName();
|
||||
String testName = name.substring(0, name.lastIndexOf("."));
|
||||
result[i] = new Object[]{freeMindFile, new File(DATA_DIR_PATH, testName + ".wxml"), new File(DATA_DIR_PATH, testName + ".mmr")};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.wisemapping.test.importer;
|
||||
|
||||
import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.importer.VersionNumber;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class VersionComparisonTest {
|
||||
|
||||
@Test
|
||||
public void compareVersionTest() throws ImporterException {
|
||||
|
||||
final VersionNumber greatest = new VersionNumber("1.0.1");
|
||||
final VersionNumber smaller = new VersionNumber("0.9.0");
|
||||
final VersionNumber intermediate = new VersionNumber("1.0.0");
|
||||
|
||||
Assert.assertTrue(smaller.isSmallerThan(intermediate));
|
||||
Assert.assertFalse(greatest.isSmallerThan(intermediate));
|
||||
|
||||
Assert.assertTrue(greatest.isGreaterThan(smaller));
|
||||
Assert.assertFalse(intermediate.isGreaterThan(greatest));
|
||||
|
||||
Assert.assertTrue(intermediate.equals(intermediate));
|
||||
Assert.assertFalse(greatest.equals(smaller));
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user