From af9672d0ac0c534708376c3e65ab3920a19d86d0 Mon Sep 17 00:00:00 2001 From: Stefan Posch Date: Sat, 17 Mar 2018 08:57:06 +0100 Subject: [PATCH] allow ampersand in image names, fixes #24 --- .../informatik/rhizoTrak/addon/RhizoMain.java | 18 ++++++++++++++++++ .../rhizoTrak/display/Displayable.java | 5 ++++- .../informatik/rhizoTrak/display/Patch.java | 6 +++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/unihalle/informatik/rhizoTrak/addon/RhizoMain.java b/src/main/java/de/unihalle/informatik/rhizoTrak/addon/RhizoMain.java index 3b9783bf5..c596ce735 100644 --- a/src/main/java/de/unihalle/informatik/rhizoTrak/addon/RhizoMain.java +++ b/src/main/java/de/unihalle/informatik/rhizoTrak/addon/RhizoMain.java @@ -75,4 +75,22 @@ public void disposeGUIs() rA.getConflictManager().disposeConflictFrame(); } + /** Code a string to conform to html convention + * @param rel_path + * @return + */ + public static String htmlCode( String s) { + StringBuilder out = new StringBuilder(Math.max(16, s.length())); + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') { + out.append("&#"); + out.append((int) c); + out.append(';'); + } else { + out.append(c); + } + } + return out.toString(); + } } diff --git a/src/main/java/de/unihalle/informatik/rhizoTrak/display/Displayable.java b/src/main/java/de/unihalle/informatik/rhizoTrak/display/Displayable.java index f33f96817..ced59946b 100644 --- a/src/main/java/de/unihalle/informatik/rhizoTrak/display/Displayable.java +++ b/src/main/java/de/unihalle/informatik/rhizoTrak/display/Displayable.java @@ -104,6 +104,7 @@ as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.tx import java.util.Set; import de.unihalle.informatik.rhizoTrak.Project; +import de.unihalle.informatik.rhizoTrak.addon.RhizoMain; import de.unihalle.informatik.rhizoTrak.display.graphics.AddARGBComposite; import de.unihalle.informatik.rhizoTrak.display.graphics.ColorYCbCrComposite; import de.unihalle.informatik.rhizoTrak.display.graphics.DifferenceARGBComposite; @@ -1410,7 +1411,9 @@ public void exportXML(final StringBuilder sb_body, final String in, final XMLOpt if (!visible) sb_body.append(in).append("visible=\"false\"\n"); // 'style' is taken care in subclasses if (null != title && title.length() > 0) { - sb_body.append(in).append("title=\"").append(title.replaceAll("\"", "^#^")).append("\"\n"); // fix possible harm by '"' characters (backslash should be taken care of as well TODO) + // code string for html + sb_body.append(in).append("title=\"").append( RhizoMain.htmlCode( title.replaceAll("\"", "^#^"))).append("\"\n"); // fix possible harm by '"' characters (backslash should be taken care of as well TODO) +// sb_body.append(in).append("title=\"").append(title.replaceAll("\"", "^#^")).append("\"\n"); // fix possible harm by '"' characters (backslash should be taken care of as well TODO) } if (COMPOSITE_NORMAL != compositeMode) { diff --git a/src/main/java/de/unihalle/informatik/rhizoTrak/display/Patch.java b/src/main/java/de/unihalle/informatik/rhizoTrak/display/Patch.java index ca939d631..492572c36 100644 --- a/src/main/java/de/unihalle/informatik/rhizoTrak/display/Patch.java +++ b/src/main/java/de/unihalle/informatik/rhizoTrak/display/Patch.java @@ -115,6 +115,7 @@ as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.tx import java.util.zip.ZipOutputStream; import de.unihalle.informatik.rhizoTrak.Project; +import de.unihalle.informatik.rhizoTrak.addon.RhizoMain; import de.unihalle.informatik.rhizoTrak.imaging.PatchStack; import de.unihalle.informatik.rhizoTrak.imaging.filters.FilterEditor; import de.unihalle.informatik.rhizoTrak.imaging.filters.IFilter; @@ -928,8 +929,11 @@ public void exportXML(final StringBuilder sb_body, final String indent, final XM if (null != imp) type = imp.getType(); } + + // code file path for html sb_body.append(in).append("type=\"").append(type /*null == any ? ImagePlus.GRAY8 : type*/).append("\"\n") - .append(in).append("file_path=\"").append(rel_path).append("\"\n") + .append(in).append("file_path=\"").append( RhizoMain.htmlCode( rel_path)).append("\"\n") +// .append(in).append("file_path=\"").append(rel_path).append("\"\n") .append(in).append("style=\"fill-opacity:").append(alpha).append(";stroke:#").append(RGB[0]).append(RGB[1]).append(RGB[2]).append(";\"\n") .append(in).append("o_width=\"").append(o_width).append("\"\n") .append(in).append("o_height=\"").append(o_height).append("\"\n")