- Remove commited JAXB stubs

- Export support multiline notes.
This commit is contained in:
Paulo Gustavo Veiga
2012-03-06 23:26:11 -03:00
parent 6506b60977
commit 25f1e2f549
84 changed files with 3322 additions and 10578 deletions

View File

@@ -1,54 +1,55 @@
/*
* 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.importer;
import com.wisemapping.importer.freemind.FreemindImporter;
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(ImportFormat format)
throws ImporterException
{
Importer importer;
switch (format)
{
case FREEMIND:
importer = new FreemindImporter();
break;
default:
throw new ImporterException("Invalid format type:" + format);
}
return importer;
}
}
/*
* 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.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;
}
}

View File

@@ -0,0 +1,36 @@
package com.wisemapping.importer;
import java.io.OutputStream;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
@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"}); //
// set any other options you'd like
// of.setPreserveSpace(true);
of.setIndenting(true);
// create the serializer
XMLSerializer result = new XMLSerializer(of);
result.setOutputByteStream(out);
return result;
}
}

View File

@@ -25,12 +25,12 @@ import com.wisemapping.importer.VersionNumber;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.ShapeStyle;
import com.wisemapping.util.JAXBUtils;
import com.wisemapping.xml.freemind.*;
import com.wisemapping.xml.freemind.Map;
import com.wisemapping.xml.freemind.Node;
import com.wisemapping.xml.mindmap.RelationshipType;
import com.wisemapping.xml.mindmap.TopicType;
import com.wisemapping.xml.mindmap.Link;
import com.wisemapping.jaxb.freemind.*;
import com.wisemapping.jaxb.freemind.Map;
import com.wisemapping.jaxb.freemind.Node;
import com.wisemapping.jaxb.mindmap.RelationshipType;
import com.wisemapping.jaxb.mindmap.TopicType;
import com.wisemapping.jaxb.mindmap.Link;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.*;
@@ -46,12 +46,12 @@ import java.math.BigInteger;
public class FreemindImporter
implements Importer {
public static final String CODE_VERSION = "pela";
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;
private com.wisemapping.xml.mindmap.ObjectFactory mindmapObjectFactory;
private com.wisemapping.jaxb.mindmap.ObjectFactory mindmapObjectFactory;
private static final String POSITION_LEFT = "left";
private static final String BOLD = "bold";
private static final String ITALIC = "italic";
@@ -99,11 +99,11 @@ public class FreemindImporter
final MindMap result = new MindMap();
nodesMap = new HashMap<String, TopicType>();
relationships = new ArrayList<RelationshipType>();
mindmapObjectFactory = new com.wisemapping.xml.mindmap.ObjectFactory();
mindmapObjectFactory = new com.wisemapping.jaxb.mindmap.ObjectFactory();
try {
String wiseXml;
final Map freemindMap = (Map) JAXBUtils.getMapObject(input, "com.wisemapping.xml.freemind");
final Map freemindMap = (Map) JAXBUtils.getMapObject(input, "com.wisemapping.jaxb.freemind");
final String version = freemindMap.getVersion();
if (version != null) {
@@ -116,7 +116,7 @@ public class FreemindImporter
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final com.wisemapping.xml.mindmap.Map mindmapMap = mindmapObjectFactory.createMap();
final com.wisemapping.jaxb.mindmap.Map mindmapMap = mindmapObjectFactory.createMap();
mindmapMap.setVersion(CODE_VERSION);
currentId = 0;
@@ -137,7 +137,7 @@ public class FreemindImporter
convertChildNodes(freeNode, wiseTopic, 1);
addRelationships(mindmapMap);
JAXBUtils.saveMap(mindmapMap, baos, "com.wisemapping.xml.mindmap");
JAXBUtils.saveMap(mindmapMap, baos, "com.wisemapping.jaxb.mindmap");
wiseXml = new String(baos.toByteArray(), UTF_8_CHARSET);
@@ -155,7 +155,7 @@ public class FreemindImporter
return result;
}
private void addRelationships(@NotNull com.wisemapping.xml.mindmap.Map mindmapMap) {
private void addRelationships(@NotNull com.wisemapping.jaxb.mindmap.Map mindmapMap) {
List<RelationshipType> mapRelationships = mindmapMap.getRelationship();
for (RelationshipType relationship : relationships) {
relationship.setId(String.valueOf(currentId++));
@@ -270,14 +270,14 @@ public class FreemindImporter
String iconId = freemindIcon.getBUILTIN();
final String wiseIconId = FreemindIconConverter.toWiseId(iconId);
if (wiseIconId != null) {
final com.wisemapping.xml.mindmap.Icon mindmapIcon = new com.wisemapping.xml.mindmap.Icon();
final com.wisemapping.jaxb.mindmap.Icon mindmapIcon = new com.wisemapping.jaxb.mindmap.Icon();
mindmapIcon.setId(wiseIconId);
currentWiseTopic.getIcon().add(mindmapIcon);
}
} else if (element instanceof Hook) {
final Hook hook = (Hook) element;
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
final com.wisemapping.jaxb.mindmap.Note mindmapNote = new com.wisemapping.jaxb.mindmap.Note();
String textNote = hook.getText();
if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook
{
@@ -291,13 +291,11 @@ public class FreemindImporter
if (type.equals("NODE")) {
String text = getText(content);
text = text.replaceAll("\n", "");
text = text.trim();
currentWiseTopic.setText(text);
} else {
String text = getRichContent(content);
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
text = text != null ? text.replaceAll("\n", "%0A") : EMPTY_NOTE;
final com.wisemapping.jaxb.mindmap.Note mindmapNote = new com.wisemapping.jaxb.mindmap.Note();
text = text != null ? text : EMPTY_NOTE;
mindmapNote.setText(text);
currentWiseTopic.setNote(mindmapNote);
@@ -347,41 +345,36 @@ public class FreemindImporter
final List<Node> nodes = new ArrayList<Node>();
int result;
if (freeChild.getWorder() != null) {
result = freeChild.getWorder().intValue();
// Collect all the nodes of the same side ...
for (Object child : freeChilden) {
if (child instanceof Node) {
Node node = (Node) child;
final String side = node.getPOSITION();
if (freeChild.getPOSITION().equals(side)) {
nodes.add(node);
}
}
}
// What is the index of the current node ?
int nodeIndex = 0;
for (Node node : nodes) {
if (node == freeChild) {
break;
}
nodeIndex++;
}
int size = nodes.size();
int center = (size - 1) / 2;
result = nodeIndex - center;
if (result < 0) {
result = (result * ORDER_SEPARATION_FACTOR * -2) - 1;
} else {
// Collect all the nodes of the same side ...
for (Object child : freeChilden) {
if (child instanceof Node) {
Node node = (Node) child;
final String side = node.getPOSITION();
if (freeChild.getPOSITION().equals(side)) {
nodes.add(node);
}
}
}
// What is the index of the current node ?
int nodeIndex = 0;
for (Node node : nodes) {
if (node == freeChild) {
break;
}
nodeIndex++;
}
int size = nodes.size();
int center = (size - 1) / 2;
result = nodeIndex - center;
if (result < 0) {
result = (result * ORDER_SEPARATION_FACTOR * -2) - 1;
} else {
result = result * ORDER_SEPARATION_FACTOR * 2;
}
result = result * ORDER_SEPARATION_FACTOR * 2;
}
return result;
}
@@ -396,53 +389,50 @@ public class FreemindImporter
String convertPosition(@NotNull TopicType wiseParent, @NotNull Node freeChild, final int depth, int order, int childrenCount) {
// Which side must be the node be positioned ?
String result = freeChild.getWcoords();
if (result == null) {
// Calculate X ...
// Calculate X ...
// Problem on setting X position:
// Text Size is not taken into account ...
int x = CENTRAL_TO_TOPIC_DISTANCE + ((depth - 1) * TOPIC_TO_TOPIC_DISTANCE);
if (depth == 1) {
// Problem on setting X position:
// Text Size is not taken into account ...
int x = CENTRAL_TO_TOPIC_DISTANCE + ((depth - 1) * TOPIC_TO_TOPIC_DISTANCE);
if (depth == 1) {
final String side = freeChild.getPOSITION();
assert side != null : "This should not happen";
x = x * (POSITION_LEFT.equals(side) ? -1 : 1);
final String side = freeChild.getPOSITION();
assert side != null : "This should not happen";
x = x * (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) {
// Follow the following algorithm ...
// Order: 3 = -100 1
// Order: 1 = -50 2
// Order: 0 = 0 3
// Order: 2 = 50 4
// Order: 4 = 100 5
if (order % 2 == 0) {
y = ROOT_LEVEL_TOPIC_HEIGHT * order;
} else {
final Coord coord = Coord.parse(wiseParent.getPosition());
x = x * (coord.isOnLeftSide() ? -1 : 1);
y = -ROOT_LEVEL_TOPIC_HEIGHT * (order + 1);
}
} 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) * SECOND_LEVEL_TOPIC_HEIGHT - (order * SECOND_LEVEL_TOPIC_HEIGHT));
// Calculate y ...
int y;
if (depth == 1) {
// Follow the following algorithm ...
// Order: 3 = -100 1
// Order: 1 = -50 2
// Order: 0 = 0 3
// Order: 2 = 50 4
// Order: 4 = 100 5
if (order % 2 == 0) {
y = ROOT_LEVEL_TOPIC_HEIGHT * order;
} else {
y = -ROOT_LEVEL_TOPIC_HEIGHT * (order + 1);
}
} 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) * SECOND_LEVEL_TOPIC_HEIGHT - (order * SECOND_LEVEL_TOPIC_HEIGHT));
}
result = x + "," + y;
}
return result;
return x + "," + y;
}
/**
@@ -546,7 +536,7 @@ public class FreemindImporter
return text.toString();
}
private void convertNodeProperties(@NotNull com.wisemapping.xml.freemind.Node freeNode, @NotNull com.wisemapping.xml.mindmap.TopicType wiseTopic) {
private void convertNodeProperties(@NotNull com.wisemapping.jaxb.freemind.Node freeNode, @NotNull com.wisemapping.jaxb.mindmap.TopicType wiseTopic) {
final String text = freeNode.getTEXT();
wiseTopic.setText(text);