private List<String> extractUsesPermissionNames(NodeList usesPermissionNodes) { List<String> usesPermissionQualifiedNames = new ArrayList<>(); for (int i = 0; i < usesPermissionNodes.getLength(); i++) { Node usesPermissionNode = usesPermissionNodes.item(i); Node nameAttribute = usesPermissionNode.getAttributes().getNamedItem("android:name"); if (nameAttribute == null) { return null; } usesPermissionQualifiedNames.add(nameAttribute.getNodeValue()); } return usesPermissionQualifiedNames; }
private static String extractNameAttribute(Node node) { return node.getAttributes().getNamedItem("name").getNodeValue(); }
public static Node getAttribute(Node node, String name) { return node.getAttributes().getNamedItem(name); }
@Override public int compare(Node o1, Node o2) { NamedNodeMap attributes1 = o1.getAttributes(); NamedNodeMap attributes2 = o2.getAttributes(); if (attributes1 == null) { return 1; } else if (attributes2 == null) { return -1; } else if (MO_TAB.equals(o1.getNodeName()) && !MO_TAB.equals(o2.getNodeName())) { return -1; } else if (!MO_TAB.equals(o1.getNodeName()) && MO_TAB.equals(o2.getNodeName())) { return 1; } else if (MO_GROUP.equals(o1.getNodeName()) && !MO_GROUP.equals(o2.getNodeName())) { if (MO_TAB.equals(o1.getNodeName()) && MO_TAB.equals(o2.getNodeName())) { id1 = attributes1.getNamedItem(TAB_NAME); id2 = attributes2.getNamedItem(TAB_NAME); } else if (MO_GROUP.equals(o1.getNodeName()) && MO_GROUP.equals(o2.getNodeName())) { id1 = attributes1.getNamedItem(GROUP_NAME); id2 = attributes2.getNamedItem(GROUP_NAME); } else { return -1; String idVal1 = id1.getNodeValue(); String idVal2 = id2.getNodeValue(); return idVal1.compareTo(idVal2);
protected void processLogLevels(Document doc) { NodeList nodeList = doc.getElementsByTagName(LEVEL); Map menuItems = _monitor.getLogLevelMenuItems(); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); NamedNodeMap map = n.getAttributes(); String name = getValue(map, NAME); try { JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItems.get(LogLevel.valueOf(name)); item.setSelected(getValue(map, SELECTED).equalsIgnoreCase("true")); } catch (LogLevelFormatException e) { // ignore it will be on by default. } } }
private static HashMap<String, String> parseNodeAttributes(Node node) { final NamedNodeMap attributes = node.getAttributes(); final int attrCount = attributes.getLength(); final HashMap<String, String> receiverAttrs = new HashMap<>(attributes.getLength()); for (int i = 0; i < attrCount; i++) { Node attribute = attributes.item(i); String value = attribute.getNodeValue(); if (value != null) { receiverAttrs.put(attribute.getNodeName(), value); } } return receiverAttrs; }
/** * Removes "debug" tag from file * * @param file AndroidManifest file * @throws AndrolibException */ public static void removeApplicationDebugTag(File file) throws AndrolibException { if (file.exists()) { try { Document doc = loadDocument(file); Node application = doc.getElementsByTagName("application").item(0); // load attr NamedNodeMap attr = application.getAttributes(); Node debugAttr = attr.getNamedItem("android:debuggable"); // remove application:debuggable if (debugAttr != null) { attr.removeNamedItem("android:debuggable"); } saveDocument(file, doc); } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) { } } }
/** * Helper function that throws an exception when the attribute is not set. * * @param elementNode that should have the attribute * @param attrName that is to be looked up * @return value of the attribute * @throws IllegalArgumentException if the attribute is not present */ public static String getAttributeValue(final Node elementNode, final String attrName) { final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName); if (attrNode == null || "".equals(attrNode.getNodeValue())) { throw new IllegalStateException( "Element '" + elementNode.getNodeName() + "' has empty or missing attribute: " + attrName); } return attrNode.getNodeValue(); }
protected void processRecordFilter(Document doc) { NodeList nodeList = doc.getElementsByTagName(NDCTEXTFILTER); // there is only one value stored Node n = nodeList.item(0); // add check for backwards compatibility as this feature was added in // version 1.2 if (n == null) { return; } NamedNodeMap map = n.getAttributes(); String text = getValue(map, NAME); if (text == null || text.equals("")) { return; } _monitor.setNDCLogRecordFilter(text); }
/** * Get all the attributes in a certain node (on the root level) * * @param node * The node to examine * @return an array of strings containing the names of the attributes. */ public static String[] getNodeAttributes( Node node ) { NamedNodeMap nnm = node.getAttributes(); if ( nnm != null ) { String[] attributes = new String[nnm.getLength()]; for ( int i = 0; i < nnm.getLength(); i++ ) { Node attr = nnm.item( i ); attributes[i] = attr.getNodeName(); } return attributes; } return null; }
private void populateAttributes(Node node, Object object) throws XPathExpressionException { for (int j = 0; j < node.getAttributes().getLength(); j++) { Node item = node.getAttributes().item(j); setProperty(object, item.getLocalName(), item.getNodeValue()); } }
private void parseUsedPermissions(Document manifestDocument) { NodeList elementsByTagName = manifestDocument.getElementsByTagName("uses-permission"); int length = elementsByTagName.getLength(); for (int i = 0; i < length; i++) { Node node = elementsByTagName.item(i).getAttributes().getNamedItem("android:name"); usedPermissions.add(node.getNodeValue()); } }
String resourceType = node.getNodeName(); if (resourceType.equals(ITEM_TAG)) { resourceType = node.getAttributes().getNamedItem("type").getNodeValue(); if (resourceType.equals("id")) { resourceCollector.addIgnoreId(node.getAttributes().getNamedItem("name").getNodeValue());
protected void processCategories(Document doc) { CategoryExplorerTree tree = _monitor.getCategoryExplorerTree(); CategoryExplorerModel model = tree.getExplorerModel(); NodeList nodeList = doc.getElementsByTagName(CATEGORY); // determine where the starting node is NamedNodeMap map = nodeList.item(0).getAttributes(); int j = (getValue(map, NAME).equalsIgnoreCase(FIRST_CATEGORY_NAME)) ? 1 : 0; // iterate backwards throught the nodeList so that expansion of the // list can occur for (int i = nodeList.getLength() - 1; i >= j; i--) { Node n = nodeList.item(i); map = n.getAttributes(); CategoryNode chnode = model.addCategory(new CategoryPath(getValue(map, PATH))); chnode.setSelected((getValue(map, SELECTED).equalsIgnoreCase("true")) ? true : false); if (getValue(map, EXPANDED).equalsIgnoreCase("true")) ; tree.expandPath(model.getTreePathToRoot(chnode)); } }
/** * Fetches the value of a given attribute */ public static String getAttributeValue(Node node, String attributeName) { try { return node.getAttributes().getNamedItem(attributeName).getNodeValue(); } catch (Exception e) { } return null; }
private static String nodeToString(Node node, boolean isNoChild) { StringBuilder stringBuilder = new StringBuilder(); if (node != null) { stringBuilder.append(node.getNodeName()); NamedNodeMap namedNodeMap = node.getAttributes(); stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_LEFT); int namedNodeMapLength = namedNodeMap.getLength(); for (int j = 0; j < namedNodeMapLength; j++) { Node attributeNode = namedNodeMap.item(j); stringBuilder.append(Constant.Symbol.AT + attributeNode.getNodeName() + Constant.Symbol.EQUAL + attributeNode.getNodeValue()); if (j < namedNodeMapLength - 1) { stringBuilder.append(Constant.Symbol.COMMA); } } stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_RIGHT); String value = StringUtil.nullToBlank(isNoChild ? node.getTextContent() : node.getNodeValue()).trim(); if (StringUtil.isNotBlank(value)) { stringBuilder.append(Constant.Symbol.EQUAL + value); } } return stringBuilder.toString(); }
/** * Replaces the node's attributes with the attributes in the given hashmap * * @param node XML node that should be edited * @param attributes HashMap of strings representing the attributes of a node (key = value) * @return The given node with ONLY the given attributes */ private static Node rewriteNodeAttributes(Node node, HashMap<String, String> attributes) { NamedNodeMap nodeAttrs = node.getAttributes(); // Remove all previous attributes while (nodeAttrs.getLength() > 0) { nodeAttrs.removeNamedItem(nodeAttrs.item(0).getNodeName()); } // Set to new attributes for (String key : attributes.keySet()) { ((Element) node).setAttribute(key, attributes.get(key)); } return node; }
private @Nullable String getAttributeValue(Node parentNode, String attributeName) { Node attributeNode = parentNode.getAttributes().getNamedItem(attributeName); return attributeNode == null ? null : attributeNode.getTextContent(); }
private void populateAttributes(Node node, Object object) { for (int j = 0; j < node.getAttributes().getLength(); j++) { Node item = node.getAttributes().item(j); p(node.getAttributes().item(j).toString()); setProperty(object, item.getLocalName(), item.getNodeValue()); } }
private static String getTagAttributeText(final Document doc, final String tag, final String attribute) { NodeList elementsByTagName = doc.getElementsByTagName(tag); for (int i = 0; i < elementsByTagName.getLength(); ++i) { Node item = elementsByTagName.item(i); Node namedItem = item.getAttributes().getNamedItem(attribute); if (namedItem != null) { return namedItem.getTextContent(); } } return null; }