Java Code Examples for org.w3c.dom.Element#getNamespaceURI()
The following examples show how to use
org.w3c.dom.Element#getNamespaceURI() .
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: SAMLTokenRenewer.java From cxf with Apache License 2.0 | 6 votes |
/** * Return true if this TokenRenewer implementation is able to renew a token in the given realm. */ public boolean canHandleToken(ReceivedToken renewTarget, String realm) { if (realm != null && !realmMap.containsKey(realm)) { return false; } Object token = renewTarget.getToken(); if (token instanceof Element) { Element tokenElement = (Element)token; String namespace = tokenElement.getNamespaceURI(); String localname = tokenElement.getLocalName(); if ((WSS4JConstants.SAML_NS.equals(namespace) || WSS4JConstants.SAML2_NS.equals(namespace)) && "Assertion".equals(localname)) { return true; } } return false; }
Example 2
Source File: KeyInfoReferenceResolver.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Validate the Element referred to by the KeyInfoReference. * * @param referentElement * * @throws XMLSecurityException */ private void validateReference(Element referentElement) throws XMLSecurityException { if (!XMLUtils.elementIsInSignatureSpace(referentElement, Constants._TAG_KEYINFO)) { Object exArgs[] = { new QName(referentElement.getNamespaceURI(), referentElement.getLocalName()) }; throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.WrongType", exArgs); } KeyInfo referent = new KeyInfo(referentElement, ""); if (referent.containsKeyInfoReference()) { if (secureValidation) { throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithSecure"); } else { // Don't support chains of references at this time. If do support in the future, this is where the code // would go to validate that don't have a cycle, resulting in an infinite loop. This may be unrealistic // to implement, and/or very expensive given remote URI references. throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithoutSecure"); } } }
Example 3
Source File: EntitlementUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public static String getPolicyVersion(String policy) { try { //build XML document DocumentBuilder documentBuilder = getSecuredDocumentBuilder(false); InputStream stream = new ByteArrayInputStream(policy.getBytes()); Document doc = documentBuilder.parse(stream); //get policy version Element policyElement = doc.getDocumentElement(); return policyElement.getNamespaceURI(); } catch (Exception e) { log.debug(e); // ignore exception as default value is used log.warn("Policy version can not be identified. Default XACML 3.0 version is used"); return XACMLConstants.XACML_3_0_IDENTIFIER; } }
Example 4
Source File: TestingUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private static String compareElements(String path, Element e1, Element e2) { if (!e1.getNamespaceURI().equals(e2.getNamespaceURI())) return "Namespaces differ at "+path+": "+e1.getNamespaceURI()+"/"+e2.getNamespaceURI(); if (!e1.getLocalName().equals(e2.getLocalName())) return "Names differ at "+path+": "+e1.getLocalName()+"/"+e2.getLocalName(); path = path + "/"+e1.getLocalName(); String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes()); if (!Utilities.noString(s)) return s; s = compareAttributes(path, e2.getAttributes(), e1.getAttributes()); if (!Utilities.noString(s)) return s; Node c1 = e1.getFirstChild(); Node c2 = e2.getFirstChild(); c1 = skipBlankText(c1); c2 = skipBlankText(c2); while (c1 != null && c2 != null) { if (c1.getNodeType() != c2.getNodeType()) return "node type mismatch in children of "+path+": "+Integer.toString(e1.getNodeType())+"/"+Integer.toString(e2.getNodeType()); if (c1.getNodeType() == Node.TEXT_NODE) { if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent()))) return "Text differs at "+path+": "+normalise(c1.getTextContent()) +"/"+ normalise(c2.getTextContent()); } else if (c1.getNodeType() == Node.ELEMENT_NODE) { s = compareElements(path, (Element) c1, (Element) c2); if (!Utilities.noString(s)) return s; } c1 = skipBlankText(c1.getNextSibling()); c2 = skipBlankText(c2.getNextSibling()); } if (c1 != null) return "node mismatch - more nodes in source in children of "+path; if (c2 != null) return "node mismatch - more nodes in target in children of "+path; return null; }
Example 5
Source File: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private static QName createQName(Element tag) { // intern must be called since Xerces uses == to compare String ? // -> see // https://github.com/apache/xerces2-j/blob/trunk/src/org/apache/xerces/impl/xs/SubstitutionGroupHandler.java#L55 String namespace = tag.getNamespaceURI(); return new QName(tag.getPrefix(), tag.getLocalName().intern(), tag.getTagName().intern(), StringUtils.isEmpty(namespace) ? null : namespace.intern()); }
Example 6
Source File: FedizX509DelegationHandler.java From cxf-fediz with Apache License 2.0 | 5 votes |
public boolean canHandleToken(ReceivedToken delegateTarget) { Object token = delegateTarget.getToken(); if (token instanceof Element) { Element tokenElement = (Element)token; String namespace = tokenElement.getNamespaceURI(); String localname = tokenElement.getLocalName(); if (WSConstants.SIG_NS.equals(namespace) && WSConstants.X509_DATA_LN.equals(localname)) { return true; } } return false; }
Example 7
Source File: SOAPHeaderLoggerHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public boolean handleMessage(SOAPMessageContext ctx) { try { SOAPHeader header = ctx.getMessage().getSOAPHeader(); if (header != null) { Iterator it = ctx.getMessage().getSOAPHeader().examineAllHeaderElements(); while(it.hasNext()) { Object obj = it.next(); if (obj instanceof Element) { Element el = (Element)obj; String nameValue = "{" + el.getNamespaceURI() + "}" + el.getLocalName(); if (this.propList.contains(nameValue)) { LOG.info(ConnectorXmlUtils.toString((Source)(new DOMSource(el)))); } } else { LOG.error("Unsupported Object with name: [" + obj.getClass().getName() + "]"); } } } } catch (SOAPException var7) { LOG.error("SOAPException: " + var7.getMessage(), var7); } catch (TechnicalConnectorException var8) { LOG.error("TechnicalConnectorException: " + var8.getMessage(), var8); } return true; }
Example 8
Source File: ElementCheckerImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void guaranteeThatElementInCorrectSpace( ElementProxy expected, Element actual ) throws XMLSecurityException { String expectedLocalname = expected.getBaseLocalName(); String expectedNamespace = expected.getBaseNamespace(); String localnameIS = actual.getLocalName(); String namespaceIS = actual.getNamespaceURI(); if ((!expectedNamespace.equals(namespaceIS)) || !expectedLocalname.equals(localnameIS) ) { Object exArgs[] = { namespaceIS + ":" + localnameIS, expectedNamespace + ":" + expectedLocalname}; throw new XMLSecurityException("xml.WrongElement", exArgs); } }
Example 9
Source File: DomainExpressionBuilderRegistry.java From cxf with Apache License 2.0 | 5 votes |
public DomainExpression build(Element element) { loadDynamic(); DomainExpressionBuilder builder; QName qname = new QName(element.getNamespaceURI(), element.getLocalName()); builder = get(qname); if (null == builder) { throw new PolicyException(new Message("NO_DOMAINEXPRESSIONBUILDER_EXC", BUNDLE, qname.toString())); } return builder.build(element); }
Example 10
Source File: ElementCheckerImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void guaranteeThatElementInCorrectSpace( ElementProxy expected, Element actual ) throws XMLSecurityException { String expectedLocalname = expected.getBaseLocalName(); String expectedNamespace = expected.getBaseNamespace(); String localnameIS = actual.getLocalName(); String namespaceIS = actual.getNamespaceURI(); if ((!expectedNamespace.equals(namespaceIS)) || !expectedLocalname.equals(localnameIS) ) { Object exArgs[] = { namespaceIS + ":" + localnameIS, expectedNamespace + ":" + expectedLocalname}; throw new XMLSecurityException("xml.WrongElement", exArgs); } }
Example 11
Source File: XCalDocument.java From biweekly with BSD 2-Clause "Simplified" License | 5 votes |
private List<Element> getChildElements(Element parent, QName qname) { List<Element> elements = new ArrayList<Element>(); for (Element child : XmlUtils.toElementList(parent.getChildNodes())) { QName childQName = new QName(child.getNamespaceURI(), child.getLocalName()); if (qname.equals(childQName)) { elements.add(child); } } return elements; }
Example 12
Source File: KeyValueTokenBuilder.java From steady with Apache License 2.0 | 5 votes |
public Assertion build(Element element, AssertionBuilderFactory factory) { SPConstants consts = MS_NS.equals(element.getNamespaceURI()) ? SP11Constants.INSTANCE : SP12Constants.INSTANCE; KeyValueToken token = new KeyValueToken(consts); token.setOptional(PolicyConstants.isOptional(element)); token.setIgnorable(PolicyConstants.isIgnorable(element)); String attribute = element.getAttributeNS(element.getNamespaceURI(), SPConstants.ATTR_INCLUDE_TOKEN); if (StringUtils.isEmpty(attribute)) { attribute = element.getAttributeNS(consts.getNamespace(), SPConstants.ATTR_INCLUDE_TOKEN); } if (StringUtils.isEmpty(attribute)) { attribute = element.getAttributeNS(SP11Constants.INSTANCE.getNamespace(), SPConstants.ATTR_INCLUDE_TOKEN); } if (!StringUtils.isEmpty(attribute)) { token.setInclusion(consts.getInclusionFromAttributeValue(attribute)); } Element polEl = PolicyConstants.findPolicyElement(element); if (polEl == null) { throw new IllegalArgumentException( "sp:KeyValueToken/wsp:Policy must have a value" ); } Element child = DOMUtils.getFirstElement(polEl); if (child != null) { QName qname = new QName(child.getNamespaceURI(), child.getLocalName()); if ("RsaKeyValue".equals(qname.getLocalPart())) { token.setForceRsaKeyValue(true); } } return token; }
Example 13
Source File: ElementCheckerImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void guaranteeThatElementInCorrectSpace( ElementProxy expected, Element actual ) throws XMLSecurityException { String expectedLocalname = expected.getBaseLocalName(); String expectedNamespace = expected.getBaseNamespace(); String localnameIS = actual.getLocalName(); String namespaceIS = actual.getNamespaceURI(); if ((!expectedNamespace.equals(namespaceIS)) || !expectedLocalname.equals(localnameIS) ) { Object exArgs[] = { namespaceIS + ":" + localnameIS, expectedNamespace + ":" + expectedLocalname}; throw new XMLSecurityException("xml.WrongElement", exArgs); } }
Example 14
Source File: TestingUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private static String compareElements(String path, Element e1, Element e2) { if (!e1.getNamespaceURI().equals(e2.getNamespaceURI())) return "Namespaces differ at "+path+": "+e1.getNamespaceURI()+"/"+e2.getNamespaceURI(); if (!e1.getLocalName().equals(e2.getLocalName())) return "Names differ at "+path+": "+e1.getLocalName()+"/"+e2.getLocalName(); path = path + "/"+e1.getLocalName(); String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes()); if (!Utilities.noString(s)) return s; s = compareAttributes(path, e2.getAttributes(), e1.getAttributes()); if (!Utilities.noString(s)) return s; Node c1 = e1.getFirstChild(); Node c2 = e2.getFirstChild(); c1 = skipBlankText(c1); c2 = skipBlankText(c2); while (c1 != null && c2 != null) { if (c1.getNodeType() != c2.getNodeType()) return "node type mismatch in children of "+path+": "+Integer.toString(e1.getNodeType())+"/"+Integer.toString(e2.getNodeType()); if (c1.getNodeType() == Node.TEXT_NODE) { if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent()))) return "Text differs at "+path+": "+normalise(c1.getTextContent()) +"/"+ normalise(c2.getTextContent()); } else if (c1.getNodeType() == Node.ELEMENT_NODE) { s = compareElements(path, (Element) c1, (Element) c2); if (!Utilities.noString(s)) return s; } c1 = skipBlankText(c1.getNextSibling()); c2 = skipBlankText(c2.getNextSibling()); } if (c1 != null) return "node mismatch - more nodes in source in children of "+path; if (c2 != null) return "node mismatch - more nodes in target in children of "+path; return null; }
Example 15
Source File: ExtensibleMetadataProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
public void putConfigurationFragment(Element fragment, boolean shared) throws IllegalArgumentException { if (fragment.getNamespaceURI() == null || fragment.getNamespaceURI().length() == 0) { throw new IllegalArgumentException("Illegal elementName and/or namespace"); // NOI18N } if (fragment.getLocalName().equals(helper.getType().getPrimaryConfigurationDataElementName(shared)) && fragment.getNamespaceURI().equals(helper.getType().getPrimaryConfigurationDataElementNamespace(shared))) { throw new IllegalArgumentException("elementName + namespace reserved for project's primary configuration data"); // NOI18N } helper.putConfigurationFragment(fragment, shared); }
Example 16
Source File: UDA10DeviceDescriptorBinderImpl.java From TVRemoteIME with GNU General Public License v2.0 | 4 votes |
protected void hydrateRoot(MutableDevice descriptor, Element rootElement) throws DescriptorBindingException { if (rootElement.getNamespaceURI() == null || !rootElement.getNamespaceURI().equals(Descriptor.Device.NAMESPACE_URI)) { log.warning("Wrong XML namespace declared on root element: " + rootElement.getNamespaceURI()); } if (!rootElement.getNodeName().equals(ELEMENT.root.name())) { throw new DescriptorBindingException("Root element name is not <root>: " + rootElement.getNodeName()); } NodeList rootChildren = rootElement.getChildNodes(); Node deviceNode = null; for (int i = 0; i < rootChildren.getLength(); i++) { Node rootChild = rootChildren.item(i); if (rootChild.getNodeType() != Node.ELEMENT_NODE) continue; if (ELEMENT.specVersion.equals(rootChild)) { hydrateSpecVersion(descriptor, rootChild); } else if (ELEMENT.URLBase.equals(rootChild)) { try { String urlString = XMLUtil.getTextContent(rootChild); if (urlString != null && urlString.length() > 0) { // We hope it's RFC 2396 and RFC 2732 compliant descriptor.baseURL = new URL(urlString); } } catch (Exception ex) { throw new DescriptorBindingException("Invalid URLBase: " + ex.getMessage()); } } else if (ELEMENT.device.equals(rootChild)) { // Just sanity check here... if (deviceNode != null) throw new DescriptorBindingException("Found multiple <device> elements in <root>"); deviceNode = rootChild; } else { log.finer("Ignoring unknown element: " + rootChild.getNodeName()); } } if (deviceNode == null) { throw new DescriptorBindingException("No <device> element in <root>"); } hydrateDevice(descriptor, deviceNode); }
Example 17
Source File: WSDLParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private Definitions parseDefinitionsNoImport( TWSDLParserContextImpl context, Document doc) { Element e = doc.getDocumentElement(); //at this poinjt we expect a wsdl or schema document to be fully qualified if(e.getNamespaceURI() == null || (!e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !e.getLocalName().equals("definitions"))){ return null; } context.push(); context.registerNamespaces(e); Definitions definitions = new Definitions(context.getDocument(), forest.locatorTable.getStartLocation(e)); String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME); definitions.setName(name); String targetNamespaceURI = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TARGET_NAMESPACE); definitions.setTargetNamespaceURI(targetNamespaceURI); boolean gotDocumentation = false; boolean gotTypes = false; for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { Element e2 = Util.nextElement(iter); if (e2 == null) break; if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { if (gotDocumentation) { errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); return null; } gotDocumentation = true; if(definitions.getDocumentation() == null) definitions.setDocumentation(getDocumentationFor(e2)); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_TYPES)) { if (gotTypes && !options.isExtensionMode()) { errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_TYPES_ALLOWED(Constants.TAG_DEFINITIONS)); return null; } gotTypes = true; //add all the wsdl:type elements to latter make a list of all the schema elements // that will be needed to create jaxb model if(!options.isExtensionMode()) validateSchemaImports(e2); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_MESSAGE)) { Message message = parseMessage(context, definitions, e2); definitions.add(message); } else if ( XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT_TYPE)) { PortType portType = parsePortType(context, definitions, e2); definitions.add(portType); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_BINDING)) { Binding binding = parseBinding(context, definitions, e2); definitions.add(binding); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_SERVICE)) { Service service = parseService(context, definitions, e2); definitions.add(service); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_IMPORT)) { definitions.add(parseImport(context, definitions, e2)); } else if (XmlUtil.matchesTagNS(e2, SchemaConstants.QNAME_IMPORT)) { errReceiver.warning(forest.locatorTable.getStartLocation(e2), WsdlMessages.WARNING_WSI_R_2003()); } else { // possible extensibility element -- must live outside the WSDL namespace checkNotWsdlElement(e2); if (!handleExtension(context, definitions, e2)) { checkNotWsdlRequired(e2); } } } context.pop(); context.fireDoneParsingEntity( WSDLConstants.QNAME_DEFINITIONS, definitions); return definitions; }
Example 18
Source File: WSDLParser.java From hottub with GNU General Public License v2.0 | 4 votes |
private Definitions parseDefinitionsNoImport( TWSDLParserContextImpl context, Document doc) { Element e = doc.getDocumentElement(); //at this poinjt we expect a wsdl or schema document to be fully qualified if(e.getNamespaceURI() == null || (!e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !e.getLocalName().equals("definitions"))){ return null; } context.push(); context.registerNamespaces(e); Definitions definitions = new Definitions(context.getDocument(), forest.locatorTable.getStartLocation(e)); String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME); definitions.setName(name); String targetNamespaceURI = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TARGET_NAMESPACE); definitions.setTargetNamespaceURI(targetNamespaceURI); boolean gotDocumentation = false; boolean gotTypes = false; for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) { Element e2 = Util.nextElement(iter); if (e2 == null) break; if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_DOCUMENTATION)) { if (gotDocumentation) { errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_DOCUMENTATION_ALLOWED(e.getLocalName())); return null; } gotDocumentation = true; if(definitions.getDocumentation() == null) definitions.setDocumentation(getDocumentationFor(e2)); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_TYPES)) { if (gotTypes && !options.isExtensionMode()) { errReceiver.error(forest.locatorTable.getStartLocation(e2), WsdlMessages.PARSING_ONLY_ONE_TYPES_ALLOWED(Constants.TAG_DEFINITIONS)); return null; } gotTypes = true; //add all the wsdl:type elements to latter make a list of all the schema elements // that will be needed to create jaxb model if(!options.isExtensionMode()) validateSchemaImports(e2); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_MESSAGE)) { Message message = parseMessage(context, definitions, e2); definitions.add(message); } else if ( XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_PORT_TYPE)) { PortType portType = parsePortType(context, definitions, e2); definitions.add(portType); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_BINDING)) { Binding binding = parseBinding(context, definitions, e2); definitions.add(binding); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_SERVICE)) { Service service = parseService(context, definitions, e2); definitions.add(service); } else if (XmlUtil.matchesTagNS(e2, WSDLConstants.QNAME_IMPORT)) { definitions.add(parseImport(context, definitions, e2)); } else if (XmlUtil.matchesTagNS(e2, SchemaConstants.QNAME_IMPORT)) { errReceiver.warning(forest.locatorTable.getStartLocation(e2), WsdlMessages.WARNING_WSI_R_2003()); } else { // possible extensibility element -- must live outside the WSDL namespace checkNotWsdlElement(e2); if (!handleExtension(context, definitions, e2)) { checkNotWsdlRequired(e2); } } } context.pop(); context.fireDoneParsingEntity( WSDLConstants.QNAME_DEFINITIONS, definitions); return definitions; }
Example 19
Source File: Util.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static boolean isTagName(Element element, QName name){ return (element.getLocalName().equals(name.getLocalPart()) && (element.getNamespaceURI() != null && element.getNamespaceURI().equals(name.getNamespaceURI()))); }
Example 20
Source File: Util.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static boolean isTagName(Element element, QName name){ return (element.getLocalName().equals(name.getLocalPart()) && (element.getNamespaceURI() != null && element.getNamespaceURI().equals(name.getNamespaceURI()))); }