/** * Returns true if the xpath query contains something * * @param xmlNode * the current node * @param xPathString * the expected child node * @return true if the current node has any filled child node */ public static boolean isNotEmpty(final Node xmlNode, final String xPathString) { // xpath suffix allows to skip text nodes and empty lines NodeList nodeList = getNodeList(xmlNode, xPathString + "/child::node()[not(self::text())]"); return (nodeList != null) && (nodeList.getLength() > 0); }
/** * Returns the Node corresponding to the XPath query. * * @param xmlNode * The node where the search should be performed. * @param xPathString * XPath query string * @return the Node corresponding to the XPath query. */ public static Node getNode(final Node xmlNode, final String xPathString) { final NodeList list = getNodeList(xmlNode, xPathString); if (list.getLength() > 1) { throw new DSSException("More than one result for XPath: " + xPathString); } return list.item(0); }
protected Set<CertificateToken> findCertificates(String xPath) { Set<CertificateToken> certificates = new HashSet<>(); NodeList nodeList = DomUtils.getNodeList(signatureElement, xPath); for (int i = 0; i < nodeList.getLength(); i++) { Element certificateElement = (Element) nodeList.item(i); CertificateToken certToken = createCertificateToken(certificateElement); if (!certificates.contains(certToken)) { String idIdentifier = DSSXMLUtils.getIDIdentifier(certificateElement); certToken.setXmlId(idIdentifier); certificates.add(certToken); } } return certificates; }
private TimeStampToken findTimestampToken() { logger.debug("Finding timestamp token"); NodeList timestampNodes = DomUtils.getNodeList(signatureElement, xPathQueryHolder.XPATH_SIGNATURE_TIMESTAMP); if (timestampNodes.getLength() == 0) { logger.warn("Signature timestamp element was not found"); return null; } if (timestampNodes.getLength() > 1) { logger.warn("Signature contains more than one timestamp: " + timestampNodes.getLength() + ". Using only the first one"); } Node timestampNode = timestampNodes.item(0); Element timestampTokenNode = DomUtils.getElement(timestampNode, xPathQueryHolder.XPATH__ENCAPSULATED_TIMESTAMP); if (timestampTokenNode == null) { logger.warn("The timestamp cannot be extracted from the signature"); return null; } String base64EncodedTimestamp = timestampTokenNode.getTextContent(); return createTimeStampToken(base64EncodedTimestamp); }