diff --git a/wise-webapp/pom.xml b/wise-webapp/pom.xml index 00090372..bff5060c 100644 --- a/wise-webapp/pom.xml +++ b/wise-webapp/pom.xml @@ -9,7 +9,7 @@ org.wisemapping wisemapping ../pom.xml - 3.0-SNAPSHOT + 3.1-SNAPSHOT diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/ExportFormat.java b/wise-webapp/src/main/java/com/wisemapping/exporter/ExportFormat.java index 7bc60eca..560ae519 100644 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/ExportFormat.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/ExportFormat.java @@ -26,9 +26,12 @@ public enum ExportFormat { PNG("image/png", "png"), PDF("application/pdf", "pdf"), FREEMIND("application/freemind", "mm"), + TEXT("text/plain", "txt"), + MICROSOFT_EXCEL("application/vnd.ms-excel", "xls"), + MICROSOFT_WORD("application/msword", "doc"), + OPEN_OFFICE_WRITER("application/vnd.oasis.opendocument.text", "odt"), WISEMAPPING("application/wisemapping+xml", "wxml"); - private String contentType; private String fileExtension; diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/Exporter.java b/wise-webapp/src/main/java/com/wisemapping/exporter/Exporter.java index f2b86523..7516a5fc 100755 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/Exporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/Exporter.java @@ -19,10 +19,11 @@ package com.wisemapping.exporter; import com.wisemapping.model.Mindmap; +import org.jetbrains.annotations.NotNull; import java.io.OutputStream; public interface Exporter { - public void export(byte[] xml, OutputStream outputStream) throws ExportException; + public void export(@NotNull byte[] xml, @NotNull OutputStream outputStream) throws ExportException; public void export(Mindmap map, OutputStream outputStream) throws ExportException; } 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 6ece42b7..6c717f5f 100644 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java @@ -124,6 +124,21 @@ public class ExporterFactory { output.write(svgString.getBytes("UTF-8")); break; } + case TEXT: { + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.TEXT); + exporter.export(xml.getBytes("UTF-8"), output); + break; + } + case OPEN_OFFICE_WRITER: { + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.OPEN_OFFICE); + exporter.export(xml.getBytes("UTF-8"), output); + break; + } + case MICROSOFT_EXCEL: { + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.MICROSOFT_EXCEL); + exporter.export(xml.getBytes("UTF-8"), output); + break; + } case FREEMIND: { final FreemindExporter exporter = new FreemindExporter(); exporter.export(xml.getBytes("UTF-8"), output); diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/XSLTExporter.java b/wise-webapp/src/main/java/com/wisemapping/exporter/XSLTExporter.java new file mode 100644 index 00000000..f0e163ef --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/XSLTExporter.java @@ -0,0 +1,88 @@ +package com.wisemapping.exporter; + +import com.wisemapping.model.Mindmap; +import org.jetbrains.annotations.NotNull; + +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.*; + +public class XSLTExporter implements Exporter { + + private Type type; + + public XSLTExporter(@NotNull Type type) { + this.type = type; + } + + @Override + public void export(@NotNull byte[] xml, @NotNull OutputStream outputStream) throws ExportException { + final ByteArrayOutputStream mmos = new ByteArrayOutputStream(); + + // Convert to freemind ... + final FreemindExporter exporter = new FreemindExporter(); + exporter.export(xml, mmos); + + // Convert to xslt transform ... + final InputStream xsltis = this.getClass().getResourceAsStream("/com/wisemapping/export/xslt/" + type.getXsltName()); + if (xsltis == null) { + throw new IllegalStateException("XSLT could not be resolved."); + } + + try { + final TransformerFactory factory = TransformerFactory.newInstance(); + final Source xslt = new StreamSource(xsltis); + Transformer transformer = factory.newTransformer(xslt); + + final CharArrayReader reader = new CharArrayReader(mmos.toString("iso-8859-1").toCharArray()); + final Source mmSource = new StreamSource(reader); + transformer.transform(mmSource, new StreamResult(outputStream)); + } catch (TransformerException e) { + throw new ExportException(e); + } catch (UnsupportedEncodingException e) { + throw new ExportException(e); + } + + } + + @Override + public void export(@NotNull Mindmap map, OutputStream outputStream) throws ExportException { + throw new UnsupportedOperationException(); + } + + @NotNull + public static Exporter createTextExporter() { + return create(Type.TEXT); + } + + @NotNull + public static Exporter create(@NotNull Type type) { + return new XSLTExporter(type); + } + + public static enum Type { + TEXT("mm2text.xsl"), + WORD("mm2wordml_utf8.xsl"), + CSV("mm2csv.xsl"), + LATEX("mm2latex.xsl"), + MICROSOFT_EXCEL("mm2xls_utf8.xsl"), + OPEN_OFFICE("mm2oowriter.xsl"); + + public String getXsltName() { + return xsltName; + } + + private String xsltName; + + Type(@NotNull String xstFile) { + this.xsltName = xstFile; + } + } + + +} + diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index b0e60a07..976c860b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -88,6 +88,38 @@ public class MindmapController extends BaseController { return new ModelAndView("transformViewFreemind", values); } + + @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"text/plain"}, params = {"download=txt"}) + @ResponseBody + public ModelAndView retrieveDocumentAsText(@PathVariable int id) throws IOException { + final Mindmap mindMap = mindmapService.findMindmapById(id); + final Map values = new HashMap(); + values.put("content", mindMap.getXmlStr()); + values.put("filename", mindMap.getTitle()); + return new ModelAndView("transformViewTxt", values); + } + + @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.ms-excel"}, params = {"download=xls"}) + @ResponseBody + public ModelAndView retrieveDocumentAsExcel(@PathVariable int id) throws IOException { + final Mindmap mindMap = mindmapService.findMindmapById(id); + final Map values = new HashMap(); + values.put("content", mindMap.getXmlStr()); + values.put("filename", mindMap.getTitle()); + return new ModelAndView("transformViewXls", values); + } + + @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.oasis.opendocument.text"}, params = {"download=odt"}) + @ResponseBody + public ModelAndView retrieveDocumentAsOdt(@PathVariable int id) throws IOException { + final Mindmap mindMap = mindmapService.findMindmapById(id); + final Map values = new HashMap(); + values.put("content", mindMap.getXmlStr()); + values.put("filename", mindMap.getTitle()); + return new ModelAndView("transformViewOdt", values); + } + + @RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json", "text/html", "application/xml"}) public ModelAndView retrieveList(@RequestParam(required = false) String q) throws IOException { final User user = Utils.getUser(); 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 f83a866c..79497e18 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 @@ -86,6 +86,9 @@ public class TransformView extends AbstractView { final Object mindmap = viewMap.get("mindmap"); final StreamResult result = new StreamResult(outputStream); jaxbMarshaller.marshal(mindmap, result); + } else if (exportFormat == ExportFormat.MICROSOFT_EXCEL || exportFormat == ExportFormat.TEXT || exportFormat == ExportFormat.OPEN_OFFICE_WRITER) { + response.setCharacterEncoding("UTF-8"); + factory.export(properties, content, outputStream, null); } else { factory.export(properties, null, outputStream, content); } diff --git a/wise-webapp/src/main/resources/com/wisemapping/export/xslt/LICENSE.MIT b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/LICENSE.MIT new file mode 100644 index 00000000..9e231e60 --- /dev/null +++ b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/LICENSE.MIT @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/wise-webapp/src/main/resources/com/wisemapping/export/xslt/hide.png b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/hide.png new file mode 100644 index 00000000..067acdb8 Binary files /dev/null and b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/hide.png differ diff --git a/wise-webapp/src/main/resources/com/wisemapping/export/xslt/ilink.png b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/ilink.png new file mode 100644 index 00000000..3e7f928d Binary files /dev/null and b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/ilink.png differ diff --git a/wise-webapp/src/main/resources/com/wisemapping/export/xslt/leaf.png b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/leaf.png new file mode 100644 index 00000000..a864906f Binary files /dev/null and b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/leaf.png differ diff --git a/wise-webapp/src/main/resources/com/wisemapping/export/xslt/marktree.js b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/marktree.js new file mode 100644 index 00000000..60fcf266 --- /dev/null +++ b/wise-webapp/src/main/resources/com/wisemapping/export/xslt/marktree.js @@ -0,0 +1,473 @@ +/* MarkTree JavaScript code + * + * Distributed under the terms of the MIT License. + * See "LICENCE.MIT" or http://www.opensource.org/licenses/mit-license.php for details. + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Miika Nurminen, 12.7.2004. + */ + +/* cross-browser (tested with ie5, mozilla 1 and opera 5) keypress detection */ +function get_keycode(evt) { + // IE + code = document.layers ? evt.which + : document.all ? event.keyCode // event.keyCode!=evt.keyCode! + : evt.keyCode; + + if (code==0) + code=evt.which; // for NS + return code; +} + +var lastnode=null; +var listnodes = null; +var list_index=1; +var lastnodetype=''; // determines if node is a link, input or text; + +// up, left, down, right, keypress codes +//ijkl +//var keys = new Array(105,106,107,108); +//num arrows +//var keys = new Array(56,52,50,54); +//wasd +// var press2 = new Array(119,97,115,100); + var press = new Array(47,45,42,43); + +// keydown codes + // var keys2=new Array(87,65,83,68); + var keys= new Array(38,37,40,39); + + // keyset 1 = keydown, otherwise press +function checkup(keyset,n) { + if (keyset==1) return (n==keys[0]); + return ((n==press[0]) /*|| (n==press2[0])*/) +} + +function checkdn(keyset,n) { + if (keyset==1) return (n==keys[2]); + return ((n==press[2]) /*|| (n==press2[2])*/) +} + +function checkl(keyset,n) { + if (keyset==1) return (n==keys[1]); + return ((n==press[1]) /*|| (n==press2[1])*/) +} + +function checkr(keyset,n) { + if (keyset==1) return (n==keys[3]); + return ((n==press[3]) /*|| (n==press2[3])*/) +} + + + + + +function is_exp(n) { + if (n==null) return false; + return ((n.className=='exp') || (n.className=='exp_active')); +} + +function is_col(n) { + if (n==null) return false; + return ((n.className=='col') || (n.className=='col_active')); +} + +function is_basic(n) { + if (n==null) return false; + return ((n.className=='basic') || (n.className=='basic_active')); +} + + + +/* returns i>=0 if true */ +function is_active(node) { + if (node.className==null) return false + return node.className.indexOf('_active'); +} + +function toggle_class(node) { + if ((node==null) || (node.className==null)) return; + str=node.className; + result=""; + i = str.indexOf('_active'); + if (i>0) + result= str.substr(0,i); + else + result= str+"_active"; + node.className=result; + return node; +} + +function activate(node) { + node.style.backgroundColor='#eeeeff'; +} + +function deactivate(node) { + node.style.backgroundColor='#ffffff'; +} + +function is_list_node(n) { + if (n==null) return false; + if (n.className==null) return false; + if ( (is_exp(n)) || + (is_col(n)) || + (is_basic(n)) ) + return true; else return false; +} + + +function get_href(n) { + alist=n.attributes; + if (alist!=null) { + hr = alist.getNamedItem('href'); + if (hr!=null) return hr.nodeValue; + } + if (n.childNodes.length==0) return ''; + for (var i=0; i=0) + toggle_class(lastnode); + lastnode=n; + if (!(is_active(lastnode)>=0)) + toggle_class(lastnode); + + +/*var d2 = new Date(); +var t_mil2 = d2.getMilliseconds(); + window.alert(t_mil2-t_mil);*/ +} + +function next_list_node() { + tempIndex = list_index; + while (tempIndex0) { + tempIndex--; + var x = listnodes[tempIndex]; + if (is_list_node(x)) { + list_index=tempIndex; + return; + } + } +} + + + +function getsub (li) { + if (li.childNodes.length==0) return null; + for (var c = 0; c < li.childNodes.length; c++) + if ( (li.childNodes[c].className == 'sub') || (li.childNodes[c].className == 'subexp') ) + return li.childNodes[c]; +} + +function find_listnode_recursive (li) { + if (is_list_node(li)) return li; + if (li.childNodes.length==0) return null; + result=null; + for (var c = 0; c < li.childNodes.length; c++) { + result=find_listnode_recursive(li.childNodes[c]); + if (result!=null) return result; + } + return null; +} + +function next_child_listnode(li) { + var result=null; + for (var i=0; i