freemind constant

This commit is contained in:
Claudio Barril 2014-09-07 23:15:27 -03:00
parent c83f4bd213
commit 7ee42468bd
4 changed files with 72 additions and 54 deletions

View File

@ -18,6 +18,7 @@
package com.wisemapping.exporter; package com.wisemapping.exporter;
import com.wisemapping.importer.VersionNumber;
import org.apache.batik.parser.AWTTransformProducer; import org.apache.batik.parser.AWTTransformProducer;
import org.apache.batik.parser.ParseException; import org.apache.batik.parser.ParseException;
import org.apache.batik.parser.TransformListParser; import org.apache.batik.parser.TransformListParser;
@ -142,7 +143,7 @@ public class ExporterFactory {
} }
case FREEMIND: { case FREEMIND: {
final FreemindExporter exporter = new FreemindExporter(); final FreemindExporter exporter = new FreemindExporter();
exporter.setVersion(properties.getVersion()); exporter.setVersion(new VersionNumber(properties.getVersion()));
exporter.export(xml.getBytes(UTF_8_CHARSET_NAME), output); exporter.export(xml.getBytes(UTF_8_CHARSET_NAME), output);
break; break;
} }

View File

@ -19,6 +19,8 @@
package com.wisemapping.exporter; package com.wisemapping.exporter;
import com.wisemapping.importer.VersionNumber;
import com.wisemapping.importer.freemind.FreemindConstant;
import com.wisemapping.importer.freemind.FreemindIconConverter; import com.wisemapping.importer.freemind.FreemindIconConverter;
import com.wisemapping.jaxb.wisemap.Note; import com.wisemapping.jaxb.wisemap.Note;
import com.wisemapping.model.Mindmap; import com.wisemapping.model.Mindmap;
@ -50,12 +52,10 @@ import java.util.Map;
public class FreemindExporter public class FreemindExporter
implements Exporter { implements Exporter {
private static final String POSITION_LEFT = "left";
private static final String POSITION_RIGHT = "right";
private com.wisemapping.jaxb.freemind.ObjectFactory objectFactory; private com.wisemapping.jaxb.freemind.ObjectFactory objectFactory;
private static final String EMPTY_FONT_STYLE = ";;;;;";
private Map<String, Node> nodesMap = null; private Map<String, Node> nodesMap = null;
private String version = "1.0.1"; private VersionNumber version = FreemindConstant.SUPPORTED_FREEMIND_VERSION;
public void export(Mindmap map, OutputStream outputStream) throws ExportException { public void export(Mindmap map, OutputStream outputStream) throws ExportException {
export(map.getUnzipXml(), outputStream); export(map.getUnzipXml(), outputStream);
@ -72,7 +72,7 @@ public class FreemindExporter
mindmapMap = (com.wisemapping.jaxb.wisemap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.jaxb.wisemap"); mindmapMap = (com.wisemapping.jaxb.wisemap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.jaxb.wisemap");
final com.wisemapping.jaxb.freemind.Map freemindMap = objectFactory.createMap(); final com.wisemapping.jaxb.freemind.Map freemindMap = objectFactory.createMap();
freemindMap.setVersion(this.getVersion()); freemindMap.setVersion(this.getVersionNumber());
final List<TopicType> topics = mindmapMap.getTopic(); final List<TopicType> topics = mindmapMap.getTopic();
@ -152,9 +152,9 @@ public class FreemindExporter
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 ? FreemindConstant.POSITION_LEFT : FreemindConstant.POSITION_RIGHT));
} else { } else {
newNode.setPOSITION(POSITION_LEFT); newNode.setPOSITION(FreemindConstant.POSITION_LEFT);
} }
} }
} }
@ -279,7 +279,7 @@ public class FreemindExporter
int countParts = part.length; int countParts = part.length;
boolean updated = false; boolean updated = false;
if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) { if (!fontStyle.endsWith(FreemindConstant.EMPTY_FONT_STYLE)) {
int idx = 0; int idx = 0;
// Font name // Font name
@ -345,11 +345,15 @@ public class FreemindExporter
} }
public String getVersion() { public VersionNumber getVersion() {
return version; return version;
} }
public void setVersion(String version) { public void setVersion(VersionNumber version) {
this.version = version; this.version = version;
} }
public String getVersionNumber() {
return this.getVersion().getVersion();
}
} }

