protected int getChildCount() { return currentElement.getChildElements().size(); }
private List<ReqEntityPart> getMultipartParts(Element e) { List<ReqEntityPart> parts = new ArrayList<>(); Elements children = e.getChildElements(); for(int i=0; i<children.size(); i++) { ReqEntityPart part = getMultipartPart(children.get(i)); parts.add(part); } return parts; }
private Map<String, String> getHeadersFromHeaderNode(final Element node) throws XMLException { Map<String, String> m = new LinkedHashMap<>(); for (int i = 0; i < node.getChildElements().size(); i++) { Element headerElement = node.getChildElements().get(i); if (!"header".equals(headerElement.getQualifiedName())) { throw new XMLException("<headers> element should contain only <header> elements"); } m.put(headerElement.getAttributeValue("key"), headerElement.getAttributeValue("value")); } return m; }
public String peekNextChild() { Elements children = currentElement.getChildElements(); if (null == children || children.size() == 0) { return null; } return decodeNode(children.get(0).getLocalName()); } }
static Auth getAuth(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("basic")) { return getBasicAuth(e); } else if(name.equals("digest")) { return getDigestAuth(e); } else if(name.equals("ntlm")) { return getNtlmAuth(e); } else if(name.equals("oauth2-bearer")) { return getOAuth2BearerAuth(e); } else { throw new XMLException("Invalid auth element encountered: " + name); } } return null; }
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; }
List<CoreMap> sentences = new ArrayList<>(); Elements sentenceElements = textElem.getChildElements("SENT"); for (int crtsent = 0; crtsent < sentenceElements.size(); crtsent ++){ Element sentElem = sentenceElements.get(crtsent); CoreMap sentence = new ArrayCoreMap();
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); } } }
private List<HttpCookie> getCookiesFromCookiesNode(final Element node) throws XMLException { List<HttpCookie> out = new ArrayList<>(); for (int i = 0; i < node.getChildElements().size(); i++) { Element e = node.getChildElements().get(i); if(!"cookie".equals(e.getQualifiedName())) { throw new XMLException("<cookies> element should contain only <cookie> elements"); } HttpCookie cookie = new HttpCookie(e.getAttributeValue("name"), e.getAttributeValue("value")); final String cookieVerStr = e.getAttributeValue("version"); if(StringUtil.isNotEmpty(cookieVerStr)) { cookie.setVersion(Integer.parseInt(cookieVerStr)); } else { cookie.setVersion(CookieVersion.DEFAULT_VERSION.getIntValue()); } out.add(cookie); } return out; }
ReqEntity getReqEntity(Element eEntity) { Elements eChildren = eEntity.getChildElements(); for(int i=0; i<eChildren.size(); i++) { Element e = eChildren.get(i); final String name = e.getLocalName();
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(e.getChildElements("fields").size() > 0) { eFields = e.getChildElements("fields").get(0).getChildElements("field");
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); } }
RequestBean requestBean = new RequestBean(); for (int i = 0; i < requestNode.getChildElements().size(); i++) { Element tNode = requestNode.getChildElements().get(i); String nodeName = tNode.getQualifiedName();
public static List<Request> getRequestCollectionFromXMLFile(final File f) throws IOException, XMLException { XmlPersistenceRead xUtlRead = new XmlPersistenceRead(); List<Request> out = new ArrayList<>(); Document doc = xUtlRead.getDocumentFromFile(f); Element eRoot = doc.getRootElement(); if(!"request-collection".equals(eRoot.getLocalName())) { throw new XMLException("Expecting root element <request-collection>, but found: " + eRoot.getLocalName()); } final String version = eRoot.getAttributeValue("version"); try { Versions.versionValidCheck(version); } catch(Versions.VersionValidationException ex) { throw new XMLException(ex); } xUtlRead.setReadVersion(version); Elements eRequests = doc.getRootElement().getChildElements(); for(int i=0; i<eRequests.size(); i++) { Element eRequest = eRequests.get(i); Request req = xUtlRead.getRequestBean(eRequest); out.add(req); } return out; }
protected Request xml2Request(final Document doc) throws MalformedURLException, XMLException { // get the rootNode Element rootNode = doc.getRootElement(); if (!"rest-client".equals(rootNode.getQualifiedName())) { throw new XMLException("Root node is not <rest-client>"); } // checking correct rest version final String rcVersion = rootNode.getAttributeValue("version"); try { Versions.versionValidCheck(rcVersion); } catch(Versions.VersionValidationException ex) { throw new XMLException(ex); } readVersion = rcVersion; // if more than two request element is present then throw the exception if (rootNode.getChildElements().size() != 1) { throw new XMLException("There can be only one child node for root node: <request>"); } // minimum one request element is present in xml if (rootNode.getFirstChildElement("request") == null) { throw new XMLException("The child node of <rest-client> should be <request>"); } Element requestNode = rootNode.getFirstChildElement("request"); return getRequestBean(requestNode); }
for(int i=0; i<eChildren.size(); i++) { Element e = eChildren.get(i); final String name = e.getLocalName();
private List<CMLLength> makeLengthList(CMLElement element) { Elements lengthElements = element.getChildCMLElements(CMLLength.TAG); List<CMLLength> lengthList = new ArrayList<CMLLength>(); for (int i = 0; i < lengthElements.size(); i++) { lengthList.add((CMLLength)lengthElements.get(i)); } if (lengthList.size() == 0) { throw new RuntimeException("no length elements in ZMatrix"); } return lengthList; }
@Override public String peekNextChild() { final Elements children = currentElement.getChildElements(); if (null == children || children.size() == 0) { return null; } return decodeNode(children.get(0).getLocalName()); } }