List of usage examples for org.w3c.dom Node getPrefix
public String getPrefix();
null
if it is unspecified. From source file:eu.semaine.util.XMLTool.java
/** * Create a child element with the given name and append it below node. * The new element will have the same namespace as node. * If node has a namespace prefix, the new element will also use that namespace prefix. * @param node/*from ww w . ja v a 2s . c o m*/ * @param childName * @return the child element */ public static Element appendChildElement(Node node, String childName) { if (node == null) throw new NullPointerException("Received null node"); if (childName == null) throw new NullPointerException("Received null childName"); Element child = (Element) node .appendChild(createElement(node.getOwnerDocument(), childName, node.getNamespaceURI())); String parentPrefix = node.getPrefix(); if (parentPrefix != null) { child.setPrefix(parentPrefix); } return child; }
From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java
private void appendCertificate(Node keyInfo, String certificate) { String prefix = keyInfo.getPrefix(); if (replaceAll == true) { keyInfo.setTextContent(""); if (prefix == null) { prefix = ""; } else {/*from w ww.jav a 2 s . com*/ prefix = prefix + ":"; } Node data = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Data"); keyInfo.appendChild(data); Node cert = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Certificate"); data.appendChild(cert); cert.setTextContent(certificate); } else { List<Element> l = DomUtilities.findChildren(keyInfo, "X509Certificate", NamespaceConstants.URI_NS_DS, true); Node cert = l.get(0); cert.setTextContent(certificate); } Logging.getInstance().log(getClass(), "Appending Certificate \r\n" + certificate + "\r\nto the" + prefix + "X509Certificate element", Logging.DEBUG); }
From source file:ca.mcgill.music.ddmal.mei.MeiXmlReader.java
private MeiElement makeMeiElement(Node element) { // TODO: CDATA // Comments get a name #comment String nshref = element.getNamespaceURI(); String nsprefix = element.getPrefix(); MeiNamespace elns = new MeiNamespace(nshref, nsprefix); MeiElement e = new MeiElement(elns, element.getNodeName()); if (element.getNodeType() == Node.COMMENT_NODE) { e.setValue(element.getNodeValue()); }/*from www . ja v a 2 s . c o m*/ NamedNodeMap attributes = element.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (XML_ID_ATTRIBUTE.equals(item.getNodeName())) { e.setId(item.getNodeValue()); } else { String attrns = item.getNamespaceURI(); String attrpre = item.getPrefix(); MeiNamespace atns = new MeiNamespace(attrns, attrpre); MeiAttribute a = new MeiAttribute(atns, item.getNodeName(), item.getNodeValue()); e.addAttribute(a); } } } NodeList childNodes = element.getChildNodes(); MeiElement lastElement = null; for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (item.getNodeType() == Node.TEXT_NODE) { if (lastElement == null) { e.setValue(item.getNodeValue()); } else { lastElement.setTail(item.getNodeValue()); } } else { MeiElement child = makeMeiElement(item); e.addChild(child); lastElement = child; } } return e; }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
@SuppressWarnings("unchecked") protected SOAPElement createXteeMessageStructure(SOAPMessage requestMessage, SOAPMessage responseMessage) throws Exception { SOAPUtil.addBaseMimeHeaders(responseMessage); SOAPUtil.addBaseNamespaces(responseMessage); if (!metaService) { // Assign xroad namespaces according to request List<String> xteeNamespaces = new ArrayList<String>(); xteeNamespaces.add(version.getNamespaceUri()); if (XRoadProtocolVersion.V4_0 == version) { xteeNamespaces.add(XTeeWsdlDefinition.XROAD_IDEN_NAMESPACE); }//from w w w .j a v a 2s. c o m Iterator<String> prefixes = requestMessage.getSOAPPart().getEnvelope().getNamespacePrefixes(); while (prefixes.hasNext()) { String nsPrefix = (String) prefixes.next(); String nsURI = requestMessage.getSOAPPart().getEnvelope().getNamespaceURI(nsPrefix).toLowerCase(); if (xteeNamespaces.contains(nsURI)) { SOAPUtil.addNamespace(responseMessage, nsPrefix, nsURI); } } // Copy headers from request NodeList reqHeaders = requestMessage.getSOAPHeader().getChildNodes(); for (int i = 0; i < reqHeaders.getLength(); i++) { Node reqHeader = reqHeaders.item(i); if (reqHeader.getNodeType() != Node.ELEMENT_NODE) { continue; } Node rspHeader = responseMessage.getSOAPPart().importNode(reqHeader, true); responseMessage.getSOAPHeader().appendChild(rspHeader); } } responseMessage.getSOAPPart().getEnvelope().setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); Node teenusElement = SOAPUtil.getFirstNonTextChild(requestMessage.getSOAPBody()); if (teenusElement.getPrefix() == null || teenusElement.getNamespaceURI() == null) { throw new IllegalStateException("Service request is missing namespace."); } SOAPUtil.addNamespace(responseMessage, teenusElement.getPrefix(), teenusElement.getNamespaceURI()); String teenusElementName = teenusElement.getLocalName(); if (teenusElementName.endsWith(SuffixBasedMessagesProvider.DEFAULT_REQUEST_SUFFIX)) { teenusElementName = teenusElementName.substring(0, teenusElementName.lastIndexOf(SuffixBasedMessagesProvider.DEFAULT_REQUEST_SUFFIX)); } teenusElementName += SuffixBasedMessagesProvider.DEFAULT_RESPONSE_SUFFIX; return responseMessage.getSOAPBody().addChildElement(teenusElementName, teenusElement.getPrefix(), teenusElement.getNamespaceURI()); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
private static void showDomNode(Node node, StringBuilder sb, int level) { if (sb == null) { // buffer not provided, return immediately return;/*from w ww. ja va2 s . c o m*/ } // indent for (int i = 0; i < level; i++) { sb.append(" "); } if (node == null) { sb.append("null\n"); } else { sb.append(node.getNodeName()); sb.append(" ("); NamedNodeMap attributes = node.getAttributes(); boolean broken = false; if (attributes != null) { for (int ii = 0; ii < attributes.getLength(); ii++) { Node attribute = attributes.item(ii); sb.append(attribute.getPrefix()); sb.append(":"); sb.append(attribute.getLocalName()); sb.append("='"); sb.append(attribute.getNodeValue()); sb.append("',"); if (attribute.getPrefix() == null && attribute.getLocalName().equals("xmlns") && (attribute.getNodeValue() == null || attribute.getNodeValue().isEmpty())) { broken = true; } } } sb.append(")"); if (broken) { sb.append(" *** WARNING: empty default namespace"); } sb.append("\n"); NodeList childNodes = node.getChildNodes(); for (int ii = 0; ii < childNodes.getLength(); ii++) { Node subnode = childNodes.item(ii); showDomNode(subnode, sb, level + 1); } } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static QName getQName(Node node) { if (node.getLocalName() == null) { if (node.getNodeName() == null) { return null; } else {/*from w ww . j ava 2 s. c o m*/ return new QName(null, node.getNodeName()); } } if (node.getPrefix() == null) { return new QName(node.getNamespaceURI(), node.getLocalName()); } return new QName(node.getNamespaceURI(), node.getLocalName(), node.getPrefix()); }
From source file:no.digipost.api.interceptors.Wss4jInterceptor.java
private boolean wasSigned(final Document doc, final List<WSSecurityEngineResult> results, final QName... qnamePath) { String path = "/" + doc.getDocumentElement().getPrefix() + ":Envelope"; for (QName qn : qnamePath) { Node n = doc.getDocumentElement().getElementsByTagNameNS(qn.getNamespaceURI(), qn.getLocalPart()) .item(0);//from w w w .j a va2 s .c o m if (n == null) { return false; } path += "/" + n.getPrefix() + ":" + n.getLocalName(); } for (WSSecurityEngineResult r : results) { if (r.containsKey("data-ref-uris")) { List<WSDataRef> refs = (List<WSDataRef>) r.get("data-ref-uris"); for (WSDataRef ref : refs) { if (ref.getName().equals(qnamePath[qnamePath.length - 1])) { if (ref.getXpath().equals(path)) { return true; } } } } } return false; }
From source file:com.gargoylesoftware.htmlunit.xml.XmlUtil.java
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML) { if (source.getNodeType() == Node.TEXT_NODE) { return new DomText(page, source.getNodeValue()); }//from www.ja va 2s. c om 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())); } 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)); } final Map<String, DomAttr> attributes = new LinkedHashMap<>(); for (int i = 0; i < nodeAttributes.getLength(); i++) { final Attr attribute = (Attr) nodeAttributes.item(i); 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); }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private SOAPElement addSoapElement(Context context, SOAPEnvelope se, SOAPElement soapParent, Node node) throws Exception { String prefix = node.getPrefix(); String namespace = node.getNamespaceURI(); String nodeName = node.getNodeName(); String localName = node.getLocalName(); String value = node.getNodeValue(); boolean includeResponseElement = true; if (context.sequenceName != null) { includeResponseElement = ((Sequence) context.requestedObject).isIncludeResponseElement(); }/*from w ww .j a v a 2s . c om*/ SOAPElement soapElement = null; if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; boolean toAdd = true; if (!includeResponseElement && "response".equalsIgnoreCase(localName)) { toAdd = false; } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(element.getParentNode().getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/".equals(namespace) || nodeName.toLowerCase().endsWith(":envelope") || nodeName.toLowerCase().endsWith(":body") //element.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || //nodeName.toUpperCase().indexOf("NS0:") != -1 ) { toAdd = false; } if (toAdd) { if (prefix == null || prefix.equals("")) { soapElement = soapParent.addChildElement(nodeName); } else { soapElement = soapParent.addChildElement(se.createName(localName, prefix, namespace)); } } else { soapElement = soapParent; } if (soapElement != null) { if (soapParent.equals(se.getBody()) && !soapParent.equals(soapElement)) { if (XsdForm.qualified == context.project.getSchemaElementForm()) { if (soapElement.getAttribute("xmlns") == null) { soapElement.addAttribute(se.createName("xmlns"), context.project.getTargetNamespace()); } } } if (element.hasAttributes()) { String attrType = element.getAttribute("type"); if (("attachment").equals(attrType)) { if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(element); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) soapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), element.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(element.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } if (!includeResponseElement && "response".equalsIgnoreCase(localName)) { // do not add attributes } else { NamedNodeMap attributes = element.getAttributes(); int len = attributes.getLength(); for (int i = 0; i < len; i++) { Node item = attributes.item(i); addSoapElement(context, se, soapElement, item); } } } if (element.hasChildNodes()) { NodeList childNodes = element.getChildNodes(); int len = childNodes.getLength(); for (int i = 0; i < len; i++) { Node item = childNodes.item(i); switch (item.getNodeType()) { case Node.ELEMENT_NODE: addSoapElement(context, se, soapElement, item); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String text = item.getNodeValue(); text = (text == null) ? "" : text; soapElement.addTextNode(text); break; default: break; } } } } } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { if (prefix == null || prefix.equals("")) { soapElement = soapParent.addAttribute(se.createName(nodeName), value); } else { soapElement = soapParent.addAttribute(se.createName(localName, prefix, namespace), value); } } return soapElement; }
From source file:com.marklogic.dom.NodeImpl.java
/** {@inheritDoc} */ public boolean isEqualNode(Node other) { // Note that normalization can affect equality; to avoid this, // nodes should be normalized before being compared. // For the moment, normalization cannot be done. if (other == null) return false; if (getNodeType() != other.getNodeType()) return false; if (!getLocalName().equals(other.getLocalName())) return false; if (notequals(getNamespaceURI(), other.getNamespaceURI())) return false; if (notequals(getPrefix(), other.getPrefix())) return false; if (notequals(getNodeValue(), other.getNodeValue())) return false; if (hasChildNodes() != other.hasChildNodes()) return false; if (hasAttributes() != other.hasAttributes()) return false; if (hasChildNodes()) { NamedNodeMap thisAttr = getAttributes(); NamedNodeMap otherAttr = other.getAttributes(); if (thisAttr.getLength() != otherAttr.getLength()) return false; for (int i = 0; i < thisAttr.getLength(); i++) if (thisAttr.item(i).isEqualNode(otherAttr.item(i))) return false; }/* ww w. ja va2 s .c o m*/ if (hasAttributes()) { NodeList thisChild = getChildNodes(); NodeList otherChild = other.getChildNodes(); if (thisChild.getLength() != otherChild.getLength()) return false; for (int i = 0; i < thisChild.getLength(); i++) if (thisChild.item(i).isEqualNode(otherChild.item(i))) return false; } return true; }