diff options
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java | 44 |
1 files changed, 25 insertions, 19 deletions
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<String, String> splitQuery(URL url) throws UnsupportedEncodingException { - Map<String, String> query_pairs = new LinkedHashMap<String, String>(); - 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<String, String> splitQuery(URL url) + throws UnsupportedEncodingException { + Map<String, String> query_pairs = new LinkedHashMap<String, String>(); + 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<String, String> query_pairs = splitQuery(url); - Iterator<Entry<String, String>> entryIt = query_pairs.entrySet().iterator(); - - if(query_pairs.isEmpty()) { + Iterator<Entry<String, String>> 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<String, String> 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(); } - + } |