List of usage examples for org.w3c.dom Node ATTRIBUTE_NODE
short ATTRIBUTE_NODE
To view the source code for org.w3c.dom Node ATTRIBUTE_NODE.
Click Source Link
Attr
. From source file:com.cellngine.util.FXMLValidator.java
private void checkAttributeNode(final Node node, final String parentName) throws InvalidFXMLException { final String nodeName = node.getNodeName(); final String nodeValue = node.getNodeValue(); if (node.getNodeType() == Node.ATTRIBUTE_NODE) { if (nodeName.equals("fx:factory")) { if (!nodeValue.equals("observableArrayList")) { throw new InvalidFXMLException("fx:factory \"" + nodeValue + "\" not allowed"); }//from w ww.j a v a2s . c om } else if (!ALLOWED_ELEMENTS.isAttributeAllowed(parentName, node.getNodeName())) { throw new InvalidFXMLException("Attribute \"" + node.getNodeName() + "\" on element type \"" + parentName + "\" not allowed"); } } else { throw new InvalidFXMLException("Node " + node.getNodeName() + " is not an attribute."); } }
From source file:com.jaspersoft.studio.data.xml.XMLDataAdapterDescriptor.java
private void findDirectChildrenAttributes(Node node, LinkedHashMap<String, JRDesignField> fieldsMap, String prefix) {//from w w w .j a v a 2 s. c om NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (item.getNodeType() == Node.ATTRIBUTE_NODE) { addNewField(item.getNodeName(), fieldsMap, item, prefix); } } } }
From source file:org.gvnix.dynamic.configuration.roo.addon.config.XmlDynamicConfiguration.java
/** * The node is a valid type to be generated as dynamic property ? * <p>//from w ww.j av a 2 s . c o m * TEXT_NODE, TEXT_NODE and ATTRIBUTE_NODE nodes are valid. * </p> * * @param node Node to check * @return Has valid format */ protected boolean isValidNode(Node node) { short type = node.getNodeType(); if (type == Node.ELEMENT_NODE || type == Node.TEXT_NODE || type == Node.ATTRIBUTE_NODE) { return true; } return false; }
From source file:Main.java
/** * Generates XPath expression with the option of the Node values appended * * @param node the Node whose XPath is to be found * @param parentXPath the XPath of the parent Node * @param ignoreWhitespace the flag to indicate if Whitespace will be ignored * @param includeValues the flag to indicate if Node values will be included * @param noIndex the flag to indicate if Node indexes are included * @return the XPath string representation of the Node *///from ww w . j a v a2s .c o m public static String generateXPath(Node node, String parentXPath, boolean ignoreWhitespace, boolean includeValues, boolean noIndex) { boolean noValues = !includeValues; if (node == null) return ""; Node parent = node.getParentNode(); int index = noIndex ? 0 : getXPathNodeIndex(node, ignoreWhitespace); String indexStr = ""; if (index > 0) indexStr = "[" + Integer.toString(index) + "]"; if (node.getNodeType() == Node.DOCUMENT_NODE) { // return only the blank String, since all the other types are preceded with / return parentXPath + ""; } else if (node.getNodeType() == Node.TEXT_NODE) { return parentXPath + (noValues ? "/" + node.getNodeValue() + indexStr : "/TEXT(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.ELEMENT_NODE) { return parentXPath + "/" + node.getNodeName() + indexStr; } else if (node.getNodeType() == Node.COMMENT_NODE) { return parentXPath + (noValues ? "/" + node.getNodeValue() + indexStr : "/COMMENT(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) { return parentXPath + (noValues ? "/" + node.getNodeValue() + indexStr : "/EntityReference(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return parentXPath + (noValues ? "/" + node.getNodeValue() + indexStr : "/PI(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return parentXPath + "/[@" + node.getNodeName() + (noValues ? "" : "=" + node.getNodeValue()) + "]"; } else if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) { return parentXPath + (noValues ? "/" + node.getNodeValue() : "/DOCTYPE(" + node.getNodeName() + ")"); } else if (node.getNodeType() == Node.CDATA_SECTION_NODE) { return parentXPath + (noValues ? "/" + node.getNodeValue() : "/CDATA(" + node.getNodeName() + ")"); } // Wont reach this far but just in case return ""; }
From source file:DOMUtils.java
/** * Given a prefix and a node, return the namespace URI that the prefix * has been associated with. This method is useful in resolving the * namespace URI of attribute values which are being interpreted as * QNames. If prefix is null, this method will return the default * namespace.// w w w. ja v a 2s . c o m * * @param context the starting node (looks up recursively from here) * @param prefix the prefix to find an xmlns:prefix=uri for * * @return the namespace URI or null if not found */ public static String getNamespaceURIFromPrefix(Node context, String prefix) { short nodeType = context.getNodeType(); Node tempNode = null; switch (nodeType) { case Node.ATTRIBUTE_NODE: { tempNode = ((Attr) context).getOwnerElement(); break; } case Node.ELEMENT_NODE: { tempNode = context; break; } default: { tempNode = context.getParentNode(); break; } } while (tempNode != null && tempNode.getNodeType() == Node.ELEMENT_NODE) { Element tempEl = (Element) tempNode; String namespaceURI = (prefix == null) ? getAttribute(tempEl, "xmlns") : getAttributeNS(tempEl, NS_URI_XMLNS, prefix); if (namespaceURI != null) { return namespaceURI; } else { tempNode = tempEl.getParentNode(); } } return null; }
From source file:com.jaspersoft.studio.data.xml.XMLDataAdapterDescriptor.java
private void findChildFields(NodeList nodes, LinkedHashMap<String, JRDesignField> fieldsMap, String prefix) { if (nodes != null) { List<String> childrenNames = new ArrayList<String>(); // temp list // to avoid // duplicates // at the // same//from w w w . ja v a2 s . c o m // level for (int i = 0; i < nodes.getLength(); i++) { Node item = nodes.item(i); String nodeName = item.getNodeName(); if ((item.getNodeType() == Node.ELEMENT_NODE || item.getNodeType() == Node.ATTRIBUTE_NODE) && !childrenNames.contains(nodeName)) { if (recursiveFind) { findDirectChildrenAttributes(item, fieldsMap, prefix + nodeName + "/"); } if (considerEmptyNodes || StringUtils.isNotBlank(DOMUtil.getChildText(item))) { addNewField(nodeName, fieldsMap, item, prefix); } if (recursiveFind && item.hasChildNodes()) { findChildFields(item.getChildNodes(), fieldsMap, prefix + nodeName + "/"); } } } } }
From source file:com.gatf.executor.validator.ResponseValidator.java
public static String getXMLNodeValue(Node node) { String xmlValue = null;// w w w. java2 s.c om if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { xmlValue = node.getNodeValue(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { xmlValue = ((Attr) node).getValue(); } else if (node.getNodeType() == Node.ELEMENT_NODE && node.getChildNodes().getLength() >= 1 && (node.getFirstChild().getNodeType() == Node.TEXT_NODE || node.getFirstChild().getNodeType() == Node.CDATA_SECTION_NODE)) { xmlValue = node.getFirstChild().getNodeValue(); } return xmlValue; }
From source file:com.dinochiesa.edgecallouts.EditXmlNode.java
private void insertBefore(NodeList nodes, Node newNode, short newNodeType) { Node currentNode = nodes.item(0); switch (newNodeType) { case Node.ATTRIBUTE_NODE: Element parent = ((Attr) currentNode).getOwnerElement(); parent.setAttributeNode((Attr) newNode); break;// ww w .j a va 2s . c o m case Node.ELEMENT_NODE: currentNode.getParentNode().insertBefore(newNode, currentNode); break; case Node.TEXT_NODE: String v = currentNode.getNodeValue(); currentNode.setNodeValue(newNode.getNodeValue() + v); break; } }
From source file:cc.siara.csv_ml_demo.MainActivity.java
/** * Evaluates given XPath from Input box against Document generated by * parsing csv_ml in input box and sets value or node list to output box. *///from ww w.j a va 2 s. c om void processXPath() { EditText etInput = (EditText) findViewById(R.id.etInput); EditText etXPath = (EditText) findViewById(R.id.etXPath); CheckBox cbPretty = (CheckBox) findViewById(R.id.cbPretty); XPath xpath = XPathFactory.newInstance().newXPath(); MultiLevelCSVParser parser = new MultiLevelCSVParser(); Document doc = null; try { doc = parser.parseToDOM(new StringReader(etInput.getText().toString()), false); } catch (IOException e1) { e1.printStackTrace(); } if (doc == null) return; StringBuffer out_str = new StringBuffer(); try { XPathExpression expr = xpath.compile(etXPath.getText().toString()); try { Document outDoc = Util.parseXMLToDOM("<output></output>"); Element rootElement = outDoc.getDocumentElement(); NodeList ret = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < ret.getLength(); i++) { Object o = ret.item(i); if (o instanceof String) { out_str.append(o); } else if (o instanceof Node) { Node n = (Node) o; short nt = n.getNodeType(); switch (nt) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.CDATA_SECTION_NODE: // Only one value gets // evaluated? if (out_str.length() > 0) out_str.append(','); if (nt == Node.ATTRIBUTE_NODE) out_str.append(n.getNodeValue()); else out_str.append(n.getTextContent()); break; case Node.ELEMENT_NODE: rootElement.appendChild(outDoc.importNode(n, true)); break; } } } if (out_str.length() > 0) { rootElement.setTextContent(out_str.toString()); out_str.setLength(0); } out_str.append(Util.docToString(outDoc, true)); } catch (Exception e) { // Thrown most likely because the given XPath evaluates to a // string out_str.append(expr.evaluate(doc)); } } catch (XPathExpressionException e) { e.printStackTrace(); } if (out_str.length() > 5 && out_str.substring(0, 5).equals("<?xml")) out_str.delete(0, out_str.indexOf(">") + 1); EditText etOutput = (EditText) findViewById(R.id.etOutput); etOutput.setText(out_str.toString()); // tfOutputSize.setText(String.valueOf(xmlString.length())); }
From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java
@SuppressWarnings("restriction") protected ContentAssistRequest computeDozerClassContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { int offset = nodeAtOffset.getStartOffset(); int len = nodeAtOffset.getLength(); if (nodeAtOffset.getNodeType() == Node.ATTRIBUTE_NODE) { offset += nodeAtOffset.getNodeName().length() + 2; len -= nodeAtOffset.getNodeName().length() + 3; }/*from w ww . j a va 2 s . c o m*/ ContentAssistRequest contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, offset, len, matchString); IContentAssistProposalRecorder recorder = new DefaultContentAssistProposalRecorder(contentAssistRequest); IContentAssistContext context = new DefaultContentAssistContext(contentAssistRequest, "xyz", //@TODO matchString); BeansJavaCompletionUtils.addClassValueProposals(context, recorder, BeansJavaCompletionUtils.FLAG_PACKAGE | BeansJavaCompletionUtils.FLAG_CLASS | BeansJavaCompletionUtils.FLAG_INTERFACE); convertProposals(contentAssistRequest.getProposals()); return contentAssistRequest; }