From: Svjatoslav Agejenko Date: Wed, 5 Apr 2017 22:20:50 +0000 (+0300) Subject: Restored HTML indexer to semi-working state. X-Git-Tag: meviz-1.1~1 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=meviz.git;a=commitdiff_plain;h=3d29e476a202b7e6c05df21cf557ce909bddc076 Restored HTML indexer to semi-working state. --- diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/UrlParamEncoder.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/UrlParamEncoder.java new file mode 100755 index 0000000..15d9302 --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/UrlParamEncoder.java @@ -0,0 +1,55 @@ +/* + * Svjatoslav Commons - shared library of common functionality. + * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 3 of the GNU Lesser General Public License + * or later as published by the Free Software Foundation. + */ + +package eu.svjatoslav.meviz.htmlindexer; + +public class UrlParamEncoder { + + public static String decode(final String source) { + + final String result = source.replaceAll("%20", " "); + + return result; + } + + public static String encode(final String source) { + + final StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < source.length(); i++) { + boolean replaced = false; + final char character = source.charAt(i); + + if (character == ' ') { + buffer.append("%20"); + replaced = true; + } + + if (character == '?') { + buffer.append("%3F"); + replaced = true; + } + + if (character == ',') { + buffer.append("%2C"); + replaced = true; + } + + if (character == ':') { + buffer.append("%3A"); + replaced = true; + } + + if (!replaced) + buffer.append(character); + } + + return buffer.toString(); + } + +} diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java index 69c1c43..853b510 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java @@ -13,8 +13,10 @@ import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import java.io.*; -import java.net.URLEncoder; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.HashSet; import java.util.zip.CRC32; @@ -118,14 +120,23 @@ public class Utils { return isMevizFile; } + /** + * TODO: URL path component is encoded differently from URL query parameter. + * Also some URL encoding might work for HTML on local filesystem, while other + * stuff works for web. Things must be cleared up here. Currently they are mixed and + * hacked together. + */ public static String urlEncode(String string) { if (string.startsWith("./")) string = string.substring(2); - try { - return URLEncoder.encode(string, UTF_8).replace("+", "%20"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + // TODO: get rid of UrlParamEncoder. + return UrlParamEncoder.encode(string); + // +// try { +// return URLEncoder.encode(string, UTF_8).replace("+", "%20"); +// } catch (UnsupportedEncodingException e) { +// throw new RuntimeException(e); +// } } }