View File

@ -0,0 +1,34 @@
package com.wisemapping.importer.freemind;
import com.wisemapping.importer.VersionNumber;
import java.nio.charset.Charset;
public interface FreemindConstant {
public static final String LAST_SUPPORTED_FREEMIND_VERSION = "1.0.1";
public static final VersionNumber SUPPORTED_FREEMIND_VERSION = new VersionNumber(LAST_SUPPORTED_FREEMIND_VERSION);
public static final String CODE_VERSION = "tango";
public static final int SECOND_LEVEL_TOPIC_HEIGHT = 25;
public static final int ROOT_LEVEL_TOPIC_HEIGHT = SECOND_LEVEL_TOPIC_HEIGHT;
public static final int CENTRAL_TO_TOPIC_DISTANCE = 200;
public static final int TOPIC_TO_TOPIC_DISTANCE = 90;
public static final int FONT_SIZE_HUGE = 15;
public static final int FONT_SIZE_LARGE = 10;
public static final int FONT_SIZE_NORMAL = 8;
public static final int FONT_SIZE_SMALL = 6;
public static final String NODE_TYPE = "NODE";
public static final String BOLD = "bold";
public static final String ITALIC = "italic";
public static final String EMPTY_FONT_STYLE = ";;;;;";
public static final String EMPTY_NOTE = "";
public static final String POSITION_LEFT = "left";
public static final String POSITION_RIGHT = "right";
public final static Charset UTF_8_CHARSET = Charset.forName("UTF-8");
}

View File

