List of usage examples for org.w3c.dom DOMException NOT_FOUND_ERR
short NOT_FOUND_ERR
To view the source code for org.w3c.dom DOMException NOT_FOUND_ERR.
Click Source Link
Node
in a context where it does not exist. From source file:Main.java
public static String getAttr(Node node, String name) throws DOMException { assert node != null; try {/*from w w w . j av a 2 s. c om*/ NamedNodeMap attributes = node.getAttributes(); if (attributes == null) throw new Exception(""); Node attr = attributes.getNamedItem(name); if (attr == null) throw new Exception(""); String value = attr.getNodeValue(); if (value == null) throw new Exception(""); return value; } catch (Exception e) { throw new DOMException(DOMException.NOT_FOUND_ERR, String.format("attribute %s is missing at node %s", name, node.getNodeName())); } }
From source file:org.carewebframework.shell.BaseXmlParser.java
/** * Parses an xml extension from an xml string. * //from w w w .j av a2 s.co m * @param xml XML containing the extension. * @param tagName The top level tag name. * @return Result of the parsed extension. * @throws Exception Unspecified exception. */ protected Object fromXml(String xml, String tagName) throws Exception { Document document = XMLUtil.parseXMLFromString(xml); NodeList nodeList = document.getElementsByTagName(tagName); if (nodeList == null || nodeList.getLength() != 1) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Top level tag '" + tagName + "' was not found."); } Element element = (Element) nodeList.item(0); Class<?> beanClass = getBeanClass(element); BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(beanClass); doParse(element, builder); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.setParentBeanFactory(SpringUtil.getAppContext()); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); factory.registerBeanDefinition(tagName, beanDefinition); return factory.getBean(tagName); }
From source file:fi.csc.kapaVirtaAS.MessageTransformer.java
public String transform(String message, MessageDirection direction) throws Exception { try {/* ww w. j a va 2 s . c o m*/ DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = dBuilder .parse(new InputSource(new ByteArrayInputStream(stripXmlDefinition(message).getBytes()))); doc.setXmlVersion("1.0"); doc.normalizeDocument(); Element root = doc.getDocumentElement(); if (direction == MessageDirection.XRoadToVirta) { // Save XRoad schema prefix for response message xroadSchemaPrefix = namedNodeMapToStream(root.getAttributes()) .filter(node -> node .getNodeValue().toLowerCase().contains(conf.getXroadSchema().toLowerCase())) .findFirst() .orElseThrow( () -> new DOMException(DOMException.NOT_FOUND_ERR, "Xroad schema prefix not found")) .getNodeName(); xroadIdSchemaPrefix = namedNodeMapToStream(root.getAttributes()) .filter(node -> node.getNodeValue().toLowerCase() .contains(conf.getXroadIdSchema().toLowerCase())) .findFirst().orElseThrow(() -> new DOMException(DOMException.NOT_FOUND_ERR, "XroadId schema prefix not found")) .getNodeName(); // Change tns schema getNodeByKeyword(namedNodeMapToStream(root.getAttributes()), conf.getAdapterServiceSchema()) .map(attribute -> setNodeValueToNode(attribute, conf.getVirtaServiceSchema())); //There should be two children under the root node: header and body for (int i = 0; i < root.getChildNodes().getLength(); ++i) { Node child = root.getChildNodes().item(i); // Save soap-headers for reply message and remove child elements under soap-headers if (child.getNodeName().toLowerCase().contains("header")) { this.xroadHeaderElement = child.cloneNode(true); root.replaceChild(child.cloneNode(false), child); } // Change SOAP-body else if (child.getNodeName().toLowerCase().contains("body")) { for (int j = 0; j < child.getChildNodes().getLength(); ++j) { if (child.getChildNodes().item(j).getNodeType() == Node.ELEMENT_NODE) { doc.renameNode(child.getChildNodes().item(j), conf.getVirtaServiceSchema(), child.getChildNodes().item(j).getNodeName() + "Request"); break; } } } } } if (direction == MessageDirection.VirtaToXRoad) { // Add XRoad schemas with saved prefix to response message root.setAttribute(xroadSchemaPrefix, conf.getXroadSchema()); root.setAttribute(xroadIdSchemaPrefix, conf.getXroadIdSchema()); // Change tns schema getNodeByKeyword(namedNodeMapToStream(root.getAttributes()), conf.getVirtaServiceSchema()) .map(attribute -> setNodeValueToNode(attribute, conf.getAdapterServiceSchema())); // Change SOAP-headers Node headerNode = getNodeByKeyword(nodeListToStream(root.getChildNodes()), "header").get(); for (int i = 0; i < this.xroadHeaderElement.getChildNodes().getLength(); ++i) { headerNode.appendChild(doc.importNode(this.xroadHeaderElement.getChildNodes().item(i), true)); } // Change SOAP-body getNodeByKeyword(nodeListToStream(root.getChildNodes()), "body") .map(bodyNode -> removeAttribureFromElement(nodeToElement(bodyNode), virtaServicePrefix)) .map(bodyNode -> setAttributeToElement(nodeToElement(bodyNode), virtaServicePrefix, conf.getAdapterServiceSchema())); //Virta gives malformed soap fault message. Need to parse it correct. getNodeByKeyword(nodeListToStream(root.getChildNodes()), "body") .map(bodyNode -> nodeListToStream(bodyNode.getChildNodes())).map( nodesInBodyStream -> getNodeByKeyword(nodesInBodyStream, "fault") .map(faultNode -> removeAttribureFromElement( nodeToElement(nodeToElement(faultNode) .getElementsByTagName("faultstring").item(0)), "xml:lang"))); } doc.normalizeDocument(); DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, result); message = writer.toString(); return stripXmlDefinition(message); } catch (Exception e) { if (direction == MessageDirection.XRoadToVirta) { log.error("Error in parsing request message."); throw e; } else { log.error("Error in parsing response message"); log.error(e.toString()); return stripXmlDefinition(faultMessageService.generateSOAPFault(message, faultMessageService.getResValidFail(), this.xroadHeaderElement)); } } }
From source file:de.betterform.xml.xforms.XFormsProcessorImpl.java
/** * returns the DOM Document of the XForms Instance identified by id. * @param id identifier for Instance/*from www. ja va2 s. c om*/ * @return the DOM Document of the XForms Instance identified by id * @throws DOMException in case the processor was not intialized or the wanted Instance does not exist */ public Document getInstanceDocument(String id) throws DOMException { try { ensureContainerInitialized(); } catch (XFormsException e) { throw new DOMException(DOMException.INVALID_STATE_ERR, "Processor is not intialized"); } List models = container.getModels(); Document instance = null; for (int i = 0; i < models.size(); i++) { Model model = (Model) models.get(i); instance = model.getInstanceDocument(id); if (instance != null) { return instance; } } throw new DOMException(DOMException.NOT_FOUND_ERR, "Instance with id: '" + id + "' not found"); }
From source file:de.betterform.xml.xforms.model.Model.java
/** * 7.3.1 The getInstanceDocument() Method. * <p/>//from w w w .j a v a2 s .com * This method returns a DOM Document that corresponds to the instance data * associated with the <code>instance</code> element containing an * <code>ID</code> matching the <code>instance-id</code> parameter. If there * is no matching instance data, a <code>DOMException</code> is thrown. * * @param instanceID the instance id. * @return the corresponding DOM document. * @throws DOMException if there is no matching instance data. */ public Document getInstanceDocument(String instanceID) throws DOMException { Instance instance = getInstance(instanceID); if (instance == null) { throw new DOMException(DOMException.NOT_FOUND_ERR, instanceID); } return instance.getInstanceDocument(); }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * __UNDOCUMENTED__/*from w ww . j a va 2 s. com*/ * * @param newChild __UNDOCUMENTED__ * @param refChild __UNDOCUMENTED__ * @throws DOMException __UNDOCUMENTED__ */ public static void insertAfter(Node newChild, Node refChild) throws DOMException { if (refChild == null) { throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild == null"); } Node nextSibling = refChild.getNextSibling(); if (nextSibling == null) { refChild.getParentNode().appendChild(newChild); } else { refChild.getParentNode().insertBefore(newChild, nextSibling); } }
From source file:com.gargoylesoftware.htmlunit.html.DomNode.java
/** * {@inheritDoc}//w ww.j a va 2 s . c o m */ public Node insertBefore(final Node newChild, final Node refChild) { if (refChild == null) { appendChild(newChild); } else { if (refChild.getParentNode() != this) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Reference node is not a child of this node."); } ((DomNode) refChild).insertBefore((DomNode) newChild); } return null; }
From source file:com.gargoylesoftware.htmlunit.html.DomNode.java
/** * {@inheritDoc}/*from w ww .j a v a 2 s. c o m*/ */ public Node removeChild(final Node child) { if (child.getParentNode() != this) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Node is not a child of this node."); } ((DomNode) child).remove(); return child; }
From source file:org.structr.web.entity.dom.DOMNode.java
protected void checkIsChild(Node otherNode) throws DOMException { if (otherNode instanceof DOMNode) { Node _parent = otherNode.getParentNode(); if (!isSameNode(_parent)) { throw new DOMException(DOMException.NOT_FOUND_ERR, NOT_FOUND_ERR_MESSAGE); }//from w ww. j av a 2s. c om // validation successful return; } throw new DOMException(DOMException.NOT_SUPPORTED_ERR, NOT_SUPPORTED_ERR_MESSAGE); }
From source file:com.gargoylesoftware.htmlunit.html.DomNode.java
/** * {@inheritDoc}/* ww w .ja va 2s.c om*/ */ public Node replaceChild(final Node newChild, final Node oldChild) { if (oldChild.getParentNode() != this) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Node is not a child of this node."); } ((DomNode) oldChild).replace((DomNode) newChild); return oldChild; }