Java Code Examples for nu.xom.Elements#size()

The following examples show how to use nu.xom.Elements#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlAuthUtil.java    From rest-client with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: XmlAuthUtil.java    From rest-client with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: XmlAuthUtil.java    From rest-client with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 4
Source File: XmlAuthUtil.java    From rest-client with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: XomReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String peekNextChild() {
    Elements children = currentElement.getChildElements();
    if (null == children || children.size() == 0) {
        return null;
    }
    return decodeNode(children.get(0).getLocalName());
}
 
Example 6
Source File: XMLCollectionUtil.java    From rest-client with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: XmlBodyRead.java    From rest-client with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: XmlBodyRead.java    From rest-client with Apache License 2.0 5 votes vote down vote up
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);
    }
}