Java Code Examples for org.w3c.dom.Element#setIdAttribute()
The following examples show how to use
org.w3c.dom.Element#setIdAttribute() .
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: DSSXMLUtils.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
/** * If this method finds an attribute with names ID (case-insensitive) then declares it to be a user-determined ID * attribute. * * @param childElement */ public static void setIDIdentifier(final Element childElement) { final NamedNodeMap attributes = childElement.getAttributes(); for (int jj = 0; jj < attributes.getLength(); jj++) { final Node item = attributes.item(jj); final String localName = item.getLocalName(); final String nodeName = item.getNodeName(); if (localName != null) { if (Utils.areStringsEqualIgnoreCase(XMLDSigAttribute.ID.getAttributeName(), localName)) { childElement.setIdAttribute(nodeName, true); break; } } } }
Example 2
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private boolean hasAttribute(Element el, String attrValue) { NamedNodeMap attrMap = el.getAttributes(); for(int i = 0; i < attrMap.getLength(); ++i) { Node item = attrMap.item(i); if (item.getTextContent().equalsIgnoreCase(attrValue)) { el.setIdAttribute(item.getLocalName(), true); return true; } } NodeList childs = el.getChildNodes(); for(int i = 0; i < childs.getLength(); ++i) { Node child = childs.item(i); if (child.getNodeType() == 1 && this.hasAttribute((Element)childs.item(i), attrValue)) { return true; } } return false; }
Example 3
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private boolean hasAttribute(Element el, String attrValue) { NamedNodeMap attrMap = el.getAttributes(); for(int i = 0; i < attrMap.getLength(); ++i) { Node item = attrMap.item(i); if (item.getTextContent().equalsIgnoreCase(attrValue)) { el.setIdAttribute(item.getLocalName(), true); return true; } } NodeList childs = el.getChildNodes(); for(int i = 0; i < childs.getLength(); ++i) { Node child = childs.item(i); if (child.getNodeType() == 1 && this.hasAttribute((Element)childs.item(i), attrValue)) { return true; } } return false; }
Example 4
Source File: STSServiceImpl.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private void signRequest(Element requestElement, PrivateKey privateKey, Object keyInfoValue) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException, KeyException { DOMSignContext domSignContext = new DOMSignContext(privateKey, requestElement, requestElement.getFirstChild()); String requestId = requestElement.getAttribute("RequestID"); requestElement.setIdAttribute("RequestID", true); List<Transform> transforms = new LinkedList(); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature", (TransformParameterSpec)null)); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null)); Reference reference = xmlSignatureFactory.newReference("#" + requestId, xmlSignatureFactory.newDigestMethod("http://www.w3.org/2000/09/xmldsig#sha1", (DigestMethodParameterSpec)null), transforms, (String)null, (String)null); CanonicalizationMethod canonicalizationMethod = xmlSignatureFactory.newCanonicalizationMethod("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null); SignatureMethod signatureMethod = xmlSignatureFactory.newSignatureMethod("http://www.w3.org/2000/09/xmldsig#rsa-sha1", (SignatureMethodParameterSpec)null); SignedInfo signedInfo = xmlSignatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod, Collections.singletonList(reference)); KeyInfoFactory keyInfoFactory = xmlSignatureFactory.getKeyInfoFactory(); KeyInfo keyInfo = null; if (keyInfoValue instanceof PublicKey) { keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newKeyValue((PublicKey)keyInfoValue))); } else { if (!(keyInfoValue instanceof X509Certificate)) { throw new IllegalArgumentException("Unsupported keyinfo type [" + keyInfoValue.getClass() + "]"); } keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newX509Data(Collections.singletonList(keyInfoValue)))); } XMLSignature xmlSignature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); xmlSignature.sign(domSignContext); }
Example 5
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private boolean hasAttribute(Element el, String attrValue) { NamedNodeMap attrMap = el.getAttributes(); for(int i = 0; i < attrMap.getLength(); ++i) { Node item = attrMap.item(i); if (item.getTextContent().equalsIgnoreCase(attrValue)) { el.setIdAttribute(item.getLocalName(), true); return true; } } NodeList childs = el.getChildNodes(); for(int i = 0; i < childs.getLength(); ++i) { Node child = childs.item(i); if (child.getNodeType() == 1 && this.hasAttribute((Element)childs.item(i), attrValue)) { return true; } } return false; }
Example 6
Source File: STSServiceImpl.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private void signRequest(Element requestElement, PrivateKey privateKey, Object keyInfoValue) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException, KeyException { DOMSignContext domSignContext = new DOMSignContext(privateKey, requestElement, requestElement.getFirstChild()); String requestId = requestElement.getAttribute("RequestID"); requestElement.setIdAttribute("RequestID", true); List<Transform> transforms = new LinkedList(); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature", (TransformParameterSpec)null)); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null)); Reference reference = xmlSignatureFactory.newReference("#" + requestId, xmlSignatureFactory.newDigestMethod("http://www.w3.org/2000/09/xmldsig#sha1", (DigestMethodParameterSpec)null), transforms, (String)null, (String)null); CanonicalizationMethod canonicalizationMethod = xmlSignatureFactory.newCanonicalizationMethod("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null); SignatureMethod signatureMethod = xmlSignatureFactory.newSignatureMethod("http://www.w3.org/2000/09/xmldsig#rsa-sha1", (SignatureMethodParameterSpec)null); SignedInfo signedInfo = xmlSignatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod, Collections.singletonList(reference)); KeyInfoFactory keyInfoFactory = xmlSignatureFactory.getKeyInfoFactory(); KeyInfo keyInfo = null; if (keyInfoValue instanceof PublicKey) { keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newKeyValue((PublicKey)keyInfoValue))); } else { if (!(keyInfoValue instanceof X509Certificate)) { throw new IllegalArgumentException("Unsupported keyinfo type [" + keyInfoValue.getClass() + "]"); } keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newX509Data(Collections.singletonList(keyInfoValue)))); } XMLSignature xmlSignature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); xmlSignature.sign(domSignContext); }
Example 7
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private boolean hasAttribute(Element el, String attrValue) { NamedNodeMap attrMap = el.getAttributes(); for(int i = 0; i < attrMap.getLength(); ++i) { Node item = attrMap.item(i); if (item.getTextContent().equalsIgnoreCase(attrValue)) { el.setIdAttribute(item.getLocalName(), true); return true; } } NodeList childs = el.getChildNodes(); for(int i = 0; i < childs.getLength(); ++i) { Node child = childs.item(i); if (child.getNodeType() == 1 && this.hasAttribute((Element)childs.item(i), attrValue)) { return true; } } return false; }
Example 8
Source File: STSServiceImpl.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private void signRequest(Element requestElement, PrivateKey privateKey, Object keyInfoValue) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException, KeyException { DOMSignContext domSignContext = new DOMSignContext(privateKey, requestElement, requestElement.getFirstChild()); String requestId = requestElement.getAttribute("RequestID"); requestElement.setIdAttribute("RequestID", true); List<Transform> transforms = new LinkedList(); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature", (TransformParameterSpec)null)); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null)); Reference reference = xmlSignatureFactory.newReference("#" + requestId, xmlSignatureFactory.newDigestMethod("http://www.w3.org/2000/09/xmldsig#sha1", (DigestMethodParameterSpec)null), transforms, (String)null, (String)null); CanonicalizationMethod canonicalizationMethod = xmlSignatureFactory.newCanonicalizationMethod("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null); SignatureMethod signatureMethod = xmlSignatureFactory.newSignatureMethod("http://www.w3.org/2000/09/xmldsig#rsa-sha1", (SignatureMethodParameterSpec)null); SignedInfo signedInfo = xmlSignatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod, Collections.singletonList(reference)); KeyInfoFactory keyInfoFactory = xmlSignatureFactory.getKeyInfoFactory(); KeyInfo keyInfo = null; if (keyInfoValue instanceof PublicKey) { keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newKeyValue((PublicKey)keyInfoValue))); } else { if (!(keyInfoValue instanceof X509Certificate)) { throw new IllegalArgumentException("Unsupported keyinfo type [" + keyInfoValue.getClass() + "]"); } keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newX509Data(Collections.singletonList(keyInfoValue)))); } XMLSignature xmlSignature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); xmlSignature.sign(domSignContext); }
Example 9
Source File: STSServiceImpl.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private void signRequest(Element requestElement, PrivateKey privateKey, Object keyInfoValue) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException, KeyException { DOMSignContext domSignContext = new DOMSignContext(privateKey, requestElement, requestElement.getFirstChild()); String requestId = requestElement.getAttribute("RequestID"); requestElement.setIdAttribute("RequestID", true); List<Transform> transforms = new LinkedList(); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature", (TransformParameterSpec)null)); transforms.add(xmlSignatureFactory.newTransform("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null)); Reference reference = xmlSignatureFactory.newReference("#" + requestId, xmlSignatureFactory.newDigestMethod("http://www.w3.org/2000/09/xmldsig#sha1", (DigestMethodParameterSpec)null), transforms, (String)null, (String)null); CanonicalizationMethod canonicalizationMethod = xmlSignatureFactory.newCanonicalizationMethod("http://www.w3.org/2001/10/xml-exc-c14n#", (C14NMethodParameterSpec)null); SignatureMethod signatureMethod = xmlSignatureFactory.newSignatureMethod("http://www.w3.org/2000/09/xmldsig#rsa-sha1", (SignatureMethodParameterSpec)null); SignedInfo signedInfo = xmlSignatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod, Collections.singletonList(reference)); KeyInfoFactory keyInfoFactory = xmlSignatureFactory.getKeyInfoFactory(); KeyInfo keyInfo = null; if (keyInfoValue instanceof PublicKey) { keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newKeyValue((PublicKey)keyInfoValue))); } else { if (!(keyInfoValue instanceof X509Certificate)) { throw new IllegalArgumentException("Unsupported keyinfo type [" + keyInfoValue.getClass() + "]"); } keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyInfoFactory.newX509Data(Collections.singletonList(keyInfoValue)))); } XMLSignature xmlSignature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); xmlSignature.sign(domSignContext); }
Example 10
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private boolean hasAttribute(Element el, String attrValue) { NamedNodeMap attrMap = el.getAttributes(); for(int i = 0; i < attrMap.getLength(); ++i) { Node item = attrMap.item(i); if (item.getTextContent().equalsIgnoreCase(attrValue)) { el.setIdAttribute(item.getLocalName(), true); return true; } } NodeList childs = el.getChildNodes(); for(int i = 0; i < childs.getLength(); ++i) { Node child = childs.item(i); if (child.getNodeType() == 1 && this.hasAttribute((Element)childs.item(i), attrValue)) { return true; } } return false; }
Example 11
Source File: XMLSignatureUtil.java From keycloak with Apache License 2.0 | 5 votes |
/** * Setup the ID attribute into <code>destElement</code> depending on the <code>isId</code> flag of an attribute of * <code>sourceNode</code>. * * @param sourceNode */ public static void propagateIDAttributeSetup(Node sourceNode, Element destElement) { NamedNodeMap nnm = sourceNode.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Attr attr = (Attr) nnm.item(i); if (attr.isId()) { destElement.setIdAttribute(attr.getName(), true); break; } } }
Example 12
Source File: AnchorHandler.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token) throws SnuggleParseException { /* Make sure anchor is a proper XML name */ ArgumentContainerToken anchorToken = token.getArguments()[0]; String rawAnchorId = builder.extractStringValue(anchorToken); String validatedId = builder.validateXMLId(parentElement, anchorToken, rawAnchorId); if (validatedId!=null) { /* Create <a/> element */ Element aElement = builder.appendXHTMLElement(parentElement, "a"); aElement.setAttribute("id", validatedId); aElement.setAttribute("name", validatedId); aElement.setIdAttribute("id", true); } }
Example 13
Source File: AssertionConsumerService.java From development with Apache License 2.0 | 5 votes |
private void validateDigitalSignature(Element assertion) throws DigitalSignatureValidationException { assertion.setIdAttribute("ID", true); Node signature = retrieveSignature(assertion); KeyStore keystore = loadIdpKeystore(); DigitalSignatureValidator validator = new DigitalSignatureValidator( keystore); boolean validity = validator.validate(signature); if (!validity) { DigitalSignatureValidationException exception = new DigitalSignatureValidationException( "Signature is not valid", DigitalSignatureValidationException.ReasonEnum.NOT_VALID); throw exception; } }
Example 14
Source File: SAX2DOM.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }
Example 15
Source File: SAX2DOM.java From hottub with GNU General Public License v2.0 | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }
Example 16
Source File: SAX2DOM.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }
Example 17
Source File: SAX2DOM.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }
Example 18
Source File: SAX2DOM.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }
Example 19
Source File: SAX2DOM.java From JDKSourceCode1.8 with MIT License | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }
Example 20
Source File: SAX2DOM.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void startElement(String namespace, String localName, String qName, Attributes attrs) { appendTextNode(); if (needToSetDocumentInfo) { setDocumentInfo(); needToSetDocumentInfo = false; } final Element tmp = (Element)_document.createElementNS(namespace, qName); // Add namespace declarations first if (_namespaceDecls != null) { final int nDecls = _namespaceDecls.size(); for (int i = 0; i < nDecls; i++) { final String prefix = (String) _namespaceDecls.elementAt(i++); if (prefix == null || prefix.equals(EMPTYSTRING)) { tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); } else { tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); } } _namespaceDecls.clear(); } // Add attributes to element /* final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); } else { tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); } } */ // Add attributes to element final int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { // checking if Namespace processing is being done String attQName = attrs.getQName(i); String attURI = attrs.getURI(i); if (attrs.getLocalName(i).equals("")) { tmp.setAttribute(attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttribute(attQName, true); } } else { tmp.setAttributeNS(attURI, attQName, attrs.getValue(i)); if (attrs.getType(i).equals("ID")) { tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true); } } } // Append this new node onto current stack node Node last = (Node)_nodeStk.peek(); // If the SAX2DOM is created with a non-null next sibling node, // insert the result nodes before the next sibling under the root. if (last == _root && _nextSibling != null) last.insertBefore(tmp, _nextSibling); else last.appendChild(tmp); // Push this node onto stack _nodeStk.push(tmp); _lastSibling = null; }