Search in sources :

Example 6 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project Apktool by iBotPeaches.

the class ResXmlPatcher method removeManifestVersions.

/**
     * Removes attributes like "versionCode" and "versionName" from file.
     *
     * @param file File representing AndroidManifest.xml
     * @throws AndrolibException
     */
public static void removeManifestVersions(File file) throws AndrolibException {
    if (file.exists()) {
        try {
            Document doc = loadDocument(file);
            Node manifest = doc.getFirstChild();
            NamedNodeMap attr = manifest.getAttributes();
            Node vCode = attr.getNamedItem("android:versionCode");
            Node vName = attr.getNamedItem("android:versionName");
            if (vCode != null) {
                attr.removeNamedItem("android:versionCode");
            }
            if (vName != null) {
                attr.removeNamedItem("android:versionName");
            }
            saveDocument(file, doc);
        } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 7 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hadoop by apache.

the class QueueConfigurationParser method populateProperties.

/**
   * Populate the properties for Queue
   *
   * @param field
   * @return
   */
private Properties populateProperties(Element field) {
    Properties props = new Properties();
    NodeList propfields = field.getChildNodes();
    for (int i = 0; i < propfields.getLength(); i++) {
        Node prop = propfields.item(i);
        //skip this.
        if (!(prop instanceof Element)) {
            continue;
        }
        if (PROPERTY_TAG.equals(prop.getNodeName())) {
            if (prop.hasAttributes()) {
                NamedNodeMap nmp = prop.getAttributes();
                if (nmp.getNamedItem(KEY_TAG) != null && nmp.getNamedItem(VALUE_TAG) != null) {
                    props.setProperty(nmp.getNamedItem(KEY_TAG).getTextContent(), nmp.getNamedItem(VALUE_TAG).getTextContent());
                }
            }
        }
    }
    return props;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Properties(java.util.Properties)

Example 8 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hadoop by apache.

the class QueuePlacementRule method initializeFromXml.

public void initializeFromXml(Element el) throws AllocationConfigurationException {
    boolean create = true;
    NamedNodeMap attributes = el.getAttributes();
    Map<String, String> args = new HashMap<String, String>();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node node = attributes.item(i);
        String key = node.getNodeName();
        String value = node.getNodeValue();
        if (key.equals("create")) {
            create = Boolean.parseBoolean(value);
        } else {
            args.put(key, value);
        }
    }
    initialize(create, args);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) HashMap(java.util.HashMap) Node(org.w3c.dom.Node)

Example 9 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hackpad by dropbox.

the class XmlNode method getAttributes.

XmlNode[] getAttributes() {
    NamedNodeMap attrs = this.dom.getAttributes();
    //    TODO    Or could make callers handle null?
    if (attrs == null)
        throw new IllegalStateException("Must be element.");
    XmlNode[] rv = new XmlNode[attrs.getLength()];
    for (int i = 0; i < attrs.getLength(); i++) {
        rv[i] = createImpl(attrs.item(i));
    }
    return rv;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 10 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hackpad by dropbox.

the class XmlNode method addNamespaces.

private void addNamespaces(Namespaces rv, Element element) {
    if (element == null)
        throw new RuntimeException("element must not be null");
    String myDefaultNamespace = toUri(element.lookupNamespaceURI(null));
    String parentDefaultNamespace = "";
    if (element.getParentNode() != null) {
        parentDefaultNamespace = toUri(element.getParentNode().lookupNamespaceURI(null));
    }
    if (!myDefaultNamespace.equals(parentDefaultNamespace) || !(element.getParentNode() instanceof Element)) {
        rv.declare(Namespace.create("", myDefaultNamespace));
    }
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (attr.getPrefix() != null && attr.getPrefix().equals("xmlns")) {
            rv.declare(Namespace.create(attr.getLocalName(), attr.getValue()));
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Aggregations

NamedNodeMap (org.w3c.dom.NamedNodeMap)991 Node (org.w3c.dom.Node)688 NodeList (org.w3c.dom.NodeList)338 Attr (org.w3c.dom.Attr)295 Element (org.w3c.dom.Element)237 Document (org.w3c.dom.Document)153 ArrayList (java.util.ArrayList)92 HashMap (java.util.HashMap)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)59 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)58 IOException (java.io.IOException)53 SAXException (org.xml.sax.SAXException)41 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)40 List (java.util.List)36 Map (java.util.Map)33 File (java.io.File)27 InputStream (java.io.InputStream)26 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)25 DOMException (org.w3c.dom.DOMException)25 ByteArrayInputStream (java.io.ByteArrayInputStream)19