List of usage examples for org.w3c.dom Document appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:com.nebhale.gpxconverter.StandardRouteBuilder.java
@Override public Document build(String name, List<Point> points) { try {// ww w.j a v a2s. c o m Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); document.setXmlStandalone(true); document.appendChild(gpx(document, name, points)); return document; } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
From source file:fitnesse.wiki.WikiPageProperties.java
public void save(OutputStream outputStream) { Document document; XmlWriter writer = null;// w w w .j a va2 s.co m try { document = XmlUtil.newDocument(); document.appendChild(makeRootElement(document)); writer = new XmlWriter(outputStream); writer.write(document); } catch (Exception e) { throw new TodoException(e); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.seer.datacruncher.factories.streams.SchemaStreamsEXI.java
@Override public byte[] getDownloadableStreams() { if (maxVertical == 0) return null; StringBuffer result = new StringBuffer(); result.append("<_root_>\n"); for (int i = 0; i < maxVertical; i++) { Document doc = getNewDomDocument(); Element xmlNode = doc.createElement(root.getName() + i); xmlNode.setTextContent(getNodeText(root.getPath("."), i, linkedFieldsPaths)); doc.appendChild(xmlNode); recursiveListChilds(doc, xmlNode, root, i, linkedFieldsPaths); result.append(DomToOtherFormat.convertDomToXml(doc)).append("\n"); }/*from ww w.j av a 2 s. co m*/ result.append("</_root_>"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { EXI.encodeXmlToEXI(new ByteArrayInputStream(result.toString().getBytes("UTF-8")), baos); } catch (UnsupportedEncodingException e) { log.error("UnsupportedEncodingException", e); } catch (SAXException e) { log.error("SAXException", e); } catch (EXIException e) { log.error("EXIException", e); } catch (IOException e) { log.error("IOException", e); } return baos.toByteArray(); }
From source file:be.e_contract.mycarenet.xkms.ProofOfPossessionSignatureSOAPHandler.java
private Document copyDocument(Element element) throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Node importedNode = document.importNode(element, true); document.appendChild(importedNode); return document; }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * creates a new non-namespaced, non-validating Document and creates a root node which is returned * @return the newly created root node/* ww w .j a va 2s . c o m*/ */ public static Element createRootElement(String rootNodeName) { Document inputDoc = DOMUtil.newDocument(false, false); Element rootNode = inputDoc.createElement(rootNodeName); inputDoc.appendChild(rootNode); return rootNode; }
From source file:com.syrup.storage.xml.XmlFactory.java
/** * Returns a <code>Document</code> object representing a ??? * /*ww w. j a v a 2s. c o m*/ * @param mockServices List of services to convert into an xml document * @return <code>Document</code> object representing a cXML order request */ public Document getAsDocument(IStorage store) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder docBuilder = factory.newDocumentBuilder(); Document document = docBuilder.newDocument(); XmlFileConfigurationGenerator xmlGeneratorSupport = new XmlFileConfigurationGenerator(); Element xmlRootElement = xmlGeneratorSupport.getElement(document, store); document.appendChild(xmlRootElement); return document; } catch (ParserConfigurationException pce) { System.out.println(":" + pce.getMessage()); return null; } }
From source file:de.betterform.connector.ModelSubmissionHandler.java
/** * Purpose:<br/>//from w w w . j ava2 s . c o m * The ModelSubmissionHandler can be used to exchange data between XForms models. It is capable of replacing data * in a certain instance of the receiver model.<br/><br/> * * Syntax: model:[Model ID]#instance('[Instance ID]')/[XPath]<br/><br/> * * Caveats:<br/> * - Model and Instance IDs must be known to allow explicit addressing<br/> * - the form author has to make sure that no ID collisions take place<br/> * - the XPath must be explicitly given even if the the target Node is the root Node of the instance * * * @param submission the submission issuing the request. * @param instance the instance data to be serialized and submitted. * @return * @throws de.betterform.xml.xforms.exception.XFormsException * if any error occurred during submission. */ public Map submit(Submission submission, Node instance) throws XFormsException { try { String replaceMode = submission.getReplace(); if (!(replaceMode.equals("none") || replaceMode.equals("instance"))) { throw new XFormsException( "ModelSubmissionHandler only supports 'none' or 'instance' as replace mode"); } String submissionMethod = submission.getMethod(); String resourceAttr = getURI(); String resourceModelId = null; String instanceId = null; String xpath = null; try { int devider = resourceAttr.indexOf("#"); resourceModelId = resourceAttr.substring(resourceAttr.indexOf(":") + 1, devider); int instanceIdStart = resourceAttr.indexOf("(") + 1; int instanceIdEnd = resourceAttr.indexOf(")"); instanceId = resourceAttr.substring(instanceIdStart + 1, instanceIdEnd - 1); if (resourceAttr.indexOf("/") != -1) { xpath = resourceAttr.substring(resourceAttr.indexOf("/")); } else { throw new XFormsException( "Syntax error: xpath mustn't be null. You've to provide at least the path to the rootnode."); } } catch (IndexOutOfBoundsException e) { throw new XFormsException("Syntax error in expression: " + resourceAttr); } Model providerModel; Model receiverModel; if (submissionMethod.equalsIgnoreCase("get")) { providerModel = submission.getContainerObject().getModel(resourceModelId); receiverModel = submission.getModel(); Node targetNode = XPathUtil.getAsNode(XPathCache.getInstance().evaluate( providerModel.getInstance(instanceId).getRootContext().getNodeset(), 1, xpath, providerModel.getPrefixMapping(), providerModel.getXPathFunctionContext()), 1); if (targetNode == null) { throw new XFormsException("targetNode for xpath: " + xpath + " not found"); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("targetNode to replace............"); DOMUtil.prettyPrintDOM(targetNode); } Document result = DOMUtil.newDocument(true, false); result.appendChild(result.importNode(targetNode.cloneNode(true), true)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("result Instance after insertion ............"); DOMUtil.prettyPrintDOM(result); } Map response = new HashMap(1); response.put(XFormsProcessor.SUBMISSION_RESPONSE_DOCUMENT, result); return response; } else if (submissionMethod.equalsIgnoreCase("post")) { providerModel = submission.getModel(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Instance Data to post............"); DOMUtil.prettyPrintDOM(instance); } receiverModel = submission.getContainerObject().getModel(resourceModelId); Node targetNode = XPathUtil.getAsNode(XPathCache.getInstance().evaluate( receiverModel.getInstance(instanceId).getRootContext().getNodeset(), 1, xpath, receiverModel.getPrefixMapping(), receiverModel.getXPathFunctionContext()), 1); if (targetNode == null) { throw new XFormsException("targetNode for xpath: " + xpath + " not found"); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("targetNode to replace............"); DOMUtil.prettyPrintDOM(targetNode); } //todo:review - this can be an Eleement if ref was used on submission!!! if (instance instanceof Document) { Document toImport = (Document) instance; targetNode.getParentNode().replaceChild( targetNode.getOwnerDocument().importNode(toImport.getDocumentElement(), true), targetNode); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("result Instance after insertion ............"); DOMUtil.prettyPrintDOM(receiverModel.getDefaultInstance().getInstanceDocument()); } } else { throw new XFormsException("Submission method '" + submissionMethod + "' not supported"); } receiverModel.rebuild(); receiverModel.recalculate(); receiverModel.revalidate(); receiverModel.refresh(); return new HashMap(1); } catch (Exception e) { throw new XFormsException(e); } }
From source file:ddf.security.samlp.impl.LogoutMessageImpl.java
@Override public Element getElementFromSaml(XMLObject xmlObject) throws WSSecurityException { Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); return OpenSAMLUtil.toDom(xmlObject, doc); }
From source file:de.ingrid.iplug.ckan.record.mapper.CreateIdfMapper.java
@Override public void map(SourceRecord record, Document doc) throws Exception { DOMUtils domUtils = new DOMUtils(doc, new XPathUtils(new IDFNamespaceContext())); domUtils.addNS("idf", "http://www.portalu.de/IDF/1.0"); IdfElement html = domUtils.createElement("idf:html"); doc.appendChild(html.getElement()); html.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); html.addAttribute("xsi:schemaLocation", domUtils.getNS("idf") + " ingrid_detail_data_schema.xsd"); html.addElement("idf:head"); html.addElement("idf:body"); }
From source file:ddf.security.samlp.impl.LogoutMessageImpl.java
private URI signSamlGet(SAMLObject samlObject, URI target, String relayState, String requestType) throws WSSecurityException, SimpleSign.SignatureException, IOException { Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); String encodedResponse = URLEncoder.encode(RestSecurity.deflateAndBase64Encode( DOM2Writer.nodeToString(OpenSAMLUtil.toDom(samlObject, doc, false))), "UTF-8"); String requestToSign = String.format("%s=%s&%s=%s", requestType, encodedResponse, SSOConstants.RELAY_STATE, relayState);/*from w w w. jav a 2 s . co m*/ UriBuilder uriBuilder = UriBuilder.fromUri(target); uriBuilder.queryParam(requestType, encodedResponse); uriBuilder.queryParam(SSOConstants.RELAY_STATE, relayState); new SimpleSign(systemCrypto).signUriString(requestToSign, uriBuilder); return uriBuilder.build(); }