Java Code Examples for org.w3c.dom.Attr#getNamespaceURI()
The following examples show how to use
org.w3c.dom.Attr#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: DomPostInitAction.java From hottub with GNU General Public License v2.0 | 6 votes |
public void run() { Set<String> declaredPrefixes = new HashSet<String>(); for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) { NamedNodeMap atts = n.getAttributes(); if(atts==null) continue; // broken DOM. but be graceful. for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); String nsUri = a.getNamespaceURI(); if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) continue; // not a namespace declaration String prefix = a.getLocalName(); if(prefix==null) continue; // broken DOM. skip to be safe if(prefix.equals("xmlns")) { prefix = ""; } String value = a.getValue(); if(value==null) continue; // broken DOM. skip to be safe if(declaredPrefixes.add(prefix)) { serializer.addInscopeBinding(value,prefix); } } } }
Example 2
Source File: AnyTypeBeanInfo.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void serializeAttributes(Object element, XMLSerializer target) throws SAXException { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); // work defensively String uri = a.getNamespaceURI(); if(uri==null) uri=""; String local = a.getLocalName(); String name = a.getName(); if(local==null) local = name; if (uri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE) && ("nil".equals(local))) { isNilIncluded = true; } if(name.startsWith("xmlns")) continue;// DOM reports ns decls as attributes target.attribute(uri,local,a.getValue()); } }
Example 3
Source File: AnyTypeBeanInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void serializeURIs(Object element, XMLSerializer target) { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); NamespaceContext2 context = target.getNamespaceContext(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); if ("xmlns".equals(a.getPrefix())) { context.force(a.getValue(), a.getLocalName()); continue; } if ("xmlns".equals(a.getName())) { if (element instanceof org.w3c.dom.Element) { context.declareNamespace(a.getValue(), null, false); continue; } else { context.force(a.getValue(), ""); continue; } } String nsUri = a.getNamespaceURI(); if(nsUri!=null && nsUri.length()>0) context.declareNamespace( nsUri, a.getPrefix(), true ); } }
Example 4
Source File: AnyTypeBeanInfo.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void serializeURIs(Object element, XMLSerializer target) { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); NamespaceContext2 context = target.getNamespaceContext(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); if ("xmlns".equals(a.getPrefix())) { context.force(a.getValue(), a.getLocalName()); continue; } if ("xmlns".equals(a.getName())) { if (element instanceof org.w3c.dom.Element) { context.declareNamespace(a.getValue(), null, false); continue; } else { context.force(a.getValue(), ""); continue; } } String nsUri = a.getNamespaceURI(); if(nsUri!=null && nsUri.length()>0) context.declareNamespace( nsUri, a.getPrefix(), true ); } }
Example 5
Source File: Locators.java From ttt with BSD 2-Clause "Simplified" License | 6 votes |
private static String getLocatorAttribute(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; ++i) { Node item = attributes.item(i); if (!(item instanceof Attr)) continue; Attr attribute = (Attr) item; String nsUri = attribute.getNamespaceURI(); String localName = attribute.getLocalName(); if (localName == null) localName = attribute.getName(); if (localName.indexOf("xmlns") == 0) continue; QName name = new QName(nsUri != null ? nsUri : "", localName); if (name.equals(getLocatorAttributeQName())) return attribute.getValue(); } return null; }
Example 6
Source File: DomPostInitAction.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void run() { Set<String> declaredPrefixes = new HashSet<String>(); for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) { NamedNodeMap atts = n.getAttributes(); if(atts==null) continue; // broken DOM. but be graceful. for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); String nsUri = a.getNamespaceURI(); if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) continue; // not a namespace declaration String prefix = a.getLocalName(); if(prefix==null) continue; // broken DOM. skip to be safe if(prefix.equals("xmlns")) { prefix = ""; } String value = a.getValue(); if(value==null) continue; // broken DOM. skip to be safe if(declaredPrefixes.add(prefix)) { serializer.addInscopeBinding(value,prefix); } } } }
Example 7
Source File: AnyTypeBeanInfo.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void serializeAttributes(Object element, XMLSerializer target) throws SAXException { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); // work defensively String uri = a.getNamespaceURI(); if(uri==null) uri=""; String local = a.getLocalName(); String name = a.getName(); if(local==null) local = name; if (uri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE) && ("nil".equals(local))) { isNilIncluded = true; } if(name.startsWith("xmlns")) continue;// DOM reports ns decls as attributes target.attribute(uri,local,a.getValue()); } }
Example 8
Source File: PolicyConstants.java From cxf with Apache License 2.0 | 5 votes |
public static Attr findIgnorableAttribute(Element e) { NamedNodeMap atts = e.getAttributes(); for (int x = 0; x < atts.getLength(); x++) { Attr att = (Attr)atts.item(x); QName qn = new QName(att.getNamespaceURI(), att.getLocalName()); if (Constants.isIgnorableAttribute(qn)) { return att; } } return null; }
Example 9
Source File: PolicyConstants.java From cxf with Apache License 2.0 | 5 votes |
public static Attr findOptionalAttribute(Element e) { NamedNodeMap atts = e.getAttributes(); for (int x = 0; x < atts.getLength(); x++) { Attr att = (Attr)atts.item(x); QName qn = new QName(att.getNamespaceURI(), att.getLocalName()); if (Constants.isOptionalAttribute(qn)) { return att; } } return null; }
Example 10
Source File: NodeUtils.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
static Node duplicateNode(Document document, Node node) { Node newNode; if (node.getNamespaceURI() != null) { newNode = document.createElementNS(node.getNamespaceURI(), node.getLocalName()); } else { newNode = document.createElement(node.getNodeName()); } // copy the attributes NamedNodeMap attributes = node.getAttributes(); for (int i = 0 ; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); Attr newAttr; if (attr.getNamespaceURI() != null) { newAttr = document.createAttributeNS(attr.getNamespaceURI(), attr.getLocalName()); newNode.getAttributes().setNamedItemNS(newAttr); } else { newAttr = document.createAttribute(attr.getName()); newNode.getAttributes().setNamedItem(newAttr); } newAttr.setValue(attr.getValue()); } // then duplicate the sub-nodes. NodeList children = node.getChildNodes(); for (int i = 0 ; i < children.getLength() ; i++) { Node child = children.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } Node duplicatedChild = duplicateNode(document, child); newNode.appendChild(duplicatedChild); } return newNode; }
Example 11
Source File: UnusedResourceDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) { String value = attribute.getValue(); if (value.startsWith("@+") && !value.startsWith("@+android")) { //$NON-NLS-1$ //$NON-NLS-2$ String resource = R_PREFIX + value.substring(2).replace('/', '.'); // We already have the declarations when we scan the R file, but we're tracking // these here to get attributes for position info if (context.getPhase() == 1) { mDeclarations.add(resource); } else if (mUnused.containsKey(resource)) { if (context.getDriver().isSuppressed(context, getIssue(resource), attribute)) { mUnused.remove(resource); return; } if (!context.getProject().getReportIssues()) { mUnused.remove(resource); return; } recordLocation(resource, context.getLocation(attribute)); return; } } else if (mReferences != null) { if (value.startsWith("@") //$NON-NLS-1$ && !value.startsWith("@android:")) { //$NON-NLS-1$ // Compute R-string, e.g. @string/foo => R.string.foo String r = R_PREFIX + value.substring(1).replace('/', '.'); mReferences.add(r); } else if (value.startsWith(ATTR_REF_PREFIX)) { mReferences.add(R_ATTR_PREFIX + value.substring(ATTR_REF_PREFIX.length())); } } if (attribute.getNamespaceURI() != null && !ANDROID_URI.equals(attribute.getNamespaceURI()) && mReferences != null) { mReferences.add(R_ATTR_PREFIX + attribute.getLocalName()); } }
Example 12
Source File: XSDocumentInfo.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Initialize namespace support by collecting all of the namespace * declarations in the root's ancestors. This is necessary to * support schemas fragments, i.e. schemas embedded in other * documents. See, * * https://jaxp.dev.java.net/issues/show_bug.cgi?id=43 * * Requires the DOM to be created with namespace support enabled. */ private void initNamespaceSupport(Element schemaRoot) { fNamespaceSupport = new SchemaNamespaceSupport(); fNamespaceSupport.reset(); Node parent = schemaRoot.getParentNode(); while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE && !parent.getNodeName().equals("DOCUMENT_NODE")) { Element eparent = (Element) parent; NamedNodeMap map = eparent.getAttributes(); int length = (map != null) ? map.getLength() : 0; for (int i = 0; i < length; i++) { Attr attr = (Attr) map.item(i); String uri = attr.getNamespaceURI(); // Check if attribute is an ns decl -- requires ns support if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) { String prefix = attr.getLocalName().intern(); if (prefix == "xmlns") prefix = ""; // Declare prefix if not set -- moving upwards if (fNamespaceSupport.getURI(prefix) == null) { fNamespaceSupport.declarePrefix(prefix, attr.getValue().intern()); } } } parent = parent.getParentNode(); } }
Example 13
Source File: AttrCompare.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Compares two attributes based on the C14n specification. * * <UL> * <LI>Namespace nodes have a lesser document order position than * attribute nodes. * <LI> An element's namespace nodes are sorted lexicographically by * local name (the default namespace node, if one exists, has no * local name and is therefore lexicographically least). * <LI> An element's attribute nodes are sorted lexicographically with * namespace URI as the primary key and local name as the secondary * key (an empty namespace URI is lexicographically least). * </UL> * * @param attr0 * @param attr1 * @return returns a negative integer, zero, or a positive integer as * obj0 is less than, equal to, or greater than obj1 * */ public int compare(Attr attr0, Attr attr1) { String namespaceURI0 = attr0.getNamespaceURI(); String namespaceURI1 = attr1.getNamespaceURI(); boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0); boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1); if (isNamespaceAttr0) { if (isNamespaceAttr1) { // both are namespaces String localname0 = attr0.getLocalName(); String localname1 = attr1.getLocalName(); if ("xmlns".equals(localname0)) { localname0 = ""; } if ("xmlns".equals(localname1)) { localname1 = ""; } return localname0.compareTo(localname1); } // attr0 is a namespace, attr1 is not return ATTR0_BEFORE_ATTR1; } else if (isNamespaceAttr1) { // attr1 is a namespace, attr0 is not return ATTR1_BEFORE_ATTR0; } // none is a namespace if (namespaceURI0 == null) { if (namespaceURI1 == null) { String name0 = attr0.getName(); String name1 = attr1.getName(); return name0.compareTo(name1); } return ATTR0_BEFORE_ATTR1; } else if (namespaceURI1 == null) { return ATTR1_BEFORE_ATTR0; } int a = namespaceURI0.compareTo(namespaceURI1); if (a != 0) { return a; } return (attr0.getLocalName()).compareTo(attr1.getLocalName()); }
Example 14
Source File: Canonicalizer20010315.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns the Attr[]s to be output for the given element. * <br> * The code of this method is a copy of {@link #handleAttributes(Element, * NameSpaceSymbTable)}, * whereas it takes into account that subtree-c14n is -- well -- subtree-based. * So if the element in question isRoot of c14n, it's parent is not in the * node set, as well as all other ancestors. * * @param element * @param ns * @return the Attr[]s to be output * @throws CanonicalizationException */ @Override protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns) throws CanonicalizationException { if (!element.hasAttributes() && !firstCall) { return null; } // result will contain the attrs which have to be output final SortedSet<Attr> result = this.result; result.clear(); if (element.hasAttributes()) { NamedNodeMap attrs = element.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NUri = attribute.getNamespaceURI(); String NName = attribute.getLocalName(); String NValue = attribute.getValue(); if (!XMLNS_URI.equals(NUri)) { //It's not a namespace attr node. Add to the result and continue. result.add(attribute); } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) { //The default mapping for xml must not be output. Node n = ns.addMappingAndRender(NName, NValue, attribute); if (n != null) { //Render the ns definition result.add((Attr)n); if (C14nHelper.namespaceIsRelative(attribute)) { Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() }; throw new CanonicalizationException( "c14n.Canonicalizer.RelativeNamespace", exArgs ); } } } } } if (firstCall) { //It is the first node of the subtree //Obtain all the namespaces defined in the parents, and added to the output. ns.getUnrenderedNodes(result); //output the attributes in the xml namespace. xmlattrStack.getXmlnsAttr(result); firstCall = false; } return result.iterator(); }
Example 15
Source File: XmlUtil.java From HtmlUnit-Android with Apache License 2.0 | 4 votes |
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) { if (source.getNodeType() == Node.TEXT_NODE) { return new DomText(page, source.getNodeValue()); } if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue()); } if (source.getNodeType() == Node.COMMENT_NODE) { return new DomComment(page, source.getNodeValue()); } if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) { final DocumentType documentType = (DocumentType) source; return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId()); } final String ns = source.getNamespaceURI(); String localName = source.getLocalName(); if (handleXHTMLAsHTML && HTMLParser.XHTML_NAMESPACE.equals(ns)) { final ElementFactory factory = HTMLParser.getFactory(localName); return factory.createElementNS(page, ns, localName, namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source)); } final NamedNodeMap nodeAttributes = source.getAttributes(); if (page != null && page.isHtmlPage()) { localName = localName.toUpperCase(Locale.ROOT); } final String qualifiedName; if (source.getPrefix() == null) { qualifiedName = localName; } else { qualifiedName = source.getPrefix() + ':' + localName; } final String namespaceURI = source.getNamespaceURI(); if (HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) { return HTMLParser.SVG_FACTORY.createElementNS(page, namespaceURI, qualifiedName, namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source)); } final Map<String, DomAttr> attributes = new LinkedHashMap<>(); for (int i = 0; i < nodeAttributes.getLength(); i++) { final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i); final Attr attribute = (Attr) nodeAttributes.item(orderedIndex); final String attributeNamespaceURI = attribute.getNamespaceURI(); final String attributeQualifiedName; if (attribute.getPrefix() != null) { attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName(); } else { attributeQualifiedName = attribute.getLocalName(); } final String value = attribute.getNodeValue(); final boolean specified = attribute.getSpecified(); final DomAttr xmlAttribute = new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified); attributes.put(attribute.getNodeName(), xmlAttribute); } return new DomElement(namespaceURI, qualifiedName, page, attributes); }
Example 16
Source File: XmlUtils.java From htmlunit with Apache License 2.0 | 4 votes |
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) { if (source.getNodeType() == Node.TEXT_NODE) { return new DomText(page, source.getNodeValue()); } if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue()); } if (source.getNodeType() == Node.COMMENT_NODE) { return new DomComment(page, source.getNodeValue()); } if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) { final DocumentType documentType = (DocumentType) source; return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId()); } final String ns = source.getNamespaceURI(); String localName = source.getLocalName(); if (handleXHTMLAsHTML && Html.XHTML_NAMESPACE.equals(ns)) { final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(localName); return factory.createElementNS(page, ns, localName, namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source)); } final NamedNodeMap nodeAttributes = source.getAttributes(); if (page != null && page.isHtmlPage()) { localName = localName.toUpperCase(Locale.ROOT); } final String qualifiedName; if (source.getPrefix() == null) { qualifiedName = localName; } else { qualifiedName = source.getPrefix() + ':' + localName; } final String namespaceURI = source.getNamespaceURI(); if (Html.SVG_NAMESPACE.equals(namespaceURI)) { return page.getWebClient().getPageCreator().getHtmlParser().getSvgFactory() .createElementNS(page, namespaceURI, qualifiedName, namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source)); } final Map<String, DomAttr> attributes = new LinkedHashMap<>(); for (int i = 0; i < nodeAttributes.getLength(); i++) { final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i); final Attr attribute = (Attr) nodeAttributes.item(orderedIndex); final String attributeNamespaceURI = attribute.getNamespaceURI(); final String attributeQualifiedName; if (attribute.getPrefix() != null) { attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName(); } else { attributeQualifiedName = attribute.getLocalName(); } final String value = attribute.getNodeValue(); final boolean specified = attribute.getSpecified(); final DomAttr xmlAttribute = new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified); attributes.put(attribute.getNodeName(), xmlAttribute); } return new DomElement(namespaceURI, qualifiedName, page, attributes); }
Example 17
Source File: AttrCompare.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Compares two attributes based on the C14n specification. * * <UL> * <LI>Namespace nodes have a lesser document order position than * attribute nodes. * <LI> An element's namespace nodes are sorted lexicographically by * local name (the default namespace node, if one exists, has no * local name and is therefore lexicographically least). * <LI> An element's attribute nodes are sorted lexicographically with * namespace URI as the primary key and local name as the secondary * key (an empty namespace URI is lexicographically least). * </UL> * * @param attr0 * @param attr1 * @return returns a negative integer, zero, or a positive integer as * obj0 is less than, equal to, or greater than obj1 * */ public int compare(Attr attr0, Attr attr1) { String namespaceURI0 = attr0.getNamespaceURI(); String namespaceURI1 = attr1.getNamespaceURI(); boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0); boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1); if (isNamespaceAttr0) { if (isNamespaceAttr1) { // both are namespaces String localname0 = attr0.getLocalName(); String localname1 = attr1.getLocalName(); if ("xmlns".equals(localname0)) { localname0 = ""; } if ("xmlns".equals(localname1)) { localname1 = ""; } return localname0.compareTo(localname1); } // attr0 is a namespace, attr1 is not return ATTR0_BEFORE_ATTR1; } else if (isNamespaceAttr1) { // attr1 is a namespace, attr0 is not return ATTR1_BEFORE_ATTR0; } // none is a namespace if (namespaceURI0 == null) { if (namespaceURI1 == null) { String name0 = attr0.getName(); String name1 = attr1.getName(); return name0.compareTo(name1); } return ATTR0_BEFORE_ATTR1; } else if (namespaceURI1 == null) { return ATTR1_BEFORE_ATTR0; } int a = namespaceURI0.compareTo(namespaceURI1); if (a != 0) { return a; } return (attr0.getLocalName()).compareTo(attr1.getLocalName()); }
Example 18
Source File: Canonicalizer20010315.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Returns the Attr[]s to be output for the given element. * <br> * The code of this method is a copy of {@link #handleAttributes(Element, * NameSpaceSymbTable)}, * whereas it takes into account that subtree-c14n is -- well -- subtree-based. * So if the element in question isRoot of c14n, it's parent is not in the * node set, as well as all other ancestors. * * @param element * @param ns * @return the Attr[]s to be output * @throws CanonicalizationException */ @Override protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns) throws CanonicalizationException { if (!element.hasAttributes() && !firstCall) { return null; } // result will contain the attrs which have to be output final SortedSet<Attr> result = this.result; result.clear(); if (element.hasAttributes()) { NamedNodeMap attrs = element.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NUri = attribute.getNamespaceURI(); String NName = attribute.getLocalName(); String NValue = attribute.getValue(); if (!XMLNS_URI.equals(NUri)) { //It's not a namespace attr node. Add to the result and continue. result.add(attribute); } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) { //The default mapping for xml must not be output. Node n = ns.addMappingAndRender(NName, NValue, attribute); if (n != null) { //Render the ns definition result.add((Attr)n); if (C14nHelper.namespaceIsRelative(attribute)) { Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() }; throw new CanonicalizationException( "c14n.Canonicalizer.RelativeNamespace", exArgs ); } } } } } if (firstCall) { //It is the first node of the subtree //Obtain all the namespaces defined in the parents, and added to the output. ns.getUnrenderedNodes(result); //output the attributes in the xml namespace. xmlattrStack.getXmlnsAttr(result); firstCall = false; } return result.iterator(); }
Example 19
Source File: NettyHttpServerEngineBeanDefinitionParser.java From cxf with Apache License 2.0 | 4 votes |
private void mapTLSServerParameters(Element e, BeanDefinitionBuilder bean) { BeanDefinitionBuilder paramsbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.TLSServerParametersTypeInternal.class); // read the attributes NamedNodeMap as = e.getAttributes(); for (int i = 0; i < as.getLength(); i++) { Attr a = (Attr) as.item(i); if (a.getNamespaceURI() == null) { String aname = a.getLocalName(); if ("jsseProvider".equals(aname) || "secureSocketProtocol".equals(aname)) { paramsbean.addPropertyValue(aname, a.getValue()); } } } // read the child elements Node n = e.getFirstChild(); while (n != null) { if (Node.ELEMENT_NODE != n.getNodeType() || !SECURITY_NS.equals(n.getNamespaceURI())) { n = n.getNextSibling(); continue; } String ename = n.getLocalName(); // Schema should require that no more than one each of these exist. String ref = ((Element)n).getAttribute("ref"); if ("keyManagers".equals(ename)) { if (ref != null && ref.length() > 0) { paramsbean.addPropertyReference("keyManagersRef", ref); } else { mapElementToJaxbProperty((Element)n, paramsbean, ename, KeyManagersType.class); } } else if ("trustManagers".equals(ename)) { if (ref != null && ref.length() > 0) { paramsbean.addPropertyReference("trustManagersRef", ref); } else { mapElementToJaxbProperty((Element)n, paramsbean, ename, TrustManagersType.class); } } else if ("cipherSuites".equals(ename)) { mapElementToJaxbProperty((Element)n, paramsbean, ename, CipherSuites.class); } else if ("cipherSuitesFilter".equals(ename)) { mapElementToJaxbProperty((Element)n, paramsbean, ename, FiltersType.class); } else if ("secureRandomParameters".equals(ename)) { mapElementToJaxbProperty((Element)n, paramsbean, ename, SecureRandomParameters.class); } else if ("clientAuthentication".equals(ename)) { mapElementToJaxbProperty((Element)n, paramsbean, ename, ClientAuthentication.class); } else if ("certConstraints".equals(ename)) { mapElementToJaxbProperty((Element)n, paramsbean, ename, CertificateConstraintsType.class); } else if ("certAlias".equals(ename)) { paramsbean.addPropertyValue(ename, n.getTextContent()); } n = n.getNextSibling(); } BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.class); jaxbbean.addConstructorArgValue(paramsbean.getBeanDefinition()); bean.addPropertyValue("tlsServerParameters", jaxbbean.getBeanDefinition()); }
Example 20
Source File: Canonicalizer11.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns the Attr[]s to be output for the given element. * <br> * The code of this method is a copy of {@link #handleAttributes(Element, * NameSpaceSymbTable)}, * whereas it takes into account that subtree-c14n is -- well -- * subtree-based. * So if the element in question isRoot of c14n, it's parent is not in the * node set, as well as all other ancestors. * * @param element * @param ns * @return the Attr[]s to be output * @throws CanonicalizationException */ @Override protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns) throws CanonicalizationException { if (!element.hasAttributes() && !firstCall) { return null; } // result will contain the attrs which have to be output final SortedSet<Attr> result = this.result; result.clear(); if (element.hasAttributes()) { NamedNodeMap attrs = element.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NUri = attribute.getNamespaceURI(); String NName = attribute.getLocalName(); String NValue = attribute.getValue(); if (!XMLNS_URI.equals(NUri)) { // It's not a namespace attr node. Add to the result and continue. result.add(attribute); } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) { // The default mapping for xml must not be output. Node n = ns.addMappingAndRender(NName, NValue, attribute); if (n != null) { // Render the ns definition result.add((Attr)n); if (C14nHelper.namespaceIsRelative(attribute)) { Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()}; throw new CanonicalizationException( "c14n.Canonicalizer.RelativeNamespace", exArgs ); } } } } } if (firstCall) { // It is the first node of the subtree // Obtain all the namespaces defined in the parents, and added to the output. ns.getUnrenderedNodes(result); // output the attributes in the xml namespace. xmlattrStack.getXmlnsAttr(result); firstCall = false; } return result.iterator(); }