List of usage examples for org.w3c.dom Node getParentNode
public Node getParentNode();
From source file:org.apache.ode.bpel.runtime.AssignHelper.java
protected void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Assign.copy(" + ocopy + ")"); ScopeEvent se;/*from w w w. j a va 2 s . c om*/ // Check for message to message - copy, we can do this efficiently in // the database. if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef()) || (ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef())) { if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef()) && ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef()) { final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable()); final VariableInstance rval = _scopeFrame.resolve(((VariableRef) ocopy.from).getVariable()); Element lvalue = (Element) fetchVariableData(rval, false); initializeVariable(lval, lvalue); se = new VariableModificationEvent(lval.declaration.name); ((VariableModificationEvent) se).setNewValue(lvalue); } else { // This really should have been caught by the compiler. __log.fatal("Message/Non-Message Assignment, should be caught by compiler:" + ocopy); throw new FaultException(ocopy.getOwner().constants.qnSelectionFailure, "Message/Non-Message Assignment: " + ocopy); } } else { // Conventional Assignment logic. Node rvalue = evalRValue(ocopy.from); Node lvalue = evalLValue(ocopy.to); if (__log.isDebugEnabled()) { __log.debug("lvalue after eval " + lvalue); if (lvalue != null) __log.debug("content " + DOMUtils.domToString(lvalue)); } // Get a pointer within the lvalue. Node lvaluePtr = lvalue; boolean headerAssign = false; if (ocopy.to instanceof OAssign.DirectRef) { DirectRef dref = ((DirectRef) ocopy.to); Element el = DOMUtils.findChildByName((Element) lvalue, dref.elName); if (el == null) { el = (Element) ((Element) lvalue).appendChild(lvalue.getOwnerDocument() .createElementNS(dref.elName.getNamespaceURI(), dref.elName.getLocalPart())); } lvaluePtr = el; } else if (ocopy.to instanceof OAssign.VariableRef) { VariableRef varRef = ((VariableRef) ocopy.to); if (varRef.headerPart != null) headerAssign = true; lvaluePtr = evalQuery(lvalue, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, new EvaluationContextProxy(varRef.getVariable(), lvalue)); } else if (ocopy.to instanceof OAssign.PropertyRef) { PropertyRef propRef = ((PropertyRef) ocopy.to); lvaluePtr = evalQuery(lvalue, propRef.propertyAlias.part, propRef.propertyAlias.location, new EvaluationContextProxy(propRef.getVariable(), lvalue)); } else if (ocopy.to instanceof OAssign.LValueExpression) { LValueExpression lexpr = (LValueExpression) ocopy.to; lexpr.setInsertMissingToData(ocopy.insertMissingToData); lvaluePtr = evalQuery(lvalue, null, lexpr.expression, new EvaluationContextProxy(lexpr.getVariable(), lvalue)); if (__log.isDebugEnabled()) __log.debug("lvaluePtr expr res " + lvaluePtr); } // For partner link assignmenent, the whole content is assigned. if (ocopy.to instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = ((OAssign.PartnerLinkRef) ocopy.to); PartnerLinkInstance plval = _scopeFrame.resolve(pLinkRef.partnerLink); replaceEndpointRefence(plval, rvalue); se = new PartnerLinkModificationEvent(((OAssign.PartnerLinkRef) ocopy.to).partnerLink.getName()); } else { // Sneakily converting the EPR if it's not the format expected by the lvalue if (ocopy.from instanceof OAssign.PartnerLinkRef) { rvalue = getBpelRuntimeContext().convertEndpointReference((Element) rvalue, lvaluePtr); if (rvalue.getNodeType() == Node.DOCUMENT_NODE) rvalue = ((Document) rvalue).getDocumentElement(); } Node parentNode = lvaluePtr.getParentNode(); if (headerAssign && parentNode != null && "message".equals(parentNode.getNodeName()) && rvalue.getNodeType() == Node.ELEMENT_NODE) { lvalue = copyInto((Element) lvalue, (Element) lvaluePtr, (Element) rvalue); } else if (rvalue.getNodeType() == Node.ELEMENT_NODE && lvaluePtr.getNodeType() == Node.ELEMENT_NODE) { lvalue = replaceElement((Element) lvalue, (Element) lvaluePtr, (Element) rvalue, ocopy.keepSrcElementName); } else { lvalue = replaceContent(lvalue, lvaluePtr, rvalue.getTextContent()); } final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable()); if (__log.isDebugEnabled()) __log.debug("ASSIGN Writing variable '" + lval.declaration.name + "' value '" + DOMUtils.domToString(lvalue) + "'"); commitChanges(lval, lvalue); se = new VariableModificationEvent(lval.declaration.name); ((VariableModificationEvent) se).setNewValue(lvalue); } } if (ocopy.debugInfo != null) se.setLineNo(ocopy.debugInfo.startLine); sendEvent(se); }
From source file:org.apache.ode.bpel.runtime.AssignHelper.java
/** * isInsert flag desginates this as an 'element' type insertion, which * requires insert the actual element value, rather than it's children * * @return//from w w w.j av a2 s .c o m * @throws FaultException */ private Node replaceContent(Node lvalue, Node lvaluePtr, String rvalue) throws FaultException { Document d = lvaluePtr.getOwnerDocument(); if (__log.isDebugEnabled()) { __log.debug("lvaluePtr type " + lvaluePtr.getNodeType()); __log.debug("lvaluePtr " + DOMUtils.domToString(lvaluePtr)); __log.debug("lvalue " + lvalue); __log.debug("rvalue " + rvalue); } switch (lvaluePtr.getNodeType()) { case Node.ELEMENT_NODE: // Remove all the children. while (lvaluePtr.hasChildNodes()) lvaluePtr.removeChild(lvaluePtr.getFirstChild()); // Append a new text node. lvaluePtr.appendChild(d.createTextNode(rvalue)); // If lvalue is a text, removing all lvaluePtr children had just removed it // so we need to rebuild it as a child of lvaluePtr if (lvalue instanceof Text) lvalue = lvaluePtr.getFirstChild(); break; case Node.TEXT_NODE: Node newval = d.createTextNode(rvalue); // Replace ourselves . lvaluePtr.getParentNode().replaceChild(newval, lvaluePtr); // A little kludge, let our caller know that the root element has changed. // (used for assignment to a simple typed variable) if (lvalue.getNodeType() == Node.ELEMENT_NODE) { // No children, adding an empty text children to point to if (lvalue.getFirstChild() == null) { Text txt = lvalue.getOwnerDocument().createTextNode(""); lvalue.appendChild(txt); } if (lvalue.getFirstChild().getNodeType() == Node.TEXT_NODE) lvalue = lvalue.getFirstChild(); } if (lvalue.getNodeType() == Node.TEXT_NODE && ((Text) lvalue).getWholeText().equals(((Text) lvaluePtr).getWholeText())) lvalue = lvaluePtr = newval; break; case Node.ATTRIBUTE_NODE: ((Attr) lvaluePtr).setValue(rvalue); break; default: // This could occur if the expression language selects something // like // a PI or a CDATA. String msg = __msgs.msgInvalidLValue(); if (__log.isDebugEnabled()) __log.debug(lvaluePtr + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } return lvalue; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Given a prefix and a node, return the namespace URI that the prefix has * been associated with. This method is useful in resolving the namespace * URI of attribute values which are being interpreted as QNames. If prefix * is null, this method will return the default namespace. * * @param context the starting node (looks up recursively from here) * @param prefix the prefix to find an xmlns:prefix=uri for * * @return the namespace URI or null if not found *///from ww w .j a va2 s .c om public static String getNamespaceURIFromPrefix(Node context, String prefix) { short nodeType = context.getNodeType(); Node tempNode = null; switch (nodeType) { case Node.ATTRIBUTE_NODE: { tempNode = ((Attr) context).getOwnerElement(); break; } case Node.ELEMENT_NODE: { tempNode = context; break; } default: { tempNode = context.getParentNode(); break; } } while ((tempNode != null) && (tempNode.getNodeType() == Node.ELEMENT_NODE)) { Element tempEl = (Element) tempNode; String namespaceURI = (prefix == null) ? getAttribute(tempEl, "xmlns") : getAttributeNS(tempEl, NS_URI_XMLNS, prefix); if (namespaceURI != null) { return namespaceURI; } tempNode = tempEl.getParentNode(); } return null; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * This method traverses the DOM and grabs namespace declarations * on parent elements with the intent of preserving them for children. <em>Note * that the DOM level 3 document method {@link Element#getAttribute(java.lang.String)} * is not desirable in this case, as it does not respect namespace prefix * bindings that may affect attribute values. (Namespaces in DOM are * uncategorically a mess, especially in the context of XML Schema.)</em> * @param el the starting element//from ww w. j ava2 s. c o m * @return a {@link Map} containing prefix bindings. */ public static Map<String, String> getParentNamespaces(Element el) { HashMap<String, String> pref = new HashMap<String, String>(); Map<String, String> mine = getMyNamespaces(el); Node n = el.getParentNode(); while (n != null && n.getNodeType() != Node.DOCUMENT_NODE) { if (n instanceof Element) { Element l = (Element) n; NamedNodeMap nnm = l.getAttributes(); int len = nnm.getLength(); for (int i = 0; i < len; ++i) { Attr a = (Attr) nnm.item(i); if (isNSAttribute(a)) { String key = getNSPrefixFromNSAttr(a); String uri = a.getValue(); // prefer prefix bindings that are lower down in the tree. if (pref.containsKey(key) || mine.containsKey(key)) continue; pref.put(key, uri); } } } n = n.getParentNode(); } return pref; }
From source file:org.apache.ranger.utils.install.XmlConfigChanger.java
private void delProperty(String propName) { Node node = findProperty(propName); if (node != null) { node.getParentNode().removeChild(node); }//from w w w .j a v a 2 s .c om }
From source file:org.apache.shindig.gadgets.parse.CompactHtmlSerializer.java
@Override protected void writeText(Node n, Appendable output) throws IOException { if (isSpecialTag(n.getParentNode().getNodeName())) { super.writeText(n, output); } else {/* w ww .jav a 2 s .c o m*/ collapseWhitespace(n.getTextContent(), output); } }
From source file:org.apache.shindig.gadgets.parse.CompactHtmlSerializer.java
@Override protected void writeComment(Node n, Appendable output) throws IOException { if (isSpecialTag(n.getParentNode().getNodeName())) { super.writeComment(n, output); } else if (isIeConditionalComment(n)) { super.writeComment(n, output); }//from w w w. jav a2s. c o m }
From source file:org.apache.ws.security.message.TestMessageTransformer.java
public static Element duplicateEncryptedDataInWsseWrapperHeader(Element saaj, boolean moveReferenceList) { if (moveReferenceList) { moveReferenceList(saaj);/*from w ww. j a va 2 s. c om*/ } Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"), true); Element encData = getFirstChildElement(body, new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), true); Element newEncData = createNewEncryptedData(encData); Element sh = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header"), true); Element signature = getFirstChildElement(sh, new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"), true); Node wsseHeader = signature.getParentNode(); Node newWsseHeader = wsseHeader.cloneNode(false); Node cur = wsseHeader.getFirstChild(); String newId = newEncData.getAttributeNS(null, "Id"); while (!cur.isSameNode(signature)) { cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId); } Element wrapper = encData.getOwnerDocument().createElementNS(null, "a"); wrapper.appendChild(newEncData); newWsseHeader.appendChild(wrapper); while (cur != null) { cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId); } if (!moveReferenceList) { updateEncryptedKeyRefList(newWsseHeader, newId); } Node parent = wsseHeader.getParentNode(); parent.removeChild(wsseHeader); parent.appendChild(newWsseHeader); print(saaj.getOwnerDocument()); return newEncData; }
From source file:org.apache.ws.security.message.UsernameTokenTest.java
/** * A test for sending multiple nonces in the UsernameToken *//*from w w w . ja v a 2 s . com*/ @org.junit.Test public void testMultipleNonce() throws Exception { WSSecUsernameToken builder = new WSSecUsernameToken(); builder.setPasswordType(WSConstants.PASSWORD_DIGEST); builder.setUserInfo("wernerd", "verySecret"); Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); Document utDoc = builder.build(doc, secHeader); // // Manually find the Nonce node and duplicate it // org.w3c.dom.Element elem = builder.getUsernameTokenElement(); org.w3c.dom.NodeList list = elem.getElementsByTagNameNS(WSConstants.WSSE_NS, "Nonce"); org.w3c.dom.Node nonceNode = list.item(0); org.w3c.dom.Node nonceCopy = nonceNode.cloneNode(true); nonceNode.getParentNode().insertBefore(nonceCopy, nonceNode); if (LOG.isDebugEnabled()) { String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(utDoc); LOG.debug(outputString); } WSSecurityEngine newEngine = new WSSecurityEngine(); try { newEngine.processSecurityHeader(doc, null, callbackHandler, null); fail("Expected failure as it is not BSP compliant"); } catch (WSSecurityException ex) { // expected } WSSConfig config = WSSConfig.getNewInstance(); config.setWsiBSPCompliant(false); newEngine.setWssConfig(config); newEngine.processSecurityHeader(doc, null, callbackHandler, null); }
From source file:org.apache.ws.security.message.UsernameTokenTest.java
/** * A test for sending multiple Created elements in the UsernameToken *//*from w w w .j a v a 2s . c om*/ @org.junit.Test public void testMultipleCreated() throws Exception { WSSecUsernameToken builder = new WSSecUsernameToken(); builder.setPasswordType(WSConstants.PASSWORD_DIGEST); builder.setUserInfo("wernerd", "verySecret"); Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); Document utDoc = builder.build(doc, secHeader); // // Manually find the Created node and duplicate it // org.w3c.dom.Element elem = builder.getUsernameTokenElement(); org.w3c.dom.NodeList list = elem.getElementsByTagNameNS(WSConstants.WSU_NS, "Created"); org.w3c.dom.Node createdNode = list.item(0); org.w3c.dom.Node createdCopy = createdNode.cloneNode(true); createdNode.getParentNode().insertBefore(createdCopy, createdNode); if (LOG.isDebugEnabled()) { String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(utDoc); LOG.debug(outputString); } WSSecurityEngine newEngine = new WSSecurityEngine(); try { newEngine.processSecurityHeader(doc, null, callbackHandler, null); fail("Expected failure as it is not BSP compliant"); } catch (WSSecurityException ex) { // expected } WSSConfig config = WSSConfig.getNewInstance(); config.setWsiBSPCompliant(false); newEngine.setWssConfig(config); newEngine.processSecurityHeader(doc, null, callbackHandler, null); }