private static ContentType getContentType(Element e) { String contentType = e.getAttributeValue("content-type"); String charsetStr = e.getAttributeValue("charset"); if(StringUtil.isNotEmpty(contentType)) { return new ContentTypeBean(contentType, (charsetStr!=null? Charset.forName(charsetStr): null)); } else { return null; } } }
public String getAttribute(String name) { return currentElement.getAttributeValue(encodeAttribute(name)); }
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; }
private ReqEntityMultipartBean getMultipart(Element e) { final String subTypeStr = e.getAttributeValue("subtype"); final MultipartSubtype subType = subTypeStr!=null? MultipartSubtype.valueOf(subTypeStr): MultipartSubtype.FORM_DATA; final String mode = e.getAttributeValue("mode"); MultipartMode format = StringUtil.isNotEmpty(mode)? MultipartMode.valueOf(mode): null; List<ReqEntityPart> parts = getMultipartParts(e); return new ReqEntityMultipartBean(parts, format, subType); }
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; }
String docID = docElem.getAttributeValue("id"); Matcher matcher = datePattern.matcher(docID); matcher.find();
private ReqEntityPart getMultipartPart(Element e) { final String name = e.getLocalName(); final String partName = e.getAttributeValue("name"); final ContentType ct = getContentType(e); String fileName = e.getAttributeValue("filename");
final SSLKeyStoreBean keyStore = new SSLKeyStoreBean(); final String typeStr = e.getAttributeValue("type"); if(StringUtil.isNotEmpty(typeStr)) keyStore.setType(KeyStoreType.valueOf(typeStr)); keyStore.setFile(new File(e.getAttributeValue("file"))); keyStore.setPassword(Util.base64decode(e.getAttributeValue("password")).toCharArray()); out.setKeyStore(keyStore); break; final SSLKeyStoreBean trustStore = new SSLKeyStoreBean(); final String typeStr = e.getAttributeValue("type"); if(StringUtil.isNotEmpty(typeStr)) trustStore.setType(KeyStoreType.valueOf(typeStr)); trustStore.setFile(new File(e.getAttributeValue("file"))); trustStore.setPassword(Util.base64decode(e.getAttributeValue("password")).toCharArray()); out.setTrustStore(trustStore); break;
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; }
Versions.versionValidCheck(rootNode.getAttributeValue("version")); } else if ("status".equals(nodeName)) { responseBean.setStatusLine(tNode.getValue()); responseBean.setStatusCode(Integer.parseInt(tNode.getAttributeValue("code"))); } else if ("headers".equals(nodeName)) { Map<String, String> m = getHeadersFromHeaderNode(tNode);
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); }
@Override public String getAttribute(final String name) { return currentElement.getAttributeValue(encodeAttribute(name)); }
/** * Get full class name (package + class) for "class" XML element. * * @param elem The element. * @return the full class name (package + class) for "class" XML element. */ private String fullClassName( Element elem ) { final Element packageElem = (Element) elem.getParent().getParent(); final String packageName = packageElem.getAttributeValue( "name" ); final String className = elem.getAttributeValue( "name" ); return packageName.length() != 0 ? packageName + "." + className : className; }
void createPattern() { List<Node> patterns = CMLUtil.getQueryNodes(simpleType, "./" + XSD_RESTRICTION + CMLConstants.S_SLASH + XSD_PATTERN, XPATH_XSD); if (patterns.size() > 0) { pattern = ((Element) patterns.get(0)).getAttributeValue("value"); } }
private static void copyAttributeTo(Element from, Element to, String attName) { String attVal = from.getAttributeValue(attName); if (attVal != null) { to.addAttribute(new Attribute(attName, attVal)); } }
/** constructor. * @param xsdElement */ public CMLElementType(Element xsdElement) { init(); this.xsdElement = xsdElement; this.name = xsdElement.getAttributeValue("name"); processContentTypes(); }
private static void setNodeMeans(Element variablesElement, SemIm im) { Elements vars = variablesElement.getChildElements(SemXmlConstants.CONTINUOUS_VARIABLE); for (int i = 0; i < vars.size(); i++) { Element var = vars.get(i); Node node = im.getSemPm().getGraph().getNode(var.getAttributeValue(SemXmlConstants.NAME)); if (var.getAttributeValue(SemXmlConstants.MEAN) != null) { im.setMean(node, Double.parseDouble(var.getAttributeValue(SemXmlConstants.MEAN))); } else { return; } } }
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; }
private String categorize(Element row) { String cssClass = row.getAttributeValue("class"); if (cssClass == null) { Element cell = (Element) row.query("td").get(0); cssClass = cell.getAttributeValue("class"); } Check.notNull(cssClass, "cssClass is null"); return cssClass.toUpperCase(); }
protected Attributes toAttributes(nu.xom.Element eAttributes) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { Attributes attributes = new Attributes(); nu.xom.Elements eAttributeList = eAttributes.getChildElements("attribute", SpecificationWriter.NS); for (nu.xom.Element element : iterable(eAttributeList)) { String name = element.getAttributeValue("name"); Object value = toAttribute(element); attributes.put(name, value); } return attributes; }