private String getNodeValueByTagName( Node node, String tagName ) { if ( node != null && node.getFirstChild() != null ) { return node.getFirstChild().getNodeValue(); } else { return null; } }
public static String getXmlNodeValue(Node node) { if (node.getNodeType() != Node.ELEMENT_NODE) { return null; } String ret = ""; NodeList textNodes = node.getChildNodes(); for (int i = 0; i < textNodes.getLength(); i++) { Node n = textNodes.item(i); if (n.getNodeType() == Node.TEXT_NODE && n.getNodeValue().replaceAll("[ \\n\\t\\r]", "").length() > 0) { ret += n.getNodeValue(); } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) { ret += n.getNodeValue(); } } return ret.length() == 0 ? null : ret.replaceAll("^\\s+", "").replaceAll("\\s+$", ""); }
private boolean isQueryable(Node layerNode) { NamedNodeMap attributes = layerNode.getAttributes(); Node q = attributes.getNamedItem("queryable"); if (q != null) { return "1".equals(q.getNodeValue()); } return false; }
private static void removeWhitespaceInner(Node n, Node parent) { // This n is removed from the parent if n is a whitespace node if (parent != null && n instanceof Text && (!(n instanceof CDATASection))) { Text t = (Text) n; if (t.getData().matches("[ \t\n]*")) { parent.removeChild(t); } } if (n.hasChildNodes()) { int length = n.getChildNodes().getLength(); List<Node> toBeProcessed = new ArrayList<Node>(); // We collect all the nodes to iterate as the child nodes will change // upon removal for (int i = 0; i < length; i++) { toBeProcessed.add(n.getChildNodes().item(i)); } // This changes the child nodes, but the iterator of nodes never changes // meaning that this is safe for (Node childNode : toBeProcessed) { removeWhitespaceInner(childNode, n); } } }
@Nullable private String getTextValue(@Nonnull final Node node) { Node child = node.getFirstChild(); if (child != null && child.getNodeType() == TEXT_NODE) { return child.getNodeValue(); } return null; }
protected void parse(Node node) { NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); String nodeName = child.getNodeName(); if ("Name".equalsIgnoreCase(nodeName)) { name = getValueRecursive(child); } else if ("Title".equalsIgnoreCase(nodeName)) { title = getValueRecursive(child); } else if ("Abstract".equalsIgnoreCase(nodeName)) { abstractt = getValueRecursive(child); } else if ("LegendURL".equalsIgnoreCase(nodeName)) { legendUrl = createLegendInfo(child); } } }
protected void parse(Node node) { NamedNodeMap attributes = node.getAttributes(); type = getValueRecursive(attributes.getNamedItem("type")); NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); String nodeName = child.getNodeName(); if ("Format".equalsIgnoreCase(nodeName)) { format = getValueRecursive(child); } else if ("OnlineResource".equalsIgnoreCase(nodeName)) { onlineResource = createOnlineResource(child); } } }
@Override @SuppressWarnings( { "cast", "unchecked" } ) protected Map<String, String> getAttributesAsMap( Element element ) { NamedNodeMap nodes = element.getAttributes(); int length = nodes.getLength(); if ( length == 0 ) { return (Map<String, String>) Collections.EMPTY_MAP; } Map<String, String> attributes = new HashMap<String, String>( length ); for ( int loop = 0; loop < length; loop++ ) { Node node = nodes.item( loop ); attributes.put( node.getNodeName(), node.getNodeValue() ); } return attributes; } }
protected double getAttributeAsDouble(Node node, String name) { Node attr = node.getAttributes().getNamedItem(name); return getValueRecursiveAsDouble(attr); }
@Override public String getText() { final StringBuilder result = new StringBuilder(); final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node child = nodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) result.append(child.getNodeValue()); } return result.toString(); }
LazyXmlParser(@Nonnull final Node entryNode) { assert "entry".equals(entryNode.getNodeName()); assert entryNode.getNodeType() == ELEMENT_NODE; this.entryNode = entryNode; }
protected boolean hasAttribute(Node node, String name) { return node.hasAttributes() && node.getAttributes().getNamedItem(name) != null; }
private List<Node> getNodesByTagName( Element element, String tagName ) { List<Node> nodes = new ArrayList<Node>(); NodeList list = element.getChildNodes(); for ( int i = 0; i < list.getLength(); i++ ) { Node node = list.item( i ); if ( node != null && node.getNodeName().equals( tagName ) ) { nodes.add( node ); } } return nodes; }
private boolean isLinkBelongToFeed(@Nonnull final Node node) { return node.getParentNode() != null && FEED_TAG.equals(node.getParentNode().getNodeName()); }
private void parseEntries(@Nonnull final Document document) { NodeList entryNodes = document.getElementsByTagName(ENTRY_TAG); if (entryNodes != null) { Node entryNode; for (int i = 0; i < entryNodes.getLength(); i++) { entryNode = entryNodes.item(i); assert entryNode != null; if (entryNode.getNodeType() == ELEMENT_NODE) { entries.add(new Entry(entryNodes.item(i))); } } Collections.reverse(entries); } } }
public ArrayList<String> getParameters(String name) { ArrayList<String> array = new ArrayList<String>(); if (hasProperty(name)) { NodeList nodes = this.properties.getElementsByTagName(name); for (int i = 0; i < nodes.getLength(); i++) { array.add(nodes.item(i).getFirstChild().toString()); } } return array; }
private void addLatLonBoundingBox(Node bboxNode) { NodeList childNodes = bboxNode.getChildNodes(); double x = 0, y = 0, maxx = 0, maxy = 0; for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); String nodeName = child.getNodeName(); if ("westBoundLongitude".equalsIgnoreCase(nodeName)) { x = getValueRecursiveAsDouble(child); } else if ("eastBoundLongitude".equalsIgnoreCase(nodeName)) { maxx = getValueRecursiveAsDouble(child); } else if ("southBoundLatitude".equalsIgnoreCase(nodeName)) { y = getValueRecursiveAsDouble(child); } else if ("northBoundLatitude".equalsIgnoreCase(nodeName)) { maxy = getValueRecursiveAsDouble(child); } } latlonBoundingBox = new Bbox(x, y, maxx - x, maxy - y); } }
protected void parse(Node node) { NamedNodeMap attributes = node.getAttributes(); width = getValueRecursiveAsInteger(attributes.getNamedItem("width")); height = getValueRecursiveAsInteger(attributes.getNamedItem("height")); NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); String nodeName = child.getNodeName(); if ("Format".equalsIgnoreCase(nodeName)) { format = getValueRecursive(child); } else if ("OnlineResource".equalsIgnoreCase(nodeName)) { onlineResource = createOnlineResource(child); } } }
private static void removeWhitespaceInner(Node n, Node parent) { // This n is removed from the parent if n is a whitespace node if (parent != null && n instanceof Text && (!(n instanceof CDATASection))) { Text t = (Text) n; if (t.getData().matches("[ \t\n]*")) { parent.removeChild(t); } } if (n.hasChildNodes()) { int length = n.getChildNodes().getLength(); List<Node> toBeProcessed = new ArrayList<Node>(); // We collect all the nodes to iterate as the child nodes will change // upon removal for (int i = 0; i < length; i++) { toBeProcessed.add(n.getChildNodes().item(i)); } // This changes the child nodes, but the iterator of nodes never changes // meaning that this is safe for (Node childNode : toBeProcessed) { removeWhitespaceInner(childNode, n); } } }
public IDatabaseConnection convertToObject( String xml ) { Document document = XMLParser.parse( xml ); Element element = document.getDocumentElement(); IDatabaseConnection databaseConnection = new DatabaseConnection(); databaseConnection.setDatabaseName( getNodeValueByTagName( element, DATABASE_NAME ) ); databaseConnection.setHostname( getNodeValueByTagName( element, HOSTNAME ) ); databaseConnection.setIndexTablespace( getNodeValueByTagName( element, INDEX_TABLESPACE ) ); databaseConnection.setDataTablespace( getNodeValueByTagName( element, DATA_TABLESPACE ) ); databaseConnection.setName( getNodeValueByTagName( element, NAME ) ); databaseConnection.setUsername( getNodeValueByTagName( element, USERNAME ) ); databaseConnection.setPassword( getNodeValueByTagName( element, PASSWORD ) ); databaseConnection.setDatabasePort( getNodeValueByTagName( element, DATABASE_PORT ) ); databaseConnection .setAccessType( DatabaseAccessType.getAccessTypeByName( getNodeValueByTagName( element, ACCESS_TYPE ) ) ); databaseConnection.setDatabaseType( (DatabaseType) databaseTypeHelper.getDatabaseTypeByShortName( getNodeValueByTagName( element, DATABASE_TYPE ) ) ); databaseConnection.setPassword( getNodeValueByTagName( element, PASSWORD ) ); databaseConnection.setInformixServername( getNodeValueByTagName( element, SERVER_NAME ) ); for ( Node node : getNodesByTagName( element, ATTRIBUTES ) ) { databaseConnection.getAttributes().put( node.getNodeName(), node.getNodeValue() ); } return databaseConnection; }