List of usage examples for org.w3c.dom Attr getNodeValue
public String getNodeValue() throws DOMException;
From source file:eu.elf.license.LicenseParser.java
/** * Creates list of LicenseModel elements * * @param productElementList - NodeList of <ns:product> elements: * @return List of LicenseModel objects/* www. j av a 2 s . c om*/ */ private static List<LicenseModel> createLicenseModelList(NodeList productElementList) { List<LicenseModel> lmList = new ArrayList<LicenseModel>(); for (int i = 0; i < productElementList.getLength(); i++) { LicenseModel tempLM = new LicenseModel(); Boolean isRestricted = true; Element productElement = (Element) productElementList.item(i); NamedNodeMap productElementAttributeMap = productElement.getAttributes(); for (int j = 0; j < productElementAttributeMap.getLength(); j++) { Attr attrs = (Attr) productElementAttributeMap.item(j); if (attrs.getNodeName().equals("id")) { if (attrs.getNodeName() != null) { tempLM.setId(attrs.getNodeValue()); } } } Element titleElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (titleElement != null) { tempLM.setName(titleElement.getTextContent()); } Element abstractElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "abstract").item(0); if (abstractElement != null) { tempLM.setDescription(abstractElement.getTextContent()); } Element calculationElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "calculation").item(0); Element declarationListElement = (Element) calculationElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "declarationList").item(0); Element predefinedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "predefinedParameters").item(0); NodeList predefinedParametersParameterElementList = predefinedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int k = 0; k < predefinedParametersParameterElementList.getLength(); k++) { Element parameterElement = (Element) predefinedParametersParameterElementList.item(k); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int l = 0; l < parameterElementAttributeMap.getLength(); l++) { Attr attrs = (Attr) parameterElementAttributeMap.item(l); if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { if (attrs.getNodeValue().equals("ALL_ROLES")) { Element valueElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); if (valueElement.getTextContent().equals("true")) { isRestricted = false; } } } } if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { if (attrs.getNodeValue().equals("ALLOWED_ROLES")) { NodeList valueElementList = parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int m = 0; m < valueElementList.getLength(); m++) { tempLM.addRole(valueElementList.item(m).getTextContent()); } } } } } } tempLM.setRestricted(isRestricted); tempLM.setParams(createLicenseModelParamList(declarationListElement)); lmList.add(tempLM); } return lmList; }
From source file:com.aaasec.sigserv.cscommon.xmldsig.OfflineResolver.java
/** * We resolve http URIs <I>without</I> fragment... * * @param uri//from ww w . j a va2 s. com * @param BaseURI * */ public boolean engineCanResolve(Attr uri, String BaseURI) { String uriNodeValue = uri.getNodeValue(); if (uriNodeValue.equals("") || uriNodeValue.startsWith("#")) { return false; } try { URI uriNew = getNewURI(uri.getNodeValue(), BaseURI); if (uriNew.getScheme().equals("http")) { log.debug("I state that I can resolve " + uriNew.toString()); return true; } log.debug("I state that I can't resolve " + uriNew.toString()); } catch (URISyntaxException ex) { // } return false; }
From source file:com.aaasec.sigserv.cscommon.xmldsig.OfflineResolver.java
/** * Method engineResolve//from w w w . j av a 2 s . c om * * @param uri * @param BaseURI * * @throws ResourceResolverException */ public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException { try { String URI = uri.getNodeValue(); if (OfflineResolver._uriMap.containsKey(URI)) { String newURI = OfflineResolver._uriMap.get(URI); log.debug("Mapped " + URI + " to " + newURI); InputStream is = new FileInputStream(newURI); log.debug("Available bytes = " + is.available()); XMLSignatureInput result = new XMLSignatureInput(is); // XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(URI); result.setMIMEType((String) OfflineResolver._mimeMap.get(URI)); return result; } else { Object exArgs[] = { "The URI " + URI + " is not configured for offline work" }; throw new ResourceResolverException("generic.EmptyMessage", exArgs, uri, BaseURI); } } catch (IOException ex) { throw new ResourceResolverException("generic.EmptyMessage", ex, uri, BaseURI); } }
From source file:eu.europa.ec.markt.dss.validation102853.xades.OfflineResolver.java
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { final Attr uriAttr = context.attr; final String baseUriString = context.baseUri; String uriNodeValue = uriAttr.getNodeValue(); final DSSDocument document = getDocument(uriNodeValue); if (document != null) { // The input stream is closed automatically by XMLSignatureInput class // TODO-Bob (05/09/2014): There is an error concerning the input streams base64 encoded. Some extra bytes are added within the santuario which breaks the HASH. // TODO-Vin (05/09/2014): Can you create an isolated test-case JIRA DSS-? InputStream inputStream = document.openStream(); // final byte[] bytes = DSSUtils.toByteArray(inputStream); // final String string = new String(bytes); // inputStream = DSSUtils.toInputStream(bytes); final XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNodeValue); final MimeType mimeType = document.getMimeType(); if (mimeType != null) { result.setMIMEType(mimeType.getCode()); }/* w w w. j a v a 2s . co m*/ return result; } else { Object exArgs[] = { "The uriNodeValue " + uriNodeValue + " is not configured for offline work" }; throw new ResourceResolverException("generic.EmptyMessage", exArgs, uriNodeValue, baseUriString); } }
From source file:eu.europa.ec.markt.dss.validation102853.toolbox.XPointerResourceResolver.java
@Override public boolean engineCanResolveURI(final ResourceResolverContext context) { final Attr uriAttr = context.attr; final String uri = uriAttr.getNodeValue(); final boolean xPointerQuery = isXPointerQuery(uri, false); if (LOG.isDebugEnabled()) { LOG.debug("I state that I " + (xPointerQuery ? "can" : "cannot") + " resolve Uri/Base Uri:'" + uri + "/" + context.baseUri + "'"); }/* w ww . j a v a 2s . co m*/ return xPointerQuery; }
From source file:eu.europa.ec.markt.dss.validation102853.xades.OfflineResolver.java
@Override public boolean engineCanResolveURI(final ResourceResolverContext context) { final Attr uriAttr = context.attr; final String baseUriString = context.baseUri; String documentUri = uriAttr.getNodeValue(); if (documentUri.equals("") || documentUri.startsWith("#")) { return false; }/*w ww.j av a2s .c o m*/ try { if (isKnown(documentUri) != null) { LOG.debug("I state that I can resolve '" + documentUri.toString() + "' (external document)"); return true; } final URI baseUri = new URI(baseUriString); URI uriNew = new URI(baseUri, documentUri); if (uriNew.getScheme().equals("http")) { LOG.debug("I state that I can resolve '" + uriNew.toString() + "'"); return true; } LOG.debug("I state that I can't resolve '" + uriNew.toString() + "'"); } catch (URI.MalformedURIException ex) { if (documents == null || documents.size() == 0) { LOG.warn("OfflineResolver: WARNING: ", ex); } } if (doesContainOnlyOneDocument()) { return true; } return false; }
From source file:eu.europa.esig.dss.xades.validation.OfflineResolver.java
@Override public boolean engineCanResolveURI(final ResourceResolverContext context) { final Attr uriAttr = context.attr; if (uriAttr != null) { String documentUri = uriAttr.getNodeValue(); documentUri = decodeUrl(documentUri); if ("".equals(documentUri) || documentUri.startsWith("#")) { return false; }/*from w w w . j a v a 2 s .com*/ try { if (isKnown(documentUri) != null) { LOG.debug("I state that I can resolve '" + documentUri.toString() + "' (external document)"); return true; } final String baseUriString = context.baseUri; if (StringUtils.isNotEmpty(baseUriString)) { final URI baseUri = new URI(baseUriString); URI uriNew = new URI(baseUri, documentUri); if (uriNew.getScheme().equals("http")) { LOG.debug("I state that I can resolve '" + uriNew.toString() + "'"); return true; } LOG.debug("I state that I can't resolve '" + uriNew.toString() + "'"); } } catch (URI.MalformedURIException ex) { if (documents == null || documents.size() == 0) { LOG.warn("OfflineResolver: WARNING: ", ex); } } } else if (doesContainOnlyOneDocument()) { // no URI is allowed in ASiC-S with one file return true; } return false; }
From source file:ar.com.zauber.commons.web.transformation.sanitizing.impl.AbstractElementNodeSanitizer.java
/** * Recursive tree traversal//w w w .j a v a2 s . c om * @param node * @param invalidElements */ private void sanitizeNode(final Node node, final List<Element> invalidElements) { if (node.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) node; if (!tagSecurityStrategy.isTagAllowed(element.getNodeName())) { invalidElements.add(element); return; } else { final NamedNodeMap attributes = node.getAttributes(); if (attributes.getLength() > 0) { final List<Attr> invalidAttributes = new ArrayList<Attr>(); for (int i = 0; i < attributes.getLength(); ++i) { final Attr attribute = (Attr) attributes.item(i); if (!tagSecurityStrategy.isAttributeAllowedForTag(attribute.getNodeName(), element.getNodeName()) || !tagSecurityStrategy.isAttributeValueValidForTag(attribute.getNodeValue(), attribute.getNodeName(), element.getNodeName())) { invalidAttributes.add(attribute); } } processInvalidElementAttributes(element, invalidAttributes); } } } final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { sanitizeNode(children.item(i), invalidElements); } }
From source file:eu.europa.ec.markt.dss.validation102853.toolbox.XPointerResourceResolver.java
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { final Attr uriAttr = context.attr; final String baseUri = context.baseUri; String uriNodeValue = uriAttr.getNodeValue(); if (uriNodeValue.charAt(0) != '#') { return null; }//from w w w . ja v a 2s . c o m String xpURI; try { xpURI = URLDecoder.decode(uriNodeValue, "utf-8"); } catch (UnsupportedEncodingException e) { LOG.warn("utf-8 not a valid encoding", e); return null; } String parts[] = xpURI.substring(1).split("\\s"); int i = 0; DSigNamespaceContext nsContext = null; if (parts.length > 1) { nsContext = new DSigNamespaceContext(); for (; i < parts.length - 1; ++i) { if (!parts[i].endsWith(")") || !parts[i].startsWith(XNS_OPEN)) { return null; } String mapping = parts[i].substring(XNS_OPEN.length(), parts[i].length() - 1); int pos = mapping.indexOf('='); if (pos <= 0 || pos >= mapping.length() - 1) { throw new ResourceResolverException("malformed namespace part of XPointer expression", uriNodeValue, baseUri); } nsContext.addNamespace(mapping.substring(0, pos), mapping.substring(pos + 1)); } } try { Node node = null; NodeList nodes = null; // plain ID reference. if (i == 0 && !parts[i].startsWith(XP_OPEN)) { node = this.baseNode.getOwnerDocument().getElementById(parts[i]); } else { if (!parts[i].endsWith(")") || !parts[i].startsWith(XP_OPEN)) { return null; } XPath xp = this.xPathFactory.newXPath(); if (nsContext != null) { xp.setNamespaceContext(nsContext); } nodes = (NodeList) xp.evaluate(parts[i].substring(XP_OPEN.length(), parts[i].length() - 1), this.baseNode, XPathConstants.NODESET); if (nodes.getLength() == 0) { return null; } if (nodes.getLength() == 1) { node = nodes.item(0); } } XMLSignatureInput result = null; if (node != null) { result = new XMLSignatureInput(node); } else if (nodes != null) { Set<Node> nodeSet = new HashSet<Node>(nodes.getLength()); for (int j = 0; j < nodes.getLength(); ++j) { nodeSet.add(nodes.item(j)); } result = new XMLSignatureInput(nodeSet); } else { return null; } result.setMIMEType("text/xml"); result.setExcludeComments(true); result.setSourceURI((baseUri != null) ? baseUri.concat(uriNodeValue) : uriNodeValue); return result; } catch (XPathExpressionException e) { throw new ResourceResolverException("malformed XPath inside XPointer expression", e, uriNodeValue, baseUri); } }
From source file:eu.europa.esig.dss.xades.validation.OfflineResolver.java
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { final Attr uriAttr = context.attr; String documentUri = null;//from w w w . j av a 2s . com if (uriAttr == null && doesContainOnlyOneDocument()) { documentUri = ""; } else if (uriAttr != null) { documentUri = uriAttr.getNodeValue(); } documentUri = decodeUrl(documentUri); final DSSDocument document = getDocument(documentUri); if (document != null) { // The input stream is closed automatically by XMLSignatureInput class // TODO-Bob (05/09/2014): There is an error concerning the input streams base64 encoded. Some extra bytes // are added within the santuario which breaks the HASH. // TODO-Vin (05/09/2014): Can you create an isolated test-case JIRA DSS-? InputStream inputStream = document.openStream(); final XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(documentUri); final MimeType mimeType = document.getMimeType(); if (mimeType != null) { result.setMIMEType(mimeType.getMimeTypeString()); } return result; } else { Object exArgs[] = { "The uriNodeValue " + documentUri + " is not configured for offline work" }; throw new ResourceResolverException("generic.EmptyMessage", exArgs, documentUri, context.baseUri); } }