nu.xom.Elements Java Examples
The following examples show how to use
nu.xom.Elements.
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 |
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 |
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 |
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 |
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: ReplaceEmbeddedStylesheetExtension.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void addTo(ConcordionExtender concordionExtender) { if (styleToReplace != null) { concordionExtender.withLinkedCSS(styleToReplace, new Resource("/concordion.css")); } concordionExtender.withDocumentParsingListener(document -> { Element html = document.getRootElement(); Element head = html.getFirstChildElement("head"); if (head != null) { Elements styles = head.getChildElements("style"); for (int i = 0; i < styles.size(); i++) { Element style = styles.get(i); if (styleToRemove.equals(style.getValue())) { head.removeChild(style); } } } }); }
Example #6
Source File: XomReader.java From lams with GNU General Public License v2.0 | 5 votes |
public String peekNextChild() { Elements children = currentElement.getChildElements(); if (null == children || children.size() == 0) { return null; } return decodeNode(children.get(0).getLocalName()); }
Example #7
Source File: XMLCollectionUtil.java From rest-client with Apache License 2.0 | 5 votes |
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 #8
Source File: XmlBodyRead.java From rest-client with Apache License 2.0 | 5 votes |
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 #9
Source File: XmlBodyRead.java From rest-client with Apache License 2.0 | 5 votes |
private ReqEntityPart getMultipartPart(Element e) { final String name = e.getLocalName(); final String partName = e.getAttributeValue("name"); final ContentType ct = getContentType(e); Elements eFields = null; if(e.getChildElements("fields").size() > 0) { eFields = e.getChildElements("fields").get(0).getChildElements("field"); } if("string".equals(name)) { String partBody = getPartValue(e); ReqEntityStringPartBean out = new ReqEntityStringPartBean(partName, ct, partBody); addFields(eFields, out); return out; } else if("file".equals(name)) { File file = new File(getPartValue(e)); String fileName = e.getAttributeValue("filename"); // filename: backward-compatibility: fileName = StringUtil.isEmpty(fileName)? file.getName(): fileName; return new ReqEntityFilePartBean(partName, fileName, ct, file); } else { throw new XMLException("Unsupported element encountered inside <multipart>: " + name); } }
Example #10
Source File: XmlBodyRead.java From rest-client with Apache License 2.0 | 5 votes |
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); } }