static char[] getPassword(Element ePassword) { return Util.base64decode(ePassword.getValue()).toCharArray(); } }
private void addFields(Elements eFields, ReqEntityBasePart part) { if(eFields == null) { return; } for(int i=0; i<eFields.size(); i++) { Element eField = eFields.get(i); String name = eField.getChildElements("name").get(0).getValue(); String value = eField.getChildElements("value").get(0).getValue(); part.addField(name, value); } }
static void populateBasicDigestAuth(BasicDigestAuthBaseBean bean, Element eAuth) { Elements eChildren = eAuth.getChildElements(); for(int i=0; i<eChildren.size(); i++) { Element e = eChildren.get(i); final String name = e.getLocalName(); if(name.equals("host")) { bean.setHost(e.getValue()); } else if(name.equals("realm")) { bean.setRealm(e.getValue()); } else if(name.equals("username")) { bean.setUsername(e.getValue()); } else if(name.equals("password")) { bean.setPassword(getPassword(e)); } else if(name.equals("preemptive")) { bean.setPreemptive(true); } else { throw new XMLException("Unknown element in basic/digest auth: " + name); } } }
static NtlmAuth getNtlmAuth(Element eNtlmAuth) { NtlmAuthBean out = new NtlmAuthBean(); Elements eChildren = eNtlmAuth.getChildElements(); for(int i=0; i<eChildren.size(); i++) { Element e = eChildren.get(i); final String name = e.getLocalName(); if(name.equals("domain")) { out.setDomain(e.getValue()); } else if(name.equals("workstation")) { out.setWorkstation(e.getValue()); } else if(name.equals("username")) { out.setUsername(e.getValue()); } else if(name.equals("password")) { out.setPassword(getPassword(e)); } else { throw new XMLException("Unknown element in ntlm auth: " + name); } } return out; }
if("string".equals(name)) { ContentType ct = getContentType(e); String body = e.getValue(); return new ReqEntityStringBean(body, ct); String filePath = e.getValue(); return new ReqEntityFileBean(new File(filePath), ct); byte[] body = Util.base64decodeByteArray(e.getValue()); return new ReqEntityByteArrayBean(body, ct); try { ContentType ct = getContentType(e); URL url = new URL(e.getValue()); return new ReqEntityUrlStreamBean(ct, url);
static OAuth2BearerAuth getOAuth2BearerAuth(Element eAuth) { OAuth2BearerAuthBean out = new OAuth2BearerAuthBean(); Elements eChildren = eAuth.getChildElements(); for(int i=0; i<eChildren.size(); i++) { Element e = eChildren.get(i); final String name = e.getLocalName(); if(name.equals("token")) { out.setOAuth2BearerToken(e.getValue()); } else { throw new XMLException("Unknown element in oauth2-bearer auth: " + name); } } return out; }
String nodeName = tNode.getQualifiedName(); if ("http-version".equals(nodeName)) { String t = tNode.getValue(); HTTPVersion httpVersion = "1.1".equals(t)? HTTPVersion.HTTP_1_1 : HTTPVersion.HTTP_1_0; URL url = new URL(tNode.getValue()); requestBean.setUrl(url); requestBean.setMethod(HTTPMethod.get(tNode.getValue())); requestBean.setTestScript(tNode.getValue());
responseBean.setExecutionTime(Long.parseLong(tNode.getValue())); } else if ("status".equals(nodeName)) { responseBean.setStatusLine(tNode.getValue()); responseBean.setStatusCode(Integer.parseInt(tNode.getAttributeValue("code"))); } else if ("headers".equals(nodeName)) { final String base64body = tNode.getValue(); responseBean.setResponseBody(Util.base64decodeByteArray(base64body)); } else if ("test-result".equals(nodeName)) {
break; case "hostname-verifier": out.setHostNameVerifier(SSLHostnameVerifier.valueOf(e.getValue())); break; case "keystore":
/** * @return the value of the elemnt, will return null if its an empty string. */ private static String getValue(Element value) { String v = value.getValue(); if (v != null && v.length() == 0) { return null; } return v; }
public static boolean parseBooleanElementValue(final String elementName, final Element sourceElement) { try { return Boolean.parseBoolean(XMLProcessor.parseOneChildElement(elementName, sourceElement).getValue()); } catch (MissingElementException | OverissueElementException ex) { return false; } }
private static List<Object> getExceptionsFromElement(Element root) { Elements exceptions = root.getChildElements("path-exception"); ArrayList<Object> exceptionList = new ArrayList<Object>(); for(int i=0;i<exceptions.size();i++) { Element e = exceptions.get(i); if ( REGEX.equalsIgnoreCase(e.getAttributeValue("type"))) { exceptionList.add( Pattern.compile(e.getValue()) ); } else { exceptionList.add( e.getValue() ); } } return exceptionList; }
private String getValue(Elements elements) { if(elements.size() == 1) { return elements.get(0).getValue(); } else { throw new RuntimeException("Invalid XML"); } }
private static SDocumentTitle documentTitleRoot( final Element root) { final Element e = SDocumentParser.getElement(root, "document-title"); assert e != null; return SDocumentTitle.documentTitle(e.getValue()); }
private static SFormalItemTitle formalItemTitleRoot( final Element e) { final Element ec = SDocumentParser.getElement(e, "formal-item-title"); assert ec != null; return SFormalItemTitle.formalItemTitle(ec.getValue()); }
private static SSectionTitle sectionTitleRoot( final Element root) { final Element e = SDocumentParser.getElement(root, "section-title"); assert e != null; return SSectionTitle.sectionTitle(e.getValue()); }
private static @Nullable SDocumentStyle documentStyleRoot( final Element root) throws URISyntaxException { final Element e = SDocumentParser.getElement(root, "document-style"); if (e == null) { return null; } return SDocumentStyle.documentStyle(new URI(e.getValue())); }
private static double getWeight(Element element, String source) { Elements weights = element.getChildElements("mass"); for (int i = 0; i < weights.size(); i++) { Element weight = (Element) weights.get(i); if (source != null && source.equals(weight.getAttributeValue("source"))) { return Double.parseDouble(weight.getValue()); } } return 0; }