public String getElementQName(Object o) { return (isElement(o) ? ((Element)o).getQualifiedName() : null); }
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 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 nodeName = tNode.getQualifiedName(); if ("http-version".equals(nodeName)) { String t = tNode.getValue();
if (!"rest-client".equals(rootNode.getQualifiedName())) { throw new XMLException("Root node is not <rest-client>"); for (int i = 0; i < responseNode.getChildElements().size(); i++) { tNode = responseNode.getChildElements().get(i); String nodeName = tNode.getQualifiedName(); String nn = tNode.getQualifiedName(); if ("run-count".equals(nn)) { throw new XMLException("<headers> element should contain only <header> elements");
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); }
public MissingAttributeException(final String attributeName, final Element sourceElement) { super("Missing Attribute["+attributeName+"] for Element["+sourceElement.getQualifiedName()+"]."); } }
public MissingAttributeException(final String attributeName, final Element sourceElement, final Exception cause) { super("Missing Attribute["+attributeName+"] for Element["+sourceElement.getQualifiedName()+"].", cause); }
public static int parseIntegerAttributeValue(final String attributeName, final Element sourceElement) throws MissingAttributeException, XMLParsingException { try { return Integer.parseInt(parseAttributeValue(attributeName, sourceElement)); } catch (NumberFormatException ex) { throw new XMLParsingException("Could not parse integer attribute[" + attributeName + "] for element[" + sourceElement.getQualifiedName() + "].", ex); } }
public static <T extends Enum<T>> T parseEnumAttributeValue(final String attributeName, final Element sourceElement, final Class<T> enumType) throws MissingAttributeException, XMLParsingException { String attributeValue = parseAttributeValue(attributeName, sourceElement); try { return Enum.valueOf(enumType, attributeValue); } catch (java.lang.IllegalArgumentException ex) { throw new XMLParsingException("Could not resolve enum value[" + attributeValue + "] out of attribute[" + attributeName + "] for element[" + sourceElement.getQualifiedName() + "].", ex); } }
private static HashMap<String, String> getGroupDefinitions(Element e) { HashMap<String, String> groups = new HashMap<String, String>(); Elements children = e.getChildElements(); for (int i = 0; i < children.size(); i++) { Element child = children.get(i); if (child.getQualifiedName().equals("group")) { String id = child.getAttributeValue("id").trim(); String smarts = child.getValue().trim(); groups.put(id, smarts); } } return groups; }
private static HashMap<String, String> getGroupDefinitions(Element e) { HashMap<String, String> groups = new HashMap<String, String>(); Elements children = e.getChildElements(); for (int i = 0; i < children.size(); i++) { Element child = children.get(i); if (child.getQualifiedName().equals("group")) { String id = child.getAttributeValue("id").trim(); String smarts = child.getValue().trim(); groups.put(id, smarts); } } return groups; }
/** * Get the display name of this node. For elements and attributes this is * [prefix:]localname. For unnamed nodes, it is an empty string. * * @return The display name of this node. For a node with no name, return an * empty string. */ public String getDisplayName() { switch (nodeKind) { case Type.ELEMENT: return ((Element) node).getQualifiedName(); case Type.ATTRIBUTE: return ((Attribute) node).getQualifiedName(); case Type.PROCESSING_INSTRUCTION: return ((ProcessingInstruction) node).getTarget(); default: return ""; } }
public static Elements parseChildElements(final Element sourceElement, final String childElementName, final boolean atLeastOne) throws XMLParsingException { Elements childElements = sourceElement.getChildElements(childElementName); if (atLeastOne && childElements.size() == 0) { throw new XMLParsingException("Missing at least one element[" + childElementName + "] for parent element[" + sourceElement.getQualifiedName() + "]."); } return childElements; }
private static List<PharmacophoreQuery> getdefs(Document doc) throws CDKException { Element root = doc.getRootElement(); // ltes get the children of the container // these will be either group or pharmacophore elems List<PharmacophoreQuery> ret = new ArrayList<PharmacophoreQuery>(); // get global group defs HashMap<String, String> groups = getGroupDefinitions(root); //now get the pcore defs Elements children = root.getChildElements(); for (int i = 0; i < children.size(); i++) { Element e = children.get(i); if (e.getQualifiedName().equals("pharmacophore")) ret.add(processPharmacophoreElement(e, groups)); } return ret; }
private static List<PharmacophoreQuery> getdefs(Document doc) throws CDKException { Element root = doc.getRootElement(); // ltes get the children of the container // these will be either group or pharmacophore elems List<PharmacophoreQuery> ret = new ArrayList<PharmacophoreQuery>(); // get global group defs HashMap<String, String> groups = getGroupDefinitions(root); //now get the pcore defs Elements children = root.getChildElements(); for (int i = 0; i < children.size(); i++) { Element e = children.get(i); if (e.getQualifiedName().equals("pharmacophore")) ret.add(processPharmacophoreElement(e, groups)); } return ret; }
public BayesIm getBayesIm(Element element) { if (!"bayesNet".equals(element.getQualifiedName())) { throw new IllegalArgumentException("Expecting 'bayesNet' element."); } Elements elements = element.getChildElements(); Element element0 = elements.get(0); Element element1 = elements.get(1); Element element2 = elements.get(2); List<Node> variables = getVariables(element0); BayesPm bayesPm = makeBayesPm(variables, element1); return makeBayesIm(bayesPm, element2); }
protected SwordValidationInfo handleIncorrectElement(Element element, Properties validationProperties) throws UnmarshallException { log.error( "Unexpected element. Expected: " + getQualifiedName() + ". Got: " + ((element != null) ? element.getQualifiedName() : "null")); if (validationProperties != null) { SwordValidationInfo info = new SwordValidationInfo( new XmlName(element.getNamespacePrefix(), element.getLocalName(), element.getNamespaceURI()), "This is not the expected element. Received: " + element.getQualifiedName() + " for namespaceUri: " + element.getNamespaceURI(), SwordValidationInfoType.ERROR ); return info; } else { throw new UnmarshallException("Not a " + getQualifiedName() + " element"); } }
private static void addMarginalErrorDistribution(Element marginalDistributionElement, SemIm semIm) { if (!SemXmlConstants.MARGINAL_ERROR_DISTRIBUTION.equals(marginalDistributionElement.getQualifiedName())) { throw new IllegalArgumentException("Expecting '" + SemXmlConstants.MARGINAL_ERROR_DISTRIBUTION + "' element"); //$NON-NLS-1$ //$NON-NLS-2$ } Element normal; Node node; Elements normals = marginalDistributionElement.getChildElements(SemXmlConstants.NORMAL); for (int i = 0; i < normals.size(); i++) { normal = normals.get(i); SemGraph graph = semIm.getSemPm().getGraph(); graph.setShowErrorTerms(true); node = graph.getExogenous(graph.getNode(normal.getAttributeValue(SemXmlConstants.VARIABLE))); //can't set mean at this point... semIm.setParamValue(node, node, new Double(normal.getAttributeValue(SemXmlConstants.VARIANCE))); } }
private static void addJointErrorDistribution(Element jointDistributionElement, SemIm semIm) { if (!SemXmlConstants.JOINT_ERROR_DISTRIBUTION.equals(jointDistributionElement.getQualifiedName())) { throw new IllegalArgumentException("Expecting '" + SemXmlConstants.JOINT_ERROR_DISTRIBUTION + "' element"); //$NON-NLS-1$ //$NON-NLS-2$ } Element normal; Node node1, node2; Elements normals = jointDistributionElement.getChildElements(SemXmlConstants.NORMAL); for (int i = 0; i < normals.size(); i++) { normal = normals.get(i); node1 = semIm.getSemPm().getGraph().getExogenous(semIm.getSemPm().getGraph().getNode(normal.getAttributeValue(SemXmlConstants.NODE_1))); node2 = semIm.getSemPm().getGraph().getExogenous(semIm.getSemPm().getGraph().getNode(normal.getAttributeValue(SemXmlConstants.NODE_2))); semIm.setParamValue(node1, node2, new Double(normal.getAttributeValue(SemXmlConstants.COVARIANCE))); } }