@ -44,38 +44,17 @@ import java.io.InputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
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 {
public static final String CODE_VERSION = "tango";
public static final int SECOND_LEVEL_TOPIC_HEIGHT = 25;
public static final int ROOT_LEVEL_TOPIC_HEIGHT = SECOND_LEVEL_TOPIC_HEIGHT;
public static final int CENTRAL_TO_TOPIC_DISTANCE = 200;
public static final int TOPIC_TO_TOPIC_DISTANCE = 90;
public static final String NODE_TYPE = "NODE";
private com.wisemapping.jaxb.wisemap.ObjectFactory mindmapObjectFactory; private com.wisemapping.jaxb.wisemap.ObjectFactory mindmapObjectFactory;
private static final String POSITION_LEFT = "left";
private static final String POSITION_RIGHT = "right";
private static final String BOLD = "bold";
private static final String ITALIC = "italic";
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 final static Charset UTF_8_CHARSET = Charset.forName("UTF-8");
private final static int ORDER_SEPARATION_FACTOR = 2;
private static final VersionNumber SUPPORTED_FREEMIND_VERSION = new VersionNumber("1.0.1");
private int currentId; private int currentId;
private static final int FONT_SIZE_HUGE = 15;
private static final int FONT_SIZE_LARGE = 10;
public static final int FONT_SIZE_NORMAL = 8;
private static final int FONT_SIZE_SMALL = 6;
public static void main(String argv[]) { public static void main(String argv[]) {
@ -120,7 +99,7 @@ public class FreemindImporter
if (version != null) { if (version != null) {
final VersionNumber mapVersion = new VersionNumber(version); final VersionNumber mapVersion = new VersionNumber(version);
if (mapVersion.isGreaterThan(SUPPORTED_FREEMIND_VERSION)) { if (mapVersion.isGreaterThan(FreemindConstant.SUPPORTED_FREEMIND_VERSION)) {
throw new ImporterException("FreeMind version " + mapVersion.getVersion() + " is not supported."); throw new ImporterException("FreeMind version " + mapVersion.getVersion() + " is not supported.");
} }
} }
@ -129,7 +108,7 @@ public class FreemindImporter
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final com.wisemapping.jaxb.wisemap.Map mindmapMap = mindmapObjectFactory.createMap(); final com.wisemapping.jaxb.wisemap.Map mindmapMap = mindmapObjectFactory.createMap();
mindmapMap.setVersion(CODE_VERSION); mindmapMap.setVersion(FreemindConstant.CODE_VERSION);
currentId = 0; currentId = 0;
final Node freeNode = freemindMap.getNode(); final Node freeNode = freemindMap.getNode();
@ -150,7 +129,7 @@ public class FreemindImporter
addRelationships(mindmapMap); addRelationships(mindmapMap);
JAXBUtils.saveMap(mindmapMap, baos); JAXBUtils.saveMap(mindmapMap, baos);
wiseXml = new String(baos.toByteArray(), UTF_8_CHARSET); wiseXml = new String(baos.toByteArray(), FreemindConstant.UTF_8_CHARSET);
result.setXmlStr(wiseXml); result.setXmlStr(wiseXml);
result.setTitle(mapName); result.setTitle(mapName);
result.setDescription(description); result.setDescription(description);
@ -248,7 +227,7 @@ public class FreemindImporter
if (depth != 1) { if (depth != 1) {
norder = order++; norder = order++;
} else { } else {
if (freeChild.getPOSITION() != null && freeChild.getPOSITION().equals(POSITION_LEFT)) { if (freeChild.getPOSITION() != null && freeChild.getPOSITION().equals(FreemindConstant.POSITION_LEFT)) {
norder = firstLevelLeftOrder; norder = firstLevelLeftOrder;
firstLevelLeftOrder = firstLevelLeftOrder + 2; firstLevelLeftOrder = firstLevelLeftOrder + 2;
} else { } else {
@ -299,7 +278,7 @@ public class FreemindImporter
String textNote = hook.getText(); String textNote = hook.getText();
if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook
{ {
textNote = EMPTY_NOTE; textNote = FreemindConstant.EMPTY_NOTE;
mindmapNote.setValue(textNote); mindmapNote.setValue(textNote);
currentWiseTopic.setNote(mindmapNote); currentWiseTopic.setNote(mindmapNote);
} }
@ -307,13 +286,13 @@ public class FreemindImporter
final Richcontent content = (Richcontent) element; final Richcontent content = (Richcontent) element;
final String type = content.getTYPE(); final String type = content.getTYPE();
if (type.equals(NODE_TYPE)) { if (type.equals(FreemindConstant.NODE_TYPE)) {
String text = html2text(content); String text = html2text(content);
currentWiseTopic.setText(text); currentWiseTopic.setText(text);
} else { } else {
String text = html2text(content); String text = html2text(content);
final com.wisemapping.jaxb.wisemap.Note mindmapNote = new com.wisemapping.jaxb.wisemap.Note(); final com.wisemapping.jaxb.wisemap.Note mindmapNote = new com.wisemapping.jaxb.wisemap.Note();
text = text != null ? text : EMPTY_NOTE; text = text != null ? text : FreemindConstant.EMPTY_NOTE;
mindmapNote.setValue(text); mindmapNote.setValue(text);
currentWiseTopic.setNote(mindmapNote); currentWiseTopic.setNote(mindmapNote);
@ -355,7 +334,7 @@ public class FreemindImporter
int result = 0; int result = 0;
String childSide = freeChild.getPOSITION(); String childSide = freeChild.getPOSITION();
if (childSide == null) { if (childSide == null) {
childSide = POSITION_RIGHT; childSide = FreemindConstant.POSITION_RIGHT;
} }
// Count all the nodes of the same side ... // Count all the nodes of the same side ...
@ -365,7 +344,7 @@ public class FreemindImporter
String side = node.getPOSITION(); String side = node.getPOSITION();
if (side == null) { if (side == null) {
side = POSITION_RIGHT; side = FreemindConstant.POSITION_RIGHT;
} }
if (childSide.equals(side)) { if (childSide.equals(side)) {
result++; result++;
@ -390,11 +369,11 @@ public class FreemindImporter
// Problem on setting X position: // Problem on setting X position:
// Text Size is not taken into account ... // Text Size is not taken into account ...
int x = CENTRAL_TO_TOPIC_DISTANCE + ((depth - 1) * TOPIC_TO_TOPIC_DISTANCE); int x = FreemindConstant.CENTRAL_TO_TOPIC_DISTANCE + ((depth - 1) * FreemindConstant.TOPIC_TO_TOPIC_DISTANCE);
if (depth == 1) { if (depth == 1) {
final String side = freeChild.getPOSITION(); final String side = freeChild.getPOSITION();
x = x * (side != null && POSITION_LEFT.equals(side) ? -1 : 1); x = x * (side != null && FreemindConstant.POSITION_LEFT.equals(side) ? -1 : 1);
} else { } else {
final Coord coord = Coord.parse(wiseParent.getPosition()); final Coord coord = Coord.parse(wiseParent.getPosition());
x = x * (coord.isOnLeftSide() ? -1 : 1); x = x * (coord.isOnLeftSide() ? -1 : 1);
@ -409,17 +388,17 @@ public class FreemindImporter
// odd order numbers represent nodes at the left // odd order numbers represent nodes at the left
if (order % 2 == 0) { if (order % 2 == 0) {
int multiplier = ((order + 1) - childrenCount) * 2; int multiplier = ((order + 1) - childrenCount) * 2;
y = multiplier * ROOT_LEVEL_TOPIC_HEIGHT; y = multiplier * FreemindConstant.ROOT_LEVEL_TOPIC_HEIGHT;
} else { } else {
int multiplier = (order - childrenCount) * 2; int multiplier = (order - childrenCount) * 2;
y = multiplier * ROOT_LEVEL_TOPIC_HEIGHT; y = multiplier * FreemindConstant.ROOT_LEVEL_TOPIC_HEIGHT;
} }
} else { } else {
// Problem: What happen if the node is more tall than what is defined here. // Problem: What happen if the node is more tall than what is defined here.
Coord coord = Coord.parse(wiseParent.getPosition()); Coord coord = Coord.parse(wiseParent.getPosition());
int parentY = coord.y; int parentY = coord.y;
y = parentY - ((childrenCount / 2) * SECOND_LEVEL_TOPIC_HEIGHT - (order * SECOND_LEVEL_TOPIC_HEIGHT)); y = parentY - ((childrenCount / 2) * FreemindConstant.SECOND_LEVEL_TOPIC_HEIGHT - (order * FreemindConstant.SECOND_LEVEL_TOPIC_HEIGHT));
} }
@ -551,14 +530,14 @@ public class FreemindImporter
// 10 Large // 10 Large
// 15 Huge // 15 Huge
if (font != null) { if (font != null) {
final int fontSize = ((font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(FONT_SIZE_NORMAL) : font.getSIZE()).intValue(); final int fontSize = ((font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(FreemindConstant.FONT_SIZE_NORMAL) : font.getSIZE()).intValue();
int wiseFontSize = FONT_SIZE_SMALL; int wiseFontSize = FreemindConstant.FONT_SIZE_SMALL;
if (fontSize >= 24) { if (fontSize >= 24) {
wiseFontSize = FONT_SIZE_HUGE; wiseFontSize = FreemindConstant.FONT_SIZE_HUGE;
} else if (fontSize >= 16) { } else if (fontSize >= 16) {
wiseFontSize = FONT_SIZE_LARGE; wiseFontSize = FreemindConstant.FONT_SIZE_LARGE;
} else if (fontSize >= 12) { } else if (fontSize >= 12) {
wiseFontSize = FONT_SIZE_NORMAL; wiseFontSize = FreemindConstant.FONT_SIZE_NORMAL;
} }
fontStyle.append(wiseFontSize); fontStyle.append(wiseFontSize);
@ -575,19 +554,19 @@ public class FreemindImporter
// Bold ... // Bold ...
if (font != null) { if (font != null) {
boolean hasBold = Boolean.parseBoolean(font.getBOLD()); boolean hasBold = Boolean.parseBoolean(font.getBOLD());
fontStyle.append(hasBold ? BOLD : ""); fontStyle.append(hasBold ? FreemindConstant.BOLD : "");
} }
fontStyle.append(";"); fontStyle.append(";");
// Italic ... // Italic ...
if (font != null) { if (font != null) {
boolean hasItalic = Boolean.parseBoolean(font.getITALIC()); boolean hasItalic = Boolean.parseBoolean(font.getITALIC());
fontStyle.append(hasItalic ? ITALIC : ""); fontStyle.append(hasItalic ? FreemindConstant.ITALIC : "");
} }
fontStyle.append(";"); fontStyle.append(";");
final String result = fontStyle.toString(); final String result = fontStyle.toString();
return result.equals(EMPTY_FONT_STYLE) ? null : result; return result.equals(FreemindConstant.EMPTY_FONT_STYLE) ? null : result;
} }
private private