Replace read file for FileUtils

Change jaxb mindmap package
Fix failing tests for encodding issues.
This commit is contained in:
Paulo Gustavo Veiga
2012-03-10 16:33:00 -03:00
parent 0660c7e8c3
commit b26f9715ff
21 changed files with 83 additions and 2102 deletions

View File

@@ -24,9 +24,9 @@ import com.wisemapping.model.MindMap;
import com.wisemapping.model.ShapeStyle;
import com.wisemapping.util.JAXBUtils;
import com.wisemapping.jaxb.freemind.*;
import com.wisemapping.jaxb.mindmap.RelationshipType;
import com.wisemapping.jaxb.mindmap.TopicType;
import com.wisemapping.jaxb.mindmap.Icon;
import com.wisemapping.jaxb.wisemap.RelationshipType;
import com.wisemapping.jaxb.wisemap.TopicType;
import com.wisemapping.jaxb.wisemap.Icon;
import org.jetbrains.annotations.NotNull;
import javax.xml.bind.JAXBException;
@@ -52,15 +52,15 @@ public class FreemindExporter
export(map.getXml(), outputStream);
}
public void export(byte[] xml, OutputStream outputStream) throws ExportException {
public void export(byte[] xml, @NotNull OutputStream outputStream) throws ExportException {
objectFactory = new com.wisemapping.jaxb.freemind.ObjectFactory();
nodesMap = new HashMap<String, Node>();
final com.wisemapping.jaxb.mindmap.Map mindmapMap;
final com.wisemapping.jaxb.wisemap.Map mindmapMap;
try {
final ByteArrayInputStream stream = new ByteArrayInputStream(xml);
mindmapMap = (com.wisemapping.jaxb.mindmap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.jaxb.mindmap");
mindmapMap = (com.wisemapping.jaxb.wisemap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.jaxb.wisemap");
final com.wisemapping.jaxb.freemind.Map freemindMap = objectFactory.createMap();
freemindMap.setVersion(FREE_MIND_VERSION);
@@ -104,7 +104,7 @@ public class FreemindExporter
cloudOrEdge.add(arrowlink);
}
JAXBUtils.saveMap(freemindMap, outputStream, "com.wisemapping.jaxb.freemind");
JAXBUtils.saveMap(freemindMap, outputStream);
} catch (JAXBException e) {
throw new ExportException(e);
}
@@ -128,7 +128,7 @@ public class FreemindExporter
}
}
private void setTopicPropertiesToNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, @NotNull com.wisemapping.jaxb.mindmap.TopicType mindmapTopic, boolean isRoot) {
private void setTopicPropertiesToNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, @NotNull com.wisemapping.jaxb.wisemap.TopicType mindmapTopic, boolean isRoot) {
freemindNode.setID("ID_" + mindmapTopic.getId());
String text = mindmapTopic.getTextAttr();
@@ -160,7 +160,7 @@ public class FreemindExporter
}
}
private void addNote(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.mindmap.TopicType mindmapTopic) {
private void addNote(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) {
if (mindmapTopic.getNote() != null) {
final Hook note = new Hook();
String textNote = mindmapTopic.getNote().getTextAttr();
@@ -174,14 +174,14 @@ public class FreemindExporter
}
}
private void addLinkNode(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.mindmap.TopicType mindmapTopic) {
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.mindmap.TopicType mindmapTopic) {
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) {
@@ -197,7 +197,7 @@ public class FreemindExporter
}
}
private void addEdgeNode(com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.mindmap.TopicType mindmapTopic) {
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(mindmapTopic.getBrColor());
@@ -210,7 +210,7 @@ public class FreemindExporter
* eg: Verdana;10;#ffffff;bold;italic;
*
*/
private void addFontNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.mindmap.TopicType mindmapTopic) {
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();

View File

@@ -25,6 +25,7 @@ public class JaxbCDATAMarshaller {
// 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);

View File

@@ -28,9 +28,9 @@ import com.wisemapping.util.JAXBUtils;
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 com.wisemapping.jaxb.wisemap.RelationshipType;
import com.wisemapping.jaxb.wisemap.TopicType;
import com.wisemapping.jaxb.wisemap.Link;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.*;
@@ -51,7 +51,7 @@ public class FreemindImporter
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.jaxb.mindmap.ObjectFactory mindmapObjectFactory;
private com.wisemapping.jaxb.wisemap.ObjectFactory mindmapObjectFactory;
private static final String POSITION_LEFT = "left";
private static final String BOLD = "bold";
private static final String ITALIC = "italic";
@@ -99,7 +99,7 @@ public class FreemindImporter
final MindMap result = new MindMap();
nodesMap = new HashMap<String, TopicType>();
relationships = new ArrayList<RelationshipType>();
mindmapObjectFactory = new com.wisemapping.jaxb.mindmap.ObjectFactory();
mindmapObjectFactory = new com.wisemapping.jaxb.wisemap.ObjectFactory();
try {
String wiseXml;
@@ -116,7 +116,7 @@ public class FreemindImporter
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final com.wisemapping.jaxb.mindmap.Map mindmapMap = mindmapObjectFactory.createMap();
final com.wisemapping.jaxb.wisemap.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.jaxb.mindmap");
JAXBUtils.saveMap(mindmapMap, baos);
wiseXml = new String(baos.toByteArray(), UTF_8_CHARSET);
@@ -155,7 +155,7 @@ public class FreemindImporter
return result;
}
private void addRelationships(@NotNull com.wisemapping.jaxb.mindmap.Map mindmapMap) {
private void addRelationships(@NotNull com.wisemapping.jaxb.wisemap.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.jaxb.mindmap.Icon mindmapIcon = new com.wisemapping.jaxb.mindmap.Icon();
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.mindmap.Note mindmapNote = new com.wisemapping.jaxb.mindmap.Note();
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
{
@@ -294,7 +294,7 @@ public class FreemindImporter
currentWiseTopic.setText(text);
} else {
String text = getRichContent(content);
final com.wisemapping.jaxb.mindmap.Note mindmapNote = new com.wisemapping.jaxb.mindmap.Note();
final com.wisemapping.jaxb.wisemap.Note mindmapNote = new com.wisemapping.jaxb.wisemap.Note();
text = text != null ? text : EMPTY_NOTE;
mindmapNote.setText(text);
currentWiseTopic.setNote(mindmapNote);
@@ -536,7 +536,7 @@ public class FreemindImporter
return text.toString();
}
private void convertNodeProperties(@NotNull com.wisemapping.jaxb.freemind.Node freeNode, @NotNull com.wisemapping.jaxb.mindmap.TopicType wiseTopic) {
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);

View File

@@ -57,9 +57,9 @@ public class JAXBUtils {
}
public static void saveMap(@NotNull Object obj, @NotNull OutputStream out, String packag) throws JAXBException {
public static void saveMap(@NotNull com.wisemapping.jaxb.wisemap.Map obj, @NotNull OutputStream out) throws JAXBException {
final JAXBContext context = getInstance(packag);
final JAXBContext context = getInstance("com.wisemapping.jaxb.wisemap");
final Marshaller marshaller = context.createMarshaller();
// get an Apache XMLSerializer configured to generate CDATA
@@ -72,4 +72,11 @@ public class JAXBUtils {
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.marshal(map, out);
}
}