List of usage examples for org.w3c.dom Node getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:org.structr.web.entity.dom.DOMNode.java
protected void checkSameDocument(Node otherNode) throws DOMException { Document doc = getOwnerDocument(); if (doc != null) { Document otherDoc = otherNode.getOwnerDocument(); // Shadow doc is neutral if (otherDoc != null && !doc.equals(otherDoc) && !(doc instanceof ShadowDocument)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, WRONG_DOCUMENT_ERR_MESSAGE); }//w w w .j a v a 2s . co m if (otherDoc == null) { ((DOMNode) otherNode).doAdopt((Page) doc); } } }
From source file:jef.tools.XMLUtils.java
/** * ???/* w w w .j a v a 2 s. c o m*/ * * @param node * * @param tagName * ?? * @param nodeText * * @return Element */ public static Element replaceElement(Node node, String tagName, String... nodeText) { Node pNode = node.getParentNode(); Assert.notNull(pNode); Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node; } else { doc = node.getOwnerDocument(); } Element e = doc.createElement(tagName); if (nodeText.length == 1) { setText(e, nodeText[0]); } else if (nodeText.length > 1) { setText(e, StringUtils.join(nodeText, '\n')); } pNode.replaceChild(e, node); return e; }
From source file:org.guanxi.idp.service.SSOBase.java
/** * Adds encrypted assertions to a SAML2 Response * * @param encryptionCert the X509 certificate to use for encrypting the assertions * @param assertionDoc the assertions to encrypt * @param responseDoc the SAML2 Response to add the encrypted assertions to * @throws GuanxiException if an error occurs *//*from w w w . j av a 2 s .c o m*/ protected void addEncryptedAssertionsToResponse(X509Certificate encryptionCert, AssertionDocument assertionDoc, ResponseDocument responseDoc) throws GuanxiException { try { PublicKey keyEncryptKey = encryptionCert.getPublicKey(); // Generate a secret key KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); SecretKey secretKey = keyGenerator.generateKey(); XMLCipher keyCipher = XMLCipher.getInstance(XMLCipher.RSA_OAEP); keyCipher.init(XMLCipher.WRAP_MODE, keyEncryptKey); Document domAssertionDoc = (Document) assertionDoc.newDomNode(xmlOptions); EncryptedKey encryptedKey = keyCipher.encryptKey(domAssertionDoc, secretKey); Element elementToEncrypt = domAssertionDoc.getDocumentElement(); XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.AES_128); xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey); // Add KeyInfo to the EncryptedData element EncryptedData encryptedDataElement = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(domAssertionDoc); keyInfo.add(encryptedKey); encryptedDataElement.setKeyInfo(keyInfo); // Encrypt the assertion xmlCipher.doFinal(domAssertionDoc, elementToEncrypt, false); // Go back into XMLBeans land... EncryptedDataDocument encryptedDataDoc = EncryptedDataDocument.Factory.parse(domAssertionDoc); // ...and add the encrypted assertion to the response responseDoc.getResponse().addNewEncryptedAssertion() .setEncryptedData(encryptedDataDoc.getEncryptedData()); // Look for the Response/EncryptedAssertion/EncryptedData/KeyInfo/EncryptedKey node... EncryptedDataType encryptedData = responseDoc.getResponse().getEncryptedAssertionArray(0) .getEncryptedData(); NodeList nodes = encryptedData.getKeyInfo().getDomNode().getChildNodes(); Node encryptedKeyNode = null; for (int c = 0; c < nodes.getLength(); c++) { encryptedKeyNode = nodes.item(c); if (encryptedKeyNode.getLocalName() != null) { if (encryptedKeyNode.getLocalName().equals("EncryptedKey")) break; } } // ...get a new KeyInfo ready... KeyInfoDocument keyInfoDoc = KeyInfoDocument.Factory.newInstance(); X509DataType x509Data = keyInfoDoc.addNewKeyInfo().addNewX509Data(); // ...and a useable version of the SP's encryption certificate... StringWriter sw = new StringWriter(); PEMWriter pemWriter = new PEMWriter(sw); pemWriter.writeObject(encryptionCert); pemWriter.close(); String x509 = sw.toString(); x509 = x509.replaceAll("-----BEGIN CERTIFICATE-----", ""); x509 = x509.replaceAll("-----END CERTIFICATE-----", ""); // ...add the encryption cert to the new KeyInfo... x509Data.addNewX509Certificate().setStringValue(x509); // ...and insert it into Response/EncryptedAssertion/EncryptedData/KeyInfo/EncryptedKey encryptedKeyNode.appendChild( encryptedKeyNode.getOwnerDocument().importNode(keyInfoDoc.getKeyInfo().getDomNode(), true)); } catch (NoSuchAlgorithmException nsae) { logger.error("AES encryption not available"); throw new GuanxiException(nsae); } catch (XMLEncryptionException xea) { logger.error("RSA_OAEP error with WRAP_MODE"); throw new GuanxiException(xea); } catch (Exception e) { logger.error("Error encyrpting the assertion"); throw new GuanxiException(e); } }
From source file:com.gargoylesoftware.htmlunit.html.DomNode.java
/** * Check for insertion errors for a new child node. This is overridden by derived * classes to enforce which types of children are allowed. * * @param newChild the new child node that is being inserted below this node * @throws DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does * not allow children of the type of the newChild node, or if the node to insert is one of * this node's ancestors or this node itself, or if this node is of type Document and the * DOM application attempts to insert a second DocumentType or Element node. * WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the * one that created this node./*from ww w . j av a 2 s. c om*/ */ protected void checkChildHierarchy(final Node newChild) throws DOMException { Node parentNode = this; while (parentNode != null) { if (parentNode == newChild) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Child node is already a parent."); } parentNode = parentNode.getParentNode(); } final Document thisDocument = getOwnerDocument(); final Document childDocument = newChild.getOwnerDocument(); if (childDocument != thisDocument && childDocument != null) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Child node " + newChild.getNodeName() + " is not in the same Document as this " + getNodeName() + "."); } }
From source file:de.betterform.xml.xforms.model.submission.Submission.java
private void updateInstanceAndModel(Model referedModel, Document responseInstance) throws XFormsException { if (this.targetExpr != null) { Node targetNode; if (this.instance == null) targetNode = XPathUtil.getAsNode(XPathCache.getInstance().evaluate(evalInScopeContext(), 1, this.targetExpr, this.prefixMapping, this.xpathFunctionContext), 1); else {/*from w w w .j a v a 2 s . co m*/ targetNode = XPathUtil.getAsNode(XPathCache.getInstance().evaluate( referedModel.getInstance(this.instance).getRootContext().getNodeset(), 1, this.targetExpr, this.prefixMapping, this.xpathFunctionContext), 1); } if (targetNode != null && targetNode.getNodeType() == Node.ELEMENT_NODE) { targetNode.getParentNode().replaceChild( targetNode.getOwnerDocument().importNode(responseInstance.getDocumentElement(), true), targetNode); } else if (targetNode != null && targetNode.getNodeType() == Node.ATTRIBUTE_NODE) { if (LOGGER.isDebugEnabled()) { DOMUtil.prettyPrintDOM(responseInstance); } // targetNode.setContent(responseInstance.getTextContent()); String attrValue = responseInstance.getDocumentElement().getTextContent(); targetNode.setNodeValue(attrValue); } else { throw new XFormsSubmitError("Invalid target", this.getTarget(), XFormsSubmitError.constructInfoObject(this.element, this.container, locationPath, XFormsConstants.TARGET_ERROR, getResourceURI(), 200d, null, "", "")); } } else if (this.instance != null && referedModel.getInstance(this.instance) == null) { this.container.dispatch(referedModel.getId(), XFormsEventNames.BINDING_EXCEPTION); // throw new XFormsBindingException("invalid instance id at " + DOMUtil.getCanonicalPath(this.getElement()), this.target, this.instance); } else if (this.instance != null) { referedModel.getInstance(this.instance).setInstanceDocument(responseInstance); } else { referedModel.getInstance(getInstanceId()).setInstanceDocument(responseInstance); } // perform rebuild, recalculate, revalidate, and refresh referedModel.rebuild(); referedModel.recalculate(); referedModel.revalidate(); }
From source file:ca.brood.softlogger.Softlogger.java
@Override public boolean configure(Node rootNode) { NodeList loggerConfigNodes = rootNode.getChildNodes(); log.debug("Configuring Logger..."); for (int i = 0; i < loggerConfigNodes.getLength(); i++) { Node configNode = loggerConfigNodes.item(i); if ("name".compareToIgnoreCase(configNode.getNodeName()) == 0) { //log.debug("Logger Name: "+configNode.getFirstChild().getNodeValue()); this.loggerName = configNode.getFirstChild().getNodeValue(); } else if ("defaultScanRate".compareToIgnoreCase(configNode.getNodeName()) == 0) { //log.debug("Default scan rate: "+configNode.getFirstChild().getNodeValue()); try { this.defaultScanRate = Integer.parseInt(configNode.getFirstChild().getNodeValue()); } catch (NumberFormatException e) { log.error("Invalid scan rate: " + configNode.getFirstChild().getNodeValue()); this.defaultScanRate = 0; }/* www . j av a2 s.com*/ } else if (("server".compareToIgnoreCase(configNode.getNodeName()) == 0) || ("channel".compareToIgnoreCase(configNode.getNodeName()) == 0) || ("outputModule".compareToIgnoreCase(configNode.getNodeName()) == 0) || ("#comment".compareToIgnoreCase(configNode.getNodeName()) == 0) || ("#text".compareToIgnoreCase(configNode.getNodeName()) == 0)) { continue; } else { log.warn("Got unknown node in config: " + configNode.getNodeName()); } } if (loggerName.equals("")) { log.warn("Softlogger name is blank"); } if (defaultScanRate <= 0) { log.warn("Softlogger default scan rate is invalid. Using default of 5000."); defaultScanRate = 5000; } //Load the data server loggerConfigNodes = rootNode.getOwnerDocument().getElementsByTagName("server"); if (loggerConfigNodes.getLength() == 0) { log.fatal("Could not find a server defined in the config file."); return false; } if (loggerConfigNodes.getLength() > 1) { log.fatal("Too many servers are defined in the config file"); return false; } Node currentConfigNode = loggerConfigNodes.item(0); server = new DataServer(); if (!server.configure(currentConfigNode)) { return false; } //Load the softloggerChannels loggerConfigNodes = rootNode.getOwnerDocument().getElementsByTagName("channel"); boolean workingChannel = false; for (int i = 0; i < loggerConfigNodes.getLength(); i++) { currentConfigNode = loggerConfigNodes.item(i); SoftloggerChannel mc = new SoftloggerChannel(); if (mc.configure(currentConfigNode)) { workingChannel = true; softloggerChannels.add(mc); } } if (!workingChannel) { log.fatal("No usable softloggerChannels configured"); return false; } for (int i = 0; i < softloggerChannels.size(); i++) { softloggerChannels.get(i).setDefaultScanRate(this.defaultScanRate); } ArrayList<Device> devices = new ArrayList<Device>(); for (SoftloggerChannel channel : softloggerChannels) { devices.addAll(channel.getDevices()); } //Load the global output modules currentConfigNode = rootNode.getOwnerDocument().getDocumentElement(); loggerConfigNodes = currentConfigNode.getChildNodes(); for (int i = 0; i < loggerConfigNodes.getLength(); i++) { currentConfigNode = loggerConfigNodes.item(i); if ("outputModule".compareToIgnoreCase(currentConfigNode.getNodeName()) != 0) { continue; } try { @SuppressWarnings("unchecked") Class<? extends OutputModule> outputClass = (Class<? extends OutputModule>) Class .forName(currentConfigNode.getAttributes().getNamedItem("class").getNodeValue()); OutputModule outputModule = outputClass.newInstance(); if (outputModule.configure(currentConfigNode)) { for (Device d : devices) { d.addOutputModule(outputModule.clone()); } } } catch (Exception e) { log.error("Got exception while loading output module: ", e); } } this.printAll(); return true; }
From source file:de.betterform.connector.ModelSubmissionHandler.java
/** * Purpose:<br/>/*from ww w . j a v a 2 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:lcmc.data.VMSXML.java
/** Modify xml of some device element. */ private void modifyXML(final Node domainNode, final String domainName, final Map<String, String> tagMap, final Map<String, String> attributeMap, final Map<String, String> parametersMap, final String path, final String elementName, final VirtualHardwareComparator vhc) { final String configName = namesConfigsMap.get(domainName); if (configName == null) { return;// w ww . j ava 2 s. c om } //final Node domainNode = getDomainNode(domainName); if (domainNode == null) { return; } final XPath xpath = XPathFactory.newInstance().newXPath(); final Node devicesNode = getDevicesNode(xpath, domainNode); if (devicesNode == null) { return; } try { final NodeList nodes = (NodeList) xpath.evaluate(path, domainNode, XPathConstants.NODESET); Element hwNode = vhc.getElement(nodes, parametersMap); if (hwNode == null) { hwNode = (Element) devicesNode .appendChild(domainNode.getOwnerDocument().createElement(elementName)); } for (final String param : parametersMap.keySet()) { final String value = parametersMap.get(param); if (!tagMap.containsKey(param) && attributeMap.containsKey(param)) { /* attribute */ final Node attributeNode = hwNode.getAttributes().getNamedItem(attributeMap.get(param)); if (attributeNode == null) { if (value != null && !"".equals(value)) { hwNode.setAttribute(attributeMap.get(param), value); } } else if (value == null || "".equals(value)) { hwNode.removeAttribute(attributeMap.get(param)); } else { attributeNode.setNodeValue(value); } continue; } Element node = (Element) getChildNode(hwNode, tagMap.get(param)); if ((attributeMap.containsKey(param) || "True".equals(value)) && node == null) { node = (Element) hwNode .appendChild(domainNode.getOwnerDocument().createElement(tagMap.get(param))); } else if (node != null && !attributeMap.containsKey(param) && (value == null || "".equals(value))) { hwNode.removeChild(node); } if (attributeMap.containsKey(param)) { final Node attributeNode = node.getAttributes().getNamedItem(attributeMap.get(param)); if (attributeNode == null) { if (value != null && !"".equals(value)) { node.setAttribute(attributeMap.get(param), value); } } else { if (value == null || "".equals(value)) { node.removeAttribute(attributeMap.get(param)); } else { attributeNode.setNodeValue(value); } } } } final Element hwAddressNode = (Element) getChildNode(hwNode, HW_ADDRESS); if (hwAddressNode != null) { hwNode.removeChild(hwAddressNode); } } catch (final javax.xml.xpath.XPathExpressionException e) { Tools.appError("could not evaluate: ", e); return; } }
From source file:lcmc.data.VMSXML.java
/** Modify xml of the domain. */ public Node modifyDomainXML(final String domainName, final Map<String, String> parametersMap) { final String configName = namesConfigsMap.get(domainName); if (configName == null) { return null; }//from w w w . jav a 2 s . c o m final Node domainNode = getDomainNode(domainName); if (domainNode == null) { return null; } final XPath xpath = XPathFactory.newInstance().newXPath(); final Map<String, String> paths = new HashMap<String, String>(); paths.put(VM_PARAM_MEMORY, "memory"); paths.put(VM_PARAM_CURRENTMEMORY, "currentMemory"); paths.put(VM_PARAM_VCPU, "vcpu"); paths.put(VM_PARAM_BOOTLOADER, "bootloader"); paths.put(VM_PARAM_BOOT, "os/boot"); paths.put(VM_PARAM_BOOT_2, "os/boot"); paths.put(VM_PARAM_TYPE, "os/type"); paths.put(VM_PARAM_TYPE_ARCH, "os/type"); paths.put(VM_PARAM_TYPE_MACHINE, "os/type"); paths.put(VM_PARAM_INIT, "os/init"); paths.put(VM_PARAM_LOADER, "os/loader"); paths.put(VM_PARAM_CPU_MATCH, "cpu"); paths.put(VM_PARAM_ACPI, "features"); paths.put(VM_PARAM_APIC, "features"); paths.put(VM_PARAM_PAE, "features"); paths.put(VM_PARAM_HAP, "features"); paths.put(VM_PARAM_ON_POWEROFF, "on_poweroff"); paths.put(VM_PARAM_ON_REBOOT, "on_reboot"); paths.put(VM_PARAM_ON_CRASH, "on_crash"); paths.put(VM_PARAM_EMULATOR, "devices/emulator"); final Document doc = domainNode.getOwnerDocument(); try { for (final String param : parametersMap.keySet()) { final String path = paths.get(param); if (path == null) { continue; } final NodeList nodes = (NodeList) xpath.evaluate(path, domainNode, XPathConstants.NODESET); Element node = (Element) nodes.item(0); if (node == null) { continue; } if (VM_PARAM_BOOT_2.equals(param)) { if (nodes.getLength() > 1) { node = (Element) nodes.item(1); } else { node = (Element) node.getParentNode().appendChild(doc.createElement(OS_BOOT_NODE)); } } String value = parametersMap.get(param); if (VM_PARAM_MEMORY.equals(param) || VM_PARAM_CURRENTMEMORY.equals(param)) { value = Long.toString(Tools.convertToKilobytes(value)); } if (VM_PARAM_CPU_MATCH.equals(param) || VM_PARAM_ACPI.equals(param) || VM_PARAM_APIC.equals(param) || VM_PARAM_PAE.equals(param) || VM_PARAM_HAP.equals(param)) { domainNode.removeChild(node); } else if (VM_PARAM_BOOT.equals(param)) { node.setAttribute(OS_BOOT_NODE_DEV, value); } else if (VM_PARAM_BOOT_2.equals(param)) { if (value == null || "".equals(value)) { node.getParentNode().removeChild(node); } else { node.setAttribute(OS_BOOT_NODE_DEV, value); } } else if (VM_PARAM_TYPE_ARCH.equals(param)) { node.setAttribute("arch", value); } else if (VM_PARAM_TYPE_MACHINE.equals(param)) { node.setAttribute("machine", value); } else if (VM_PARAM_CPU_MATCH.equals(param)) { if ("".equals(value)) { node.getParentNode().removeChild(node); } else { node.setAttribute("match", value); } } else if (VM_PARAM_CPUMATCH_TOPOLOGY_THREADS.equals(param)) { node.setAttribute("threads", value); } else { final Node n = getChildNode(node, "#text"); if (n == null) { node.appendChild(doc.createTextNode(value)); } else { n.setNodeValue(value); } } } addCPUMatchNode(doc, domainNode, parametersMap); addFeatures(doc, domainNode, parametersMap); } catch (final javax.xml.xpath.XPathExpressionException e) { Tools.appError("could not evaluate: ", e); return null; } return domainNode; }
From source file:de.betterform.xml.xforms.model.submission.Submission.java
/** * Performs replace processing according to section 11.1, para 5. *//*from w ww .j a v a 2s . co m*/ protected void submitReplaceText(Map response) throws XFormsException { if (getLogger().isDebugEnabled()) { getLogger().debug(this + " submit: replacing text"); } Node targetNode; if (this.targetExpr != null) { targetNode = XPathUtil .getAsNode( XPathCache.getInstance() .evaluate( this.instance == null ? evalInScopeContext() : this.model.getInstance(this.instance).getRootContext() .getNodeset(), 1, this.targetExpr, this.prefixMapping, this.xpathFunctionContext), 1); } else if (this.instance == null) { targetNode = this.model.getInstance(getInstanceId()).getInstanceDocument().getDocumentElement(); } else { targetNode = this.model.getInstance(this.instance).getInstanceDocument().getDocumentElement(); } final InputStream responseStream = (InputStream) response.get(XFormsProcessor.SUBMISSION_RESPONSE_STREAM); StringBuilder text = new StringBuilder(512); try { String contentType = (String) response.get("Content-Type"); String encoding = "UTF-8"; if (contentType != null) { final String[] contTypeEntries = contentType.split(", ?"); for (int i = 0; i < contTypeEntries.length; i++) { if (contTypeEntries[i].startsWith("charset=")) { encoding = contTypeEntries[i].substring(8); } } } byte[] buffer = new byte[512]; int bytesRead; while ((bytesRead = responseStream.read(buffer)) > 0) { text.append(new String(buffer, 0, bytesRead, encoding)); } responseStream.close(); } catch (Exception e) { // todo: check for response media type (needs submission response // refactoring) in order to dispatch xforms-link-exception throw new XFormsSubmitError("instance parsing failed", e, this.getTarget(), XFormsSubmitError.constructInfoObject(this.element, this.container, locationPath, XFormsConstants.PARSE_ERROR, getResourceURI(), 200d, null, "", "")); } if (targetNode == null) { throw new XFormsSubmitError("Invalid target", this.getTarget(), XFormsSubmitError.constructInfoObject(this.element, this.container, locationPath, XFormsConstants.TARGET_ERROR, getResourceURI(), 200d, null, "", "")); } else if (targetNode.getNodeType() == Node.ELEMENT_NODE) { while (targetNode.getFirstChild() != null) { targetNode.removeChild(targetNode.getFirstChild()); } targetNode.appendChild(targetNode.getOwnerDocument().createTextNode(text.toString())); } else if (targetNode.getNodeType() == Node.ATTRIBUTE_NODE) { targetNode.setNodeValue(text.toString()); } else { LOGGER.warn("Don't know how to handle targetNode '" + targetNode.getLocalName() + "', node is neither an element nor an attribute Node"); } // perform rebuild, recalculate, revalidate, and refresh this.model.rebuild(); this.model.recalculate(); this.model.revalidate(); this.container.refresh(); // deferred update behaviour UpdateHandler updateHandler = this.model.getUpdateHandler(); if (updateHandler != null) { updateHandler.doRebuild(false); updateHandler.doRecalculate(false); updateHandler.doRevalidate(false); updateHandler.doRefresh(false); } // dispatch xforms-submit-done this.container.dispatch(this.target, XFormsEventNames.SUBMIT_DONE, constructEventInfo(response)); }