From c42e3d7000982f249f5e1e85a5f379b5ed0e49b6 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 27 Aug 2014 12:17:19 +0200 Subject: Fixed empty Query String bug --- .../pdfas/web/helper/UrlParameterExtractor.java | 44 ++++++++++++---------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'pdf-as-web/src') diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java index 4c793524..64043cac 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java @@ -11,36 +11,42 @@ import java.util.Map.Entry; public class UrlParameterExtractor { - - public static Map splitQuery(URL url) throws UnsupportedEncodingException { - Map query_pairs = new LinkedHashMap(); - String query = url.getQuery(); - String[] pairs = query.split("&"); - for (String pair : pairs) { - int idx = pair.indexOf("="); - query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); - } - return query_pairs; + public static Map splitQuery(URL url) + throws UnsupportedEncodingException { + Map query_pairs = new LinkedHashMap(); + String query = url.getQuery(); + if (query != null) { + String[] pairs = query.split("&"); + for (String pair : pairs) { + int idx = pair.indexOf("="); + query_pairs.put( + URLDecoder.decode(pair.substring(0, idx), "UTF-8"), + URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); + } + } + return query_pairs; } - + public static String buildParameterFormString(URL url) throws IOException { Map query_pairs = splitQuery(url); - Iterator> entryIt = query_pairs.entrySet().iterator(); - - if(query_pairs.isEmpty()) { + Iterator> entryIt = query_pairs.entrySet() + .iterator(); + + if (query_pairs.isEmpty()) { return ""; } String genericTemplate = PdfAsHelper.getGenericTemplate(); StringBuilder sb = new StringBuilder(); - while(entryIt.hasNext()) { + while (entryIt.hasNext()) { Entry entry = entryIt.next(); - - String current = genericTemplate.replace("##NAME##", entry.getKey()); + + String current = genericTemplate + .replace("##NAME##", entry.getKey()); current = current.replace("##VALUE##", entry.getValue()); sb.append(current); } - + return sb.toString(); } - + } -- cgit v1.2.3