diff --git a/mindplot/src/main/javascript/DesignerKeyboard.js b/mindplot/src/main/javascript/DesignerKeyboard.js index aaba0d04..e0b12a3f 100644 --- a/mindplot/src/main/javascript/DesignerKeyboard.js +++ b/mindplot/src/main/javascript/DesignerKeyboard.js @@ -50,7 +50,9 @@ mindplot.DesignerKeyboard = new Class({ } ); this.addShortcut( - ['f2'],function() { + ['f2'],function(event) { + event.stopPropagation(); + event.preventDefault(); var node = model.selectedTopic(); if (node) { node.showTextEditor(); @@ -254,13 +256,23 @@ mindplot.DesignerKeyboard = new Class({ event.stopPropagation(); } ); - + var excludes = ['esc', 'f1', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12']; + $(document).on('keypress', function (event) { - - var keyCode = event.keyCode; + var keyCode; + // Firefox doesn't skip special keys for keypress event... + if (event.key && excludes.contains(event.key.toLowerCase())) { + return; + } + // Sometimes Firefox doesn't contain keyCode value + if (event.key && event.keyCode == 0) { + keyCode = event.charCode; + } else { + keyCode = event.keyCode; + } var specialKey = jQuery.hotkeys.specialKeys[keyCode]; - if (["enter", "capslock"].indexOf(specialKey) == -1 && !jQuery.hotkeys.shiftNums[keyCode] && keyCode != 91 /*win key*/) { + if (["enter", "capslock"].indexOf(specialKey) == -1 && !jQuery.hotkeys.shiftNums[keyCode]) { var nodes = designer.getModel().filterSelectedTopics(); if (nodes.length > 0) { @@ -377,3 +389,14 @@ mindplot.DesignerKeyboard = new Class({ } }); + +mindplot.DesignerKeyboard.specialKeys = { + 8: "backspace", 9: "tab", 10: "return", 13: "enter", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause", + 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", + 37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", + 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7", + 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", + 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", + 120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 186: ";", 191: "/", + 220: "\\", 222: "'", 224: "meta" +}; \ No newline at end of file diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/ExportProperties.java b/wise-webapp/src/main/java/com/wisemapping/exporter/ExportProperties.java index 18e1354a..ce95b955 100644 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/ExportProperties.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/ExportProperties.java @@ -20,7 +20,6 @@ package com.wisemapping.exporter; public class ExportProperties { private ExportFormat format; - private String baseImgPath; private String version; public ExportFormat getFormat() { 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 716dc2bf..3f6921f2 100644 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java @@ -54,7 +54,7 @@ import java.util.regex.Pattern; public class ExporterFactory { private static final String GROUP_NODE_NAME = "g"; private static final String IMAGE_NODE_NAME = "image"; - public static final int MARGING = 50; + public static final int MANGING = 50; public static final String UTF_8_CHARSET_NAME = "UTF-8"; private File baseImgDir; @@ -79,7 +79,7 @@ public class ExporterFactory { transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth()); // Create the transcoder input. - final String svgString = normalizeSvg(mapSvg, false); + final String svgString = normalizeSvg(mapSvg); final TranscoderInput input = new TranscoderInput(new CharArrayReader(svgString.toCharArray())); TranscoderOutput trascoderOutput = new TranscoderOutput(output); @@ -99,7 +99,7 @@ public class ExporterFactory { transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth()); // Create the transcoder input. - final String svgString = normalizeSvg(mapSvg, false); + final String svgString = normalizeSvg(mapSvg); final TranscoderInput input = new TranscoderInput(new CharArrayReader(svgString.toCharArray())); TranscoderOutput trascoderOutput = new TranscoderOutput(output); @@ -113,7 +113,7 @@ public class ExporterFactory { final Transcoder transcoder = new PDFTranscoder(); // Create the transcoder input. - final String svgString = normalizeSvg(mapSvg, false); + final String svgString = normalizeSvg(mapSvg); final TranscoderInput input = new TranscoderInput(new CharArrayReader(svgString.toCharArray())); TranscoderOutput trascoderOutput = new TranscoderOutput(output); @@ -122,22 +122,22 @@ public class ExporterFactory { break; } case SVG: { - final String svgString = normalizeSvg(mapSvg, true); + final String svgString = normalizeSvg(mapSvg); output.write(svgString.getBytes(UTF_8_CHARSET_NAME)); break; } case TEXT: { - final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.TEXT); + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.TEXT); exporter.export(xml.getBytes(UTF_8_CHARSET_NAME), output); break; } case OPEN_OFFICE_WRITER: { - final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.OPEN_OFFICE); + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.OPEN_OFFICE); exporter.export(xml.getBytes(UTF_8_CHARSET_NAME), output); break; } case MICROSOFT_EXCEL: { - final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.MICROSOFT_EXCEL); + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.MICROSOFT_EXCEL); exporter.export(xml.getBytes(UTF_8_CHARSET_NAME), output); break; } @@ -148,7 +148,7 @@ public class ExporterFactory { break; } case MINDJET: { - final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.MINDJET); + final Exporter exporter = XSLTExporter.create(XSLTExporter.Type.MINDJET); exporter.export(xml.getBytes(UTF_8_CHARSET_NAME), output); break; } @@ -157,7 +157,7 @@ public class ExporterFactory { } } - private String normalizeSvg(@NotNull String svgXml, boolean embedImg) throws ExportException { + private String normalizeSvg(@NotNull String svgXml) throws ExportException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -195,13 +195,7 @@ public class ExporterFactory { inlineImages(document, (Element) child); return domToString(document); - } catch (ParserConfigurationException e) { - throw new ExportException(e); - } catch (IOException e) { - throw new ExportException(e); - } catch (SAXException e) { - throw new ExportException(e); - } catch (TransformerException e) { + } catch (ParserConfigurationException | TransformerException | SAXException | IOException e) { throw new ExportException(e); } @@ -243,27 +237,22 @@ public class ExporterFactory { Element elem = (Element) node; - // If the image is a external URL, embeed it... - String imgUrl = elem.getAttribute("href"); - if (!imgUrl.startsWith("image/png;base64") ||!imgUrl.startsWith("data:image/png;base64") ) { + final String imgUrl = fixHref(elem); + if (!imgUrl.isEmpty() && (!imgUrl.startsWith("image/png;base64") || !imgUrl.startsWith("data:image/png;base64"))) { elem.removeAttribute("href"); - if (imgUrl == null || imgUrl.isEmpty()) { - imgUrl = elem.getAttribute("xlink:href"); // Do not support namespaces ... - elem.removeAttribute("xlink:href"); - } - FileInputStream fis = null; - + InputStream fis = null; // Obtains file name ... try { final File iconFile = iconFile(imgUrl); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); fis = new FileInputStream(iconFile); BASE64Encoder encoder = new BASE64Encoder(); encoder.encode(fis, bos); elem.setAttribute("xlink:href", "data:image/png;base64," + bos.toString("8859_1")); elem.appendChild(document.createTextNode(" ")); + } catch (IOException e) { e.printStackTrace(); } finally { @@ -274,28 +263,55 @@ public class ExporterFactory { } } + @NotNull + private String fixHref(@NotNull Element elem) { + // Fix href attribute ... + // Hack for IE: If the image is a external URL, embeed it... + String result = elem.getAttribute("href"); + if (result.isEmpty()) { + + + // Bug WISE-422: This seems to be a bug in Safari. For some reason, img add prefixed with NS1 + // { protected String version_d; @@ -58,13 +60,13 @@ public class VersionNumber } - public int compareTo(final Object otherObject) { + public int compareTo(@NotNull final VersionNumber otherObject) { if (this.equals(otherObject)) { return 0; } final StringTokenizer ownTokenizer = this.getTokenizer(); - final StringTokenizer otherTokenizer = ((VersionNumber) otherObject).getTokenizer(); + final StringTokenizer otherTokenizer = otherObject.getTokenizer(); while (ownTokenizer.hasMoreTokens()) { final int ownNumber; @@ -112,8 +114,8 @@ public class VersionNumber return (version_d != null ? version_d.hashCode() : 0); } - - protected StringTokenizer getTokenizer() { + @NotNull + private StringTokenizer getTokenizer() { return new StringTokenizer(this.getVersion(), "."); } } diff --git a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java index 52af8997..93a318e3 100755 --- a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java @@ -96,8 +96,9 @@ public class FreemindImporter final Map freemindMap = (Map) JAXBUtils.getMapObject(input, "com.wisemapping.jaxb.freemind"); final String version = freemindMap.getVersion(); - if (version != null) { - + if (version == null || version.startsWith("freeplane")) { + throw new ImporterException("You seems to be be trying to import a Freeplane map. FreePlane is not supported format."); + } else { final VersionNumber mapVersion = new VersionNumber(version); if (mapVersion.isGreaterThan(FreemindConstant.SUPPORTED_FREEMIND_VERSION)) { throw new ImporterException("FreeMind version " + mapVersion.getVersion() + " is not supported."); @@ -134,11 +135,7 @@ public class FreemindImporter result.setTitle(mapName); result.setDescription(description); - } catch (JAXBException e) { - throw new ImporterException(e); - } catch (IOException e) { - throw new ImporterException(e); - } catch (TransformerException e) { + } catch (JAXBException | IOException | TransformerException e) { throw new ImporterException(e); } return result; @@ -330,7 +327,7 @@ public class FreemindImporter } } - private int getChildrenCountSameSide(@NotNull List freeChildren, Node freeChild) { + private int getChildrenCountSameSide(@NotNull List freeChildren, Node freeChild) { int result = 0; String childSide = freeChild.getPOSITION(); if (childSide == null) { @@ -500,11 +497,7 @@ public class FreemindImporter } final Boolean folded = Boolean.valueOf(freeNode.getFOLDED()); - if (folded) { - wiseTopic.setShrink(folded); - } - - + wiseTopic.setShrink(folded); } 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 4c754537..3b2766bc 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 @@ -23,6 +23,7 @@ import com.wisemapping.exporter.ExportProperties; import com.wisemapping.exporter.ExporterFactory; import com.wisemapping.mail.NotificationService; import com.wisemapping.security.Utils; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.oxm.jaxb.Jaxb2Marshaller; @@ -38,6 +39,8 @@ import java.util.Map; public class TransformView extends AbstractView { + @NonNls + private static final String DEFAULT_ENCODING = "UTF-8"; private String contentType; private ExportFormat exportFormat; private NotificationService notificationService; @@ -74,7 +77,7 @@ public class TransformView extends AbstractView { // Set file name...:http://stackoverflow.com/questions/5325322/java-servlet-download-filename-special-characters/13359949#13359949 final String fileName = (filename != null ? filename : "map") + "." + exportFormat.getFileExtension(); - setContentDisposition(request, response, fileName); + this.setContentDisposition(request, response, fileName); // Change image link URL. final ServletContext servletContext = request.getSession().getServletContext(); @@ -86,14 +89,15 @@ public class TransformView extends AbstractView { response.setCharacterEncoding("ASCII"); factory.export(properties, content, outputStream, null); } else if (exportFormat == ExportFormat.WISEMAPPING) { - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(DEFAULT_ENCODING); 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 || exportFormat == ExportFormat.MINDJET) { - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(DEFAULT_ENCODING); factory.export(properties, content, outputStream, null); } else { + // Image export ... factory.export(properties, null, outputStream, content); } } catch (Throwable e) { diff --git a/wise-webapp/src/main/webapp/jsp/mindmapExport.jsp b/wise-webapp/src/main/webapp/jsp/mindmapExport.jsp index 17f1159e..4cd6d5cb 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapExport.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapExport.jsp @@ -11,6 +11,7 @@ +