From 0f031d36c2e6292b2ba77ca6903659ac0e9fc378 Mon Sep 17 00:00:00 2001 From: Andreas Abraham Date: Wed, 31 Jul 2019 13:24:36 +0200 Subject: pdf-over uses now jsoup to read dynamic values from html content --- .../pdfover/gui/bku/mobile/MobileBKUHelper.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java index 410ba3c1..04397f14 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java @@ -24,6 +24,11 @@ import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.protocol.Protocol; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.nodes.Node; +import org.jsoup.select.Elements; +import org.jsoup.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -148,6 +153,23 @@ public class MobileBKUHelper { } return found.substring(startidx + 1, endidx); } + + /** + * This method is the same as the non optional method but instead of throwing the exception it returns null + * @return the string or null + */ + public static String extractValueFromTagWithParamOptional(String data, String tag, + String param, String value, String returnparam) { + String str; + try { + str = extractValueFromTagWithParam(data, tag, param, value, returnparam); + } catch (Exception e) { + log.debug("Optional value is not available"); + str = null; + } + return str; + + } /** * Extracts the content from an XML tag from data with the given param="value" @@ -291,4 +313,21 @@ public class MobileBKUHelper { } return client; } + + /*** + * + * @param htmlString describes the html data in String representation + * @param attributeName is the attribute which should be selected + * @return returns the attribute name or null otherswise + */ + public static String getNameAttribute(String htmlString, String attributeName) { + + Document doc = Jsoup.parse(htmlString); + Elements inputs = doc.select("div input#" + attributeName); + + if (inputs.size() == 0 ) return null; + + String name = inputs.get(0).attr("name"); + return name; + } } -- cgit v1.2.3