diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java b/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java index e5ba98f9..54c8f664 100644 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java @@ -126,7 +126,7 @@ public class ExporterFactory { } case FREEMIND: { final FreemindExporter exporter = new FreemindExporter(); - exporter.export(xml.getBytes(), output); + exporter.export(xml.getBytes("UTF-8"), output); break; } default: diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/FreemindExporter.java b/wise-webapp/src/main/java/com/wisemapping/exporter/FreemindExporter.java index 79ea6661..be7a7ae3 100755 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/FreemindExporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/FreemindExporter.java @@ -20,6 +20,7 @@ package com.wisemapping.exporter; import com.wisemapping.importer.freemind.FreemindIconConverter; +import com.wisemapping.jaxb.wisemap.Note; import com.wisemapping.model.Mindmap; import com.wisemapping.model.ShapeStyle; import com.wisemapping.util.JAXBUtils; @@ -28,10 +29,17 @@ import com.wisemapping.jaxb.wisemap.RelationshipType; import com.wisemapping.jaxb.wisemap.TopicType; import com.wisemapping.jaxb.wisemap.Icon; 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.IOException; import java.io.OutputStream; import java.io.ByteArrayInputStream; +import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.util.HashMap; import java.util.List; @@ -45,7 +53,6 @@ public class FreemindExporter private static final String POSITION_RIGHT = "right"; private com.wisemapping.jaxb.freemind.ObjectFactory objectFactory; private static final String EMPTY_FONT_STYLE = ";;;;;"; - private Map nodesMap = null; public void export(Mindmap map, OutputStream outputStream) throws ExportException { @@ -65,7 +72,6 @@ public class FreemindExporter final com.wisemapping.jaxb.freemind.Map freemindMap = objectFactory.createMap(); freemindMap.setVersion(FREE_MIND_VERSION); - final List topics = mindmapMap.getTopic(); // Isolated Topic does not exist in Freemind only take the center topic @@ -88,7 +94,8 @@ public class FreemindExporter setTopicPropertiesToNode(main, centerTopic, true); addNodeFromTopic(centerTopic, main); } - List relationships = mindmapMap.getRelationship(); + + final List relationships = mindmapMap.getRelationship(); for (RelationshipType relationship : relationships) { Node srcNode = nodesMap.get(relationship.getSrcTopicId()); Node dstNode = nodesMap.get(relationship.getDestTopicId()); @@ -114,37 +121,57 @@ public class FreemindExporter JAXBUtils.saveMap(freemindMap, outputStream); } catch (JAXBException e) { throw new ExportException(e); + } catch (UnsupportedEncodingException e) { + throw new ExportException(e); + } catch (SAXException e) { + throw new ExportException(e); + } catch (ParserConfigurationException e) { + throw new ExportException(e); + } catch (IOException e) { + throw new ExportException(e); } } - private void addNodeFromTopic(@NotNull final TopicType mainTopic, @NotNull final Node destNode) { + private void addNodeFromTopic(@NotNull final TopicType mainTopic, @NotNull final Node destNode) throws IOException, SAXException, ParserConfigurationException { final List currentTopic = mainTopic.getTopic(); 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 ? POSITION_LEFT : POSITION_RIGHT)); + } else { + newNode.setPOSITION(POSITION_LEFT); } } } - private void setTopicPropertiesToNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, @NotNull com.wisemapping.jaxb.wisemap.TopicType mindmapTopic, boolean isRoot) { + 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(); } - freemindNode.setTEXT(text); - freemindNode.setBACKGROUNDCOLOR(mindmapTopic.getBgColor()); + // Formated text have a different representation .... + if (!text.contains("\n")) { + freemindNode.setTEXT(text); + } else { + final Richcontent richcontent = buildRichContent(text, "NODE"); + freemindNode.getArrowlinkOrCloudOrEdge().add(richcontent); + } + + freemindNode.setBACKGROUNDCOLOR(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)) { @@ -155,34 +182,49 @@ public class FreemindExporter } 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)); } + + 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 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(); - if (textNote == null || textNote.isEmpty()) { - textNote = mindmapTopic.getNote().getText(); + 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(""); + for (String line : text.split("\n")) { + htmlContent.append("

").append(line).append("

"); + } + htmlContent.append(""); + + DocumentBuilder db = getInstanceBuilder(); + Document document = db.parse(new ByteArrayInputStream(htmlContent.toString().getBytes())); + 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.getText() != null ? note.getText() : note.getTextAttr(); + if (noteStr != null) { + final Richcontent richcontent = buildRichContent(noteStr, "NOTE"); + fnode.getArrowlinkOrCloudOrEdge().add(richcontent); } - - // @Todo: For some reason central topic nodes with CDATA seems not to be loaded in the JAXB model. - // Temporally excluding and continue .. - textNote = (textNote != null) ? textNote : ""; - - textNote = textNote.replaceAll("%0A", "\n"); - note.setNAME("accessories/plugins/NodeNote.properties"); - note.setText(textNote); - freemindNode.getArrowlinkOrCloudOrEdge().add(note); } } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java b/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java index bfeeaf49..d921f565 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/view/TransformView.java @@ -84,8 +84,10 @@ public class TransformView extends AbstractView { // Write the conversion content ... final ServletOutputStream outputStream = response.getOutputStream(); if (exportFormat == ExportFormat.FREEMIND) { + response.setCharacterEncoding("iso-8859-1"); factory.export(properties, content, outputStream, null); } else if (exportFormat == ExportFormat.WISEMAPPING) { + response.setCharacterEncoding("UTF-8"); final Object mindmap = viewMap.get("mindmap"); final StreamResult result = new StreamResult(outputStream); jaxbMarshaller.marshal(mindmap, result); diff --git a/wise-webapp/src/main/java/com/wisemapping/util/JAXBUtils.java b/wise-webapp/src/main/java/com/wisemapping/util/JAXBUtils.java index 2197a71d..0f702061 100755 --- a/wise-webapp/src/main/java/com/wisemapping/util/JAXBUtils.java +++ b/wise-webapp/src/main/java/com/wisemapping/util/JAXBUtils.java @@ -26,9 +26,7 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.util.HashMap; import java.util.Map; @@ -36,12 +34,12 @@ public class JAXBUtils { private final static Map context = new HashMap(); - public static Object getMapObject(@NotNull InputStream stream, @NotNull final String pakage) throws JAXBException { + public static Object getMapObject(@NotNull InputStream is, @NotNull final String pakage) throws JAXBException, UnsupportedEncodingException { final JAXBContext context = getInstance(pakage); final Unmarshaller unmarshaller = context.createUnmarshaller(); - - return unmarshaller.unmarshal(stream); + final Reader reader = new InputStreamReader(is, "UTF-8"); + return unmarshaller.unmarshal(reader); } private static JAXBContext getInstance(@NotNull String pakage) throws JAXBException { @@ -78,6 +76,8 @@ public class JAXBUtils { 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); } } diff --git a/wise-webapp/src/main/webapp/WEB-INF/web.xml b/wise-webapp/src/main/webapp/WEB-INF/web.xml index 5f69438f..2e2b8b06 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/web.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/web.xml @@ -39,10 +39,6 @@ encoding UTF-8 - - forceEncoding - true - diff --git a/wise-webapp/src/test/java/com/wisemapping/test/freemind/ExportTest.java b/wise-webapp/src/test/java/com/wisemapping/test/freemind/ExportTest.java index 03a8b92c..075fa094 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/freemind/ExportTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/freemind/ExportTest.java @@ -16,25 +16,26 @@ import java.io.*; @Test public class ExportTest { private static final String DATA_DIR_PATH = "src/test/resources/data/wisemaps/"; - private static final String UTF_8 = "UTF-8"; + 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, "UTF-8"); + final String recContent = FileUtils.readFileToString(recFile, ENC_UTF_8); // Export mile content ... final ByteArrayOutputStream bos = new ByteArrayOutputStream(); freemindExporter.export(mindmap, bos); - final String exportContent = new String(bos.toByteArray(), UTF_8); + final String exportContent = new String(bos.toByteArray(), ENC_LATIN1); - Assert.assertEquals(recContent, exportContent); + Assert.assertEquals(exportContent, recContent); } else { final OutputStream fos = new FileOutputStream(recFile); @@ -71,6 +72,4 @@ public class ExportTest { return result; } - - } diff --git a/wise-webapp/src/test/resources/data/freemind/i18n2.mmr b/wise-webapp/src/test/resources/data/freemind/i18n2.mmr index 9f33cf32..0c8effc5 100644 --- a/wise-webapp/src/test/resources/data/freemind/i18n2.mmr +++ b/wise-webapp/src/test/resources/data/freemind/i18n2.mmr @@ -1,7 +1,25 @@ - - + + + + + +

This is a not in languange أَبْجَدِيَّة عَرَبِ

+ + +
+
+ + + + + +

Long text node:

+

أَبْجَدِيَّة عَرَب

+ + +
+
\ No newline at end of file diff --git a/wise-webapp/src/test/resources/data/freemind/longnodes.mmr b/wise-webapp/src/test/resources/data/freemind/longnodes.mmr index bb150cb6..c38d4021 100644 --- a/wise-webapp/src/test/resources/data/freemind/longnodes.mmr +++ b/wise-webapp/src/test/resources/data/freemind/longnodes.mmr @@ -1,9 +1,18 @@ - + + + + + +

Here is somefonts 

+

+

Add color changes ...

+

Add some bullets: Different Bullets

+

And all aligned !!!!s

+ + +
+
\ No newline at end of file diff --git a/wise-webapp/src/test/resources/data/freemind/richtextnode.mmr b/wise-webapp/src/test/resources/data/freemind/richtextnode.mmr index 11933aac..e304689b 100644 --- a/wise-webapp/src/test/resources/data/freemind/richtextnode.mmr +++ b/wise-webapp/src/test/resources/data/freemind/richtextnode.mmr @@ -1,8 +1,24 @@ - + + + + +

+ + + + + + + + +

bilan mi-parcours

+

du plan d'actions

+ + +
@@ -18,13 +34,29 @@ du plan d'actions" STYLE="bubble" POSITION="right" ID="ID_1" COLOR="#0000cc" BAC
- + + + + + +

1) Adapter et améliorer

+

notre offre de services

+

selon l'évolution des besoins

+ + +
- + + + + + +

couleurs = état d'avancement en septembre 2011,

+

à mettre à jour selon avancement 2012

+ + +
@@ -33,71 +65,175 @@ du plan d'actions" STYLE="bubble" POSITION="right" ID="ID_1" COLOR="#0000cc" BAC - + + + + + +

1.1. .Renforcer et structurer

+

le service "accueil et orientation"

+ + +
- + + + + + +

1.2. Adapter l'offre Halte-Garderie

+

aux besoins des familles

+ + +
- + + + + + +

1.3. Renforcer et structurer les services

+

de soutien à la parentalité

+ + +
- + + + + + +

1.4 Améliorer la qualité des

+

projets pédagogiques des ALSH

+ + +
- + + + + + +

1.5 Renforcer et améliorer les

+

activités de loisirs existantes

+ + +
- + + + + + +

1.6 Renforcer et améliorer les ateliers  

+

visant à  rompre l'isolement lié à la langue,

+

la pauvreté, la pression de la consommation

+ + +
- + + + + + +

2) Consolider nos moyens d'action :

+

locaux, organisation, communication interne

+ + +
- + + + + + +

2.1 Formaliser notre offre de services

+

et les modèles économiques correspondants

+ + +
- + + + + + +

2.2 Formaliser le "qui fait quoi"

+

en lien avec notre offre de service

+ + +
- + + + + + +

2.3. Elaborer un projet immobilier de proximité

+

réalisable au  centre ville

+ + +
- + + + + + +

3) Renforcer nos

+

partenariats et

+

notre notoriété

+ + +
- + + + + + +

3.1 Organiser pour chaque segment de notre offre

+

l'identification et la rencontre des partenaires concernés

+ + +
- + + + + + +

3.2 Formaliser et contractualiser les partenariats

+

émergeants autour d'actions communes

+ + +
@@ -106,8 +242,16 @@ du plan d'actions" STYLE="bubble" POSITION="right" ID="ID_1" COLOR="#0000cc" BAC - + + + + + +

3.4 définir et faire vivre un plan de communication

+

à partir de notre segmentation de l'offre

+ + +
diff --git a/wise-webapp/src/test/resources/data/wisemaps/bigmap.mmr b/wise-webapp/src/test/resources/data/wisemaps/bigmap.mmr index c4c18195..fe9cc3c2 100644 --- a/wise-webapp/src/test/resources/data/wisemaps/bigmap.mmr +++ b/wise-webapp/src/test/resources/data/wisemaps/bigmap.mmr @@ -1,264 +1,263 @@ - - - - - + + + + - + - - - + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - + + + - - - - - - + + + + + + - - + + - - + + - - - - - - + + + + + + - - - - + + + + - - - - + + + + - - - + + + - - - - + + + + - - + + - - - - + + + + - - - + + + - - - - + + + + - + - - - - + + + + - + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + - - - - + + + + - - - + + + - - - - - - - - + + + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - - - - - + + + + + + + + + - + - - - - - - - + + + + + + + - - + + - - + + - - + + - - - - - + + + + + - + - - - - + + + + - - - + + + - - - - - - + + + + + + - - - - + + + + - - - + + + - - - + + + - +
\ No newline at end of file diff --git a/wise-webapp/src/test/resources/data/wisemaps/cdata-support.mmr b/wise-webapp/src/test/resources/data/wisemaps/cdata-support.mmr index ff0d661b..3e054103 100644 --- a/wise-webapp/src/test/resources/data/wisemaps/cdata-support.mmr +++ b/wise-webapp/src/test/resources/data/wisemaps/cdata-support.mmr @@ -1,8 +1,3 @@ - - - - - - - + + \ No newline at end of file diff --git a/wise-webapp/src/test/resources/data/wisemaps/npe.mmr b/wise-webapp/src/test/resources/data/wisemaps/npe.mmr index 1e3e3b53..c7043fac 100644 --- a/wise-webapp/src/test/resources/data/wisemaps/npe.mmr +++ b/wise-webapp/src/test/resources/data/wisemaps/npe.mmr @@ -1,4 +1,3 @@ - - + \ No newline at end of file diff --git a/wise-webapp/src/test/resources/data/wisemaps/simple-maps.mmr b/wise-webapp/src/test/resources/data/wisemaps/simple-maps.mmr index ff76ed62..701194f8 100644 --- a/wise-webapp/src/test/resources/data/wisemaps/simple-maps.mmr +++ b/wise-webapp/src/test/resources/data/wisemaps/simple-maps.mmr @@ -1,6 +1,5 @@ - - + @@ -13,606 +12,606 @@ - + - + - + - + - + - + - - - + + + - + - - + + - - - + + + - + - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + @@ -620,4 +619,4 @@ - + \ No newline at end of file diff --git a/wise-webapp/src/test/resources/data/wisemaps/welcome.mmr b/wise-webapp/src/test/resources/data/wisemaps/welcome.mmr index 492c9904..50934c55 100644 --- a/wise-webapp/src/test/resources/data/wisemaps/welcome.mmr +++ b/wise-webapp/src/test/resources/data/wisemaps/welcome.mmr @@ -1,35 +1,64 @@ - - - - - - + + + + + + + + + + + + - - - + + + + + + + + + + +

Brainstorming

+

with

+

some

+

lines

+ + +
+
- + - + - + + + - + + + - - + + + + + + -
+ \ No newline at end of file