diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-08-19 11:45:45 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-08-19 11:45:45 +0200 |
commit | 80686cc60dc0bccb7a42fddefefcf13dcabdd80a (patch) | |
tree | 98810b82688b0b4670351bdcfd0c3f145dd44c87 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper | |
parent | e1b810ee9221f6247c575c669bff2ba98552c65e (diff) | |
download | pdf-as-4-80686cc60dc0bccb7a42fddefefcf13dcabdd80a.tar.gz pdf-as-4-80686cc60dc0bccb7a42fddefefcf13dcabdd80a.tar.bz2 pdf-as-4-80686cc60dc0bccb7a42fddefefcf13dcabdd80a.zip |
Fixed #18, Get Parameters in external urls are not discarded
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java | 7 | ||||
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java | 46 |
2 files changed, 53 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index 83dd2610..9e3fb3fe 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -746,6 +746,13 @@ public class PdfAsHelper { return xml; } + public static String getGenericTemplate() throws IOException { + String xml = FileUtils.readFileToString(FileUtils + .toFile(PdfAsHelper.class + .getResource("/template_generic_param.html"))); + return xml; + } + public static String getInvokeRedirectTemplateSL() throws IOException { String xml = FileUtils.readFileToString(FileUtils .toFile(PdfAsHelper.class 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 new file mode 100644 index 00000000..4c793524 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/UrlParameterExtractor.java @@ -0,0 +1,46 @@ +package at.gv.egiz.pdfas.web.helper; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +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 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()) { + return ""; + } + String genericTemplate = PdfAsHelper.getGenericTemplate(); + StringBuilder sb = new StringBuilder(); + while(entryIt.hasNext()) { + Entry<String, String> entry = entryIt.next(); + + String current = genericTemplate.replace("##NAME##", entry.getKey()); + current = current.replace("##VALUE##", entry.getValue()); + sb.append(current); + } + + return sb.toString(); + } + +} |