List of usage examples for org.w3c.dom Document createProcessingInstruction
public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException;
ProcessingInstruction
node given the specified name and data strings. From source file:org.apache.ode.utils.DOMUtils.java
/** * Deep clone, but don't fry, the given node in the context of the given document. * For all intents and purposes, the clone is the exact same copy of the node, * except that it might have a different owner document. * * This method is fool-proof, unlike the <code>adoptNode</code> or <code>adoptNode</code> methods, * in that it doesn't assume that the given node has a parent or a owner document. * * @param document//from w ww.j a v a 2s . c o m * @param sourceNode * @return a clone of node */ public static Node cloneNode(Document document, Node sourceNode) { Node clonedNode = null; // what is my name? QName sourceQName = getNodeQName(sourceNode); String nodeName = sourceQName.getLocalPart(); String namespaceURI = sourceQName.getNamespaceURI(); // if the node is unqualified, don't assume that it inherits the WS-BPEL target namespace if (Namespaces.WSBPEL2_0_FINAL_EXEC.equals(namespaceURI)) { namespaceURI = null; } switch (sourceNode.getNodeType()) { case Node.ATTRIBUTE_NODE: if (namespaceURI == null) { clonedNode = document.createAttribute(nodeName); } else { String prefix = ((Attr) sourceNode).lookupPrefix(namespaceURI); // the prefix for the XML namespace can't be looked up, hence this... if (prefix == null && namespaceURI.equals(NS_URI_XMLNS)) { prefix = "xmlns"; } // if a prefix exists, qualify the name with it if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; } // create the appropriate type of attribute if (prefix != null) { clonedNode = document.createAttributeNS(namespaceURI, nodeName); } else { clonedNode = document.createAttribute(nodeName); } } break; case Node.CDATA_SECTION_NODE: clonedNode = document.createCDATASection(((CDATASection) sourceNode).getData()); break; case Node.COMMENT_NODE: clonedNode = document.createComment(((Comment) sourceNode).getData()); break; case Node.DOCUMENT_FRAGMENT_NODE: clonedNode = document.createDocumentFragment(); break; case Node.DOCUMENT_NODE: clonedNode = document; break; case Node.ELEMENT_NODE: // create the appropriate type of element if (namespaceURI == null) { clonedNode = document.createElement(nodeName); } else { String prefix = namespaceURI.equals(Namespaces.XMLNS_URI) ? "xmlns" : ((Element) sourceNode).lookupPrefix(namespaceURI); if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; clonedNode = document.createElementNS(namespaceURI, nodeName); } else { clonedNode = document.createElement(nodeName); } } // attributes are not treated as child nodes, so copy them explicitly NamedNodeMap attributes = ((Element) sourceNode).getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attributeClone = (Attr) cloneNode(document, attributes.item(i)); if (attributeClone.getNamespaceURI() == null) { ((Element) clonedNode).setAttributeNode(attributeClone); } else { ((Element) clonedNode).setAttributeNodeNS(attributeClone); } } break; case Node.ENTITY_NODE: // TODO break; case Node.ENTITY_REFERENCE_NODE: clonedNode = document.createEntityReference(nodeName); // TODO break; case Node.NOTATION_NODE: // TODO break; case Node.PROCESSING_INSTRUCTION_NODE: clonedNode = document.createProcessingInstruction(((ProcessingInstruction) sourceNode).getData(), nodeName); break; case Node.TEXT_NODE: clonedNode = document.createTextNode(((Text) sourceNode).getData()); break; default: break; } // clone children of element and attribute nodes NodeList sourceChildren = sourceNode.getChildNodes(); if (sourceChildren != null) { for (int i = 0; i < sourceChildren.getLength(); i++) { Node sourceChild = sourceChildren.item(i); Node clonedChild = cloneNode(document, sourceChild); clonedNode.appendChild(clonedChild); // if the child has a textual value, parse it for any embedded prefixes if (clonedChild.getNodeType() == Node.TEXT_NODE || clonedChild.getNodeType() == Node.CDATA_SECTION_NODE) { parseEmbeddedPrefixes(sourceNode, clonedNode, clonedChild); } } } return clonedNode; }
From source file:org.fireflow.pdl.fpdl.io.FPDLDeserializer.java
public WorkflowProcess deserialize(InputStream in) throws IOException, DeserializerException, InvalidModelException { try {// w ww .j a va 2 s. c o m DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(in); String encoding = document.getXmlEncoding(); log.info("Xml:" + encoding); final org.w3c.dom.Node pi = document .createProcessingInstruction(StreamResult.PI_DISABLE_OUTPUT_ESCAPING, ""); document.appendChild(pi); WorkflowProcess wp = deserialize(document);// ? return wp; } catch (ParserConfigurationException e) { throw new DeserializerException("Error parsing document.", e); } catch (SAXException e) { throw new DeserializerException("Error parsing document.", e); } finally { } // return parse(new InputStreamReader(in)); }
From source file:org.fireflow.pdl.fpdl.io.FPDLSerializer.java
public Document serializeToDOM(WorkflowProcess workflowProcess) throws SerializerException, InvalidModelException { DocumentBuilder documentBuilder = null; try {/*from ww w .j a v a 2s . c om*/ documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new SerializerException(e); } Document document = documentBuilder.newDocument(); //??? final Node pi = document.createProcessingInstruction(StreamResult.PI_DISABLE_OUTPUT_ESCAPING, ""); document.appendChild(pi); // serialize the Package Element workflowProcessElement = document.createElementNS(FPDL_NS_URI, FPDL_NS_PREFIX + ":" + WORKFLOW_PROCESS); document.appendChild(workflowProcessElement); // workflowProcessElement.addNamespace(FPDL_NS_PREFIX, FPDL_NS_URI); // workflowProcessElement.addNamespace(SERVICE_NS_PREFIX, SERVICE_NS_URI); // workflowProcessElement.addNamespace(RESOURCE_NS_PREFIX, RESOURCE_NS_URI); // workflowProcessElement.addNamespace(XSD_NS_PREFIX, XSD_URI); // workflowProcessElement.addNamespace(XSI_NS_PREFIX, XSI_URI); // QName qname = df.createQName( // "schemaLocation", "xsi", XSI_URI); // workflowProcessElement.setAttribute(qname, FPDL_SCHEMA_LOCATION+" "+SERVICE_SCHEMA_LOCATION+" "+RESOURCE_SCHEMA_LOCATION); workflowProcessElement.setAttribute(ID, workflowProcess.getId()); workflowProcessElement.setAttribute(NAME, workflowProcess.getName()); workflowProcessElement.setAttribute(DISPLAY_NAME, workflowProcess.getDisplayName()); workflowProcessElement.setAttribute(PACKAGE_ID, workflowProcess.getPackageId()); this.writeDescription(workflowProcessElement, workflowProcess.getDescription()); //?import? //writeImports4Service(workflowProcess.getImportsForService(),workflowProcessElement);//resourceservice???2014-01-07 //writeImports4Resource(workflowProcess.getImportsForResource(),workflowProcessElement);//resourceservice???2014-01-07 this.writeImports(workflowProcess.getImports(), workflowProcessElement); //? service? ServiceParser.writeServices(workflowProcess.getServices(), workflowProcessElement); ResourceSerializer.writeResources(workflowProcess.getResources(), workflowProcessElement); Element subflowsElement = Util4Serializer.addElement(workflowProcessElement, SUBPROCESSES); List<SubProcess> subflowList = workflowProcess.getLocalSubProcesses(); if (subflowList != null && subflowList.size() > 0) { for (SubProcess subflow : subflowList) { writeSubflow(subflow, subflowsElement); } } Element diagramsElement = Util4Serializer.addElement(workflowProcessElement, DIAGRAMS); List<Diagram> diagramsList = workflowProcess.getDiagrams(); if (diagramsList != null && diagramsList.size() > 0) { for (Diagram diagram : diagramsList) { writeDiagram(diagram, diagramsElement); } } return document; }
From source file:org.fireflow.pdl.fpdl20.io.FPDLSerializer.java
public Document serializeToDOM(WorkflowProcess workflowProcess) throws SerializerException, InvalidModelException { DocumentBuilder documentBuilder = null; try {/*from w w w.j av a 2 s. com*/ documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new SerializerException(e); } Document document = documentBuilder.newDocument(); //??? final Node pi = document.createProcessingInstruction(StreamResult.PI_DISABLE_OUTPUT_ESCAPING, ""); document.appendChild(pi); // serialize the Package Element workflowProcessElement = document.createElementNS(FPDL_NS_URI, FPDL_NS_PREFIX + ":" + WORKFLOW_PROCESS); document.appendChild(workflowProcessElement); // workflowProcessElement.addNamespace(FPDL_NS_PREFIX, FPDL_NS_URI); // workflowProcessElement.addNamespace(SERVICE_NS_PREFIX, SERVICE_NS_URI); // workflowProcessElement.addNamespace(RESOURCE_NS_PREFIX, RESOURCE_NS_URI); // workflowProcessElement.addNamespace(XSD_NS_PREFIX, XSD_URI); // workflowProcessElement.addNamespace(XSI_NS_PREFIX, XSI_URI); // QName qname = df.createQName( // "schemaLocation", "xsi", XSI_URI); // workflowProcessElement.setAttribute(qname, FPDL_SCHEMA_LOCATION+" "+SERVICE_SCHEMA_LOCATION+" "+RESOURCE_SCHEMA_LOCATION); workflowProcessElement.setAttribute(ID, workflowProcess.getId()); workflowProcessElement.setAttribute(NAME, workflowProcess.getName()); workflowProcessElement.setAttribute(DISPLAY_NAME, workflowProcess.getDisplayName()); workflowProcessElement.setAttribute(BIZ_CATEGORY, workflowProcess.getBizCategory()); this.writeDescription(workflowProcessElement, workflowProcess.getDescription()); //?import? writeImports4Service(workflowProcess.getImportsForService(), workflowProcessElement); writeImports4Resource(workflowProcess.getImportsForResource(), workflowProcessElement); this.writeImport4Process(workflowProcess.getImportsForProcess(), workflowProcessElement); //? service? ServiceParser.writeServices(workflowProcess.getLocalServices(), workflowProcessElement); ResourceSerializer.writeResources(workflowProcess.getLocalResources(), workflowProcessElement); Element subflowsElement = Util4Serializer.addElement(workflowProcessElement, SUBFLOWS); List<SubProcess> subflowList = workflowProcess.getLocalSubProcesses(); if (subflowList != null && subflowList.size() > 0) { for (SubProcess subflow : subflowList) { writeSubflow(subflow, subflowsElement); } } Element diagramsElement = Util4Serializer.addElement(workflowProcessElement, DIAGRAMS); List<Diagram> diagramsList = workflowProcess.getDiagrams(); if (diagramsList != null && diagramsList.size() > 0) { for (Diagram diagram : diagramsList) { writeDiagram(diagram, diagramsElement); } } return document; }
From source file:org.gnucash.android.export.ExporterTask.java
/** * Exports transactions in the database to the OFX format. * The accounts are written to a DOM document and returned * @param exportAll Flag to export all transactions or only the new ones since last export * @return DOM {@link Document} containing the OFX file information * @throws javax.xml.parsers.ParserConfigurationException *///from w w w. j av a 2 s. co m protected Document exportOfx(boolean exportAll) throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); Element root = document.createElement("OFX"); ProcessingInstruction pi = document.createProcessingInstruction("OFX", OfxHelper.OFX_HEADER); document.appendChild(pi); document.appendChild(root); OfxExporter exporter = new OfxExporter(mContext, exportAll); exporter.toOfx(document, root); return document; }
From source file:org.gnucash.android.export.ExporterTask.java
/** * Exports transactions in the database to the OFX format. * The accounts are written to a DOM document and returned * @param exportAll Flag to export all transactions or only the new ones since last export * @return DOM {@link Document} containing the OFX file information * @throws javax.xml.parsers.ParserConfigurationException *//*from ww w .j a v a2 s . co m*/ protected Document exportOfx(boolean exportAll) throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); Element root = document.createElement("OFX"); ProcessingInstruction pi = document.createProcessingInstruction("OFX", OfxExporter.OFX_HEADER); document.appendChild(pi); document.appendChild(root); OfxExporter exporter = new OfxExporter(mContext, exportAll); exporter.toOfx(document, root); return document; }
From source file:org.gnucash.android.ui.accounts.ExportDialogFragment.java
/** * Exports transactions in the database to the OFX format. * The accounts are written to a DOM document and returned * @param exportAll Flag to export all transactions or only the new ones since last export * @return DOM {@link Document} containing the OFX file information * @throws ParserConfigurationException//www.j a v a 2s. c om */ protected Document exportOfx(boolean exportAll) throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document document = docBuilder.newDocument(); Element root = document.createElement("OFX"); ProcessingInstruction pi = document.createProcessingInstruction("OFX", OfxFormatter.OFX_HEADER); document.appendChild(pi); document.appendChild(root); OfxFormatter exporter = new OfxFormatter(getActivity(), exportAll); exporter.toOfx(document, root); return document; }
From source file:org.jbpm.bpel.sublang.xpath.XPathEvaluator.java
private static Node createNonElementChild(Step step, Element contextElem) { if (!step.getPredicates().isEmpty()) { log.error("cannot create node for step with predicates: " + step); throw new BpelFaultException(BpelConstants.FAULT_SELECTION_FAILURE); }/* w ww .j a va 2s. co m*/ Document contextDoc = contextElem.getOwnerDocument(); if (step instanceof TextNodeStep) return contextDoc.createTextNode(""); if (step instanceof ProcessingInstructionNodeStep) { ProcessingInstructionNodeStep processingStep = (ProcessingInstructionNodeStep) step; return contextDoc.createProcessingInstruction(processingStep.getName(), ""); } if (step instanceof CommentNodeStep) return contextDoc.createComment(""); log.error("cannot create node for any-node tests on the child axis: " + step); throw new BpelFaultException(BpelConstants.FAULT_SELECTION_FAILURE); }