List of usage examples for org.w3c.dom Node appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:org.apache.nutch.searcher.response.xml.XMLResponseWriter.java
/** * Creates and returns a new node within the XML document. The node contains * the text supplied as a child node./*from ww w. jav a 2 s. c o m*/ * * @param doc The XML document. * @param parent The parent Node. * @param name The name of the new node. * @param text A text string to append as a child node. * * @return The newly created node Element. */ private static void addNode(Document doc, Node parent, String name, String text) { Element child = doc.createElement(name); child.appendChild(doc.createTextNode(getLegalXml(text))); parent.appendChild(child); }
From source file:org.apache.ode.bpel.engine.ProcessAndInstanceManagementImpl.java
/** * Fill in the <code>process-info</code> element of the transfer object. * * @param info// w w w . j a va 2 s . co m * destination XMLBean * @param pconf * process configuration object (from store) * @param proc * source DAO object * @param custom * used to customize the quantity of information produced in the * info */ private void fillProcessInfo(TProcessInfo info, ProcessConf pconf, ProcessInfoCustomizer custom) { if (pconf == null) throw new IllegalArgumentException("Null pconf."); if (__log.isDebugEnabled()) __log.debug("Filling process info for " + pconf.getProcessId()); info.setPid(pconf.getProcessId().toString()); // TODO: ACTIVE and RETIRED should be used separately. // Active process may be retired at the same time if (pconf.getState() == ProcessState.RETIRED) { info.setStatus(TProcessStatus.RETIRED); } else if (pconf.getState() == ProcessState.DISABLED) { info.setStatus(TProcessStatus.DISABLED); } else { info.setStatus(TProcessStatus.ACTIVE); } info.setVersion(pconf.getVersion()); TDefinitionInfo definfo = info.addNewDefinitionInfo(); definfo.setProcessName(pconf.getType()); TDeploymentInfo depinfo = info.addNewDeploymentInfo(); depinfo.setPackage(pconf.getPackage()); if (__log.isDebugEnabled()) __log.debug(" package name: " + depinfo.getPackage()); depinfo.setDocument(pconf.getBpelDocument()); depinfo.setDeployDate(toCalendar(pconf.getDeployDate())); depinfo.setDeployer(pconf.getDeployer()); if (custom.includeDocumentLists()) { TProcessInfo.Documents docinfo = info.addNewDocuments(); List<File> files = pconf.getFiles(); if (files != null) genDocumentInfo(docinfo, files.toArray(new File[files.size()]), true); else if (__log.isDebugEnabled()) __log.debug("fillProcessInfo: No files for " + pconf.getProcessId()); } TProcessProperties properties = info.addNewProperties(); if (custom.includeProcessProperties()) { for (Map.Entry<QName, Node> propEntry : pconf.getProcessProperties().entrySet()) { TProcessProperties.Property tprocProp = properties.addNewProperty(); tprocProp.setName( new QName(propEntry.getKey().getNamespaceURI(), propEntry.getKey().getLocalPart())); Node propNode = tprocProp.getDomNode(); Document processInfoDoc = propNode.getOwnerDocument(); Node node2append = processInfoDoc.importNode(propEntry.getValue(), true); propNode.appendChild(node2append); } } TEndpointReferences eprs = info.addNewEndpoints(); OProcess oprocess = _server._engine.getOProcess(pconf.getProcessId()); if (custom.includeEndpoints() && oprocess != null) { for (OPartnerLink oplink : oprocess.getAllPartnerLinks()) { if (oplink.hasPartnerRole() && oplink.initializePartnerRole) { // TODO: this is very uncool. EndpointReference pepr = _server._engine._activeProcesses.get(pconf.getProcessId()) .getInitialPartnerRoleEPR(oplink); if (pepr != null) { TEndpointReferences.EndpointRef epr = eprs.addNewEndpointRef(); Document eprNodeDoc = epr.getDomNode().getOwnerDocument(); epr.getDomNode() .appendChild(eprNodeDoc.importNode(pepr.toXML().getDocumentElement(), true)); } } } } // TODO: add documents to the above data structure. }
From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
/** * isInsert flag desginates this as an 'element' type insertion, which * requires insert the actual element value, rather than it's children * * @return/*www . j av a 2 s . c om*/ * @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(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } return lvalue; }
From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
private Node evalQuery(Node data, OMessageVarType.Part part, OExpression expression, EvaluationContext ec) throws FaultException { assert data != null; if (part != null) { QName partName = new QName(null, part.name); Node qualLVal = DOMUtils.findChildByName((Element) data, partName); if (part.type instanceof OElementVarType) { QName elName = ((OElementVarType) part.type).elementType; qualLVal = DOMUtils.findChildByName((Element) qualLVal, elName); } else if (part.type == null) { // Special case of header parts never referenced in the WSDL def if (qualLVal != null && qualLVal.getNodeType() == Node.ELEMENT_NODE && ((Element) qualLVal).getAttribute("headerPart") != null && DOMUtils.getTextContent(qualLVal) == null) qualLVal = DOMUtils.getFirstChildElement((Element) qualLVal); // The needed part isn't there, dynamically creating it if (qualLVal == null) { qualLVal = data.getOwnerDocument().createElementNS(null, part.name); ((Element) qualLVal).setAttribute("headerPart", "true"); data.appendChild(qualLVal); }/*from w w w .j a va 2 s. c o m*/ } data = qualLVal; } if (expression != null) { // Neat little trick.... data = ec.evaluateQuery(data, expression); } return data; }
From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java
/** * isInsert flag desginates this as an 'element' type insertion, which * requires insert the actual element value, rather than it's children * (madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here) * @return//from www . ja v a 2s.c o m * @throws FaultException */ public 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.bpel.rtrep.v2.AssignHelper.java
/** * madars.vitolins _at gmail.com - 2009.04.17 moved from ASSIGN here * @param data/*from w ww. jav a 2 s . com*/ * @param part * @param expression * @param ec * @return * @throws FaultException */ private Node evalQuery(Node data, OMessageVarType.Part part, OExpression expression, EvaluationContext ec) throws FaultException { assert data != null; if (part != null) { QName partName = new QName(null, part.name); Node qualLVal = DOMUtils.findChildByName((Element) data, partName); if (part.type instanceof OElementVarType) { QName elName = ((OElementVarType) part.type).elementType; qualLVal = DOMUtils.findChildByName((Element) qualLVal, elName); } else if (part.type == null) { // Special case of header parts never referenced in the WSDL def if (qualLVal != null && qualLVal.getNodeType() == Node.ELEMENT_NODE && ((Element) qualLVal).getAttribute("headerPart") != null && DOMUtils.getTextContent(qualLVal) == null) qualLVal = DOMUtils.getFirstChildElement((Element) qualLVal); // The needed part isn't there, dynamically creating it if (qualLVal == null) { qualLVal = data.getOwnerDocument().createElementNS(null, part.name); ((Element) qualLVal).setAttribute("headerPart", "true"); data.appendChild(qualLVal); } } data = qualLVal; } if (expression != null) { // Neat little trick.... data = ec.evaluateQuery(data, expression); } return data; }
From source file:org.apache.ode.bpel.runtime.ASSIGN.java
private Node evalQuery(Node data, OMessageVarType.Part part, OExpression expression, EvaluationContext ec) throws FaultException { assert data != null; if (part != null) { QName partName = new QName(null, part.name); Node qualLVal = DOMUtils.findChildByName((Element) data, partName); if (part.type instanceof OElementVarType) { QName elName = ((OElementVarType) part.type).elementType; qualLVal = DOMUtils.findChildByName((Element) qualLVal, elName); } else if (part.type == null) { // Special case of header parts never referenced in the WSDL def if (qualLVal != null && qualLVal.getNodeType() == Node.ELEMENT_NODE && ((Element) qualLVal).getAttribute("headerPart") != null && DOMUtils.getTextContent(qualLVal) == null) qualLVal = DOMUtils.getFirstChildElement((Element) qualLVal); // The needed part isn't there, dynamically creating it if (qualLVal == null) { qualLVal = data.getOwnerDocument().createElementNS(null, part.name); ((Element) qualLVal).setAttribute("headerPart", "true"); data.appendChild(qualLVal); }/*from w w w. j a v a 2 s .co m*/ } data = qualLVal; } if (expression != null) { // Neat little trick.... try { data = ec.evaluateQuery(data, expression); } catch (EvaluationException e) { String msg = __msgs.msgEvalException(expression.toString(), e.getMessage()); if (__log.isDebugEnabled()) __log.debug(expression + ": " + msg); if (e.getCause() instanceof FaultException) throw (FaultException) e.getCause(); throw new FaultException(getOAsssign().getOwner().constants.qnSubLanguageExecutionFault, msg); } } return data; }
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 a va2s. c om * @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.bpel.runtime.AssignHelper.java
private Node evalQuery(Node data, OMessageVarType.Part part, OExpression expression, EvaluationContext ec) throws FaultException { assert data != null; if (part != null) { QName partName = new QName(null, part.name); Node qualLVal = DOMUtils.findChildByName((Element) data, partName); if (part.type instanceof OElementVarType) { QName elName = ((OElementVarType) part.type).elementType; qualLVal = DOMUtils.findChildByName((Element) qualLVal, elName); } else if (part.type == null) { // Special case of header parts never referenced in the WSDL def if (qualLVal != null && qualLVal.getNodeType() == Node.ELEMENT_NODE && ((Element) qualLVal).getAttribute("headerPart") != null && DOMUtils.getTextContent(qualLVal) == null) qualLVal = DOMUtils.getFirstChildElement((Element) qualLVal); // The needed part isn't there, dynamically creating it if (qualLVal == null) { qualLVal = data.getOwnerDocument().createElementNS(null, part.name); ((Element) qualLVal).setAttribute("headerPart", "true"); data.appendChild(qualLVal); }/*from ww w . j a va2s. com*/ } data = qualLVal; } if (expression != null) { // Neat little trick.... try { data = ec.evaluateQuery(data, expression); } catch (EvaluationException e) { String msg = __msgs.msgEvalException(expression.toString(), e.getMessage()); if (__log.isDebugEnabled()) __log.debug(expression + ": " + msg); if (e.getCause() instanceof FaultException) throw (FaultException) e.getCause(); throw new FaultException(getOActivity().getOwner().constants.qnSubLanguageExecutionFault, msg); } } return data; }
From source file:org.apache.ode.utils.DOMUtils.java
private static void parse(XMLStreamReader reader, Document doc, Node parent) throws XMLStreamException { int event = reader.getEventType(); while (reader.hasNext()) { switch (event) { case XMLStreamConstants.START_ELEMENT: // create element Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName()); if (reader.getPrefix() != null && reader.getPrefix() != "") { e.setPrefix(reader.getPrefix()); }/*from w w w . jav a2s . c o m*/ parent.appendChild(e); // copy namespaces for (int ns = 0; ns < reader.getNamespaceCount(); ns++) { String uri = reader.getNamespaceURI(ns); String prefix = reader.getNamespacePrefix(ns); declare(e, uri, prefix); } // copy attributes for (int att = 0; att < reader.getAttributeCount(); att++) { String name = reader.getAttributeLocalName(att); String prefix = reader.getAttributePrefix(att); if (prefix != null && prefix.length() > 0) { name = prefix + ":" + name; } Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name); attr.setValue(reader.getAttributeValue(att)); e.setAttributeNode(attr); } // sub-nodes if (reader.hasNext()) { reader.next(); parse(reader, doc, e); } if (parent instanceof Document) { while (reader.hasNext()) reader.next(); return; } break; case XMLStreamConstants.END_ELEMENT: return; case XMLStreamConstants.CHARACTERS: if (parent != null) { parent.appendChild(doc.createTextNode(reader.getText())); } break; case XMLStreamConstants.COMMENT: if (parent != null) { parent.appendChild(doc.createComment(reader.getText())); } break; case XMLStreamConstants.CDATA: parent.appendChild(doc.createCDATASection(reader.getText())); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); break; case XMLStreamConstants.ENTITY_REFERENCE: parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); break; case XMLStreamConstants.NAMESPACE: case XMLStreamConstants.ATTRIBUTE: break; default: break; } if (reader.hasNext()) { event = reader.next(); } } }