Search in sources :

Example 66 with Attr

use of org.w3c.dom.Attr in project aries by apache.

the class Parser method getNamespaceForAttributeValue.

/**
     * Takes an Attribute Node containing a namespace prefix qualified attribute value, and resolves the namespace using the DOM Node.<br> 
     *  
     * @param attrNode The DOM Node with the qualified attribute value.
     * @return The URI if one is resolvable, or null if the attr is null, or not namespace prefixed. (or not a DOM Attribute Node)
     * @throws ComponentDefinitionException if the namespace prefix in the attribute value cannot be resolved.
     */
private URI getNamespaceForAttributeValue(Node attrNode) throws ComponentDefinitionException {
    URI uri = null;
    if (attrNode != null && (attrNode instanceof Attr)) {
        Attr attr = (Attr) attrNode;
        String attrValue = attr.getValue();
        if (attrValue != null && attrValue.indexOf(":") != -1) {
            String[] parts = attrValue.split(":");
            String uriStr = attr.getOwnerElement().lookupNamespaceURI(parts[0]);
            if (uriStr != null) {
                uri = URI.create(uriStr);
            } else {
                throw new ComponentDefinitionException("Unsupported attribute namespace prefix " + parts[0] + " " + attr);
            }
        }
    }
    return uri;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) URI(java.net.URI) Attr(org.w3c.dom.Attr)

Example 67 with Attr

use of org.w3c.dom.Attr in project kotlin by JetBrains.

the class PrivateResourceDetector method visitElement.

@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    if (TAG_RESOURCES.equals(element.getTagName())) {
        for (Element item : LintUtils.getChildren(element)) {
            Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
            if (nameAttribute != null) {
                String name = getResourceFieldName(nameAttribute.getValue());
                String type = item.getTagName();
                if (type.equals(TAG_ITEM)) {
                    type = item.getAttribute(ATTR_TYPE);
                    if (type == null || type.isEmpty()) {
                        type = RESOURCE_CLZ_ID;
                    }
                } else if (type.equals("declare-styleable")) {
                    //$NON-NLS-1$
                    type = RESOURCE_CLR_STYLEABLE;
                } else if (type.contains("array")) {
                    //$NON-NLS-1$
                    // <string-array> etc
                    type = RESOURCE_CLZ_ARRAY;
                }
                ResourceType t = ResourceType.getEnum(type);
                if (t != null && isPrivate(context, t, name) && !VALUE_TRUE.equals(item.getAttributeNS(TOOLS_URI, ATTR_OVERRIDE))) {
                    String message = createOverrideErrorMessage(context, t, name);
                    Location location = context.getValueLocation(nameAttribute);
                    context.report(ISSUE, nameAttribute, location, message);
                }
            }
        }
    } else {
        assert TAG_STYLE.equals(element.getTagName()) || TAG_ARRAY.equals(element.getTagName()) || TAG_PLURALS.equals(element.getTagName()) || TAG_INTEGER_ARRAY.equals(element.getTagName()) || TAG_STRING_ARRAY.equals(element.getTagName());
        for (Element item : LintUtils.getChildren(element)) {
            checkChildRefs(context, item);
        }
    }
}
Also used : UElement(org.jetbrains.uast.UElement) Element(org.w3c.dom.Element) ResourceType(com.android.resources.ResourceType) Attr(org.w3c.dom.Attr) Location(com.android.tools.klint.detector.api.Location)

Example 68 with Attr

use of org.w3c.dom.Attr in project kotlin by JetBrains.

the class LayoutConsistencyDetector method lookupLocations.

private static void lookupLocations(@NonNull XmlContext context, @NonNull Element element, @NonNull Map<String, List<Location>> map) {
    String id = getId(element);
    if (id != null) {
        if (map.containsKey(id)) {
            if (context.getDriver().isSuppressed(context, INCONSISTENT_IDS, element)) {
                map.remove(id);
                return;
            }
            List<Location> locations = map.get(id);
            if (locations == null) {
                locations = Lists.newArrayList();
                map.put(id, locations);
            }
            Attr attr = element.getAttributeNodeNS(ANDROID_URI, ATTR_ID);
            assert attr != null;
            Location location = context.getLocation(attr);
            String folder = context.file.getParentFile().getName();
            location.setMessage(String.format("Occurrence in %1$s", folder));
            locations.add(location);
        }
    }
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            lookupLocations(context, (Element) child, map);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Attr(org.w3c.dom.Attr) Location(com.android.tools.klint.detector.api.Location)

Example 69 with Attr

use of org.w3c.dom.Attr in project kotlin by JetBrains.

the class BatteryDetector method visitElement.

@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    assert element.getTagName().equals("action");
    Attr attr = element.getAttributeNodeNS(ANDROID_URI, ATTR_NAME);
    if (attr == null) {
        return;
    }
    String name = attr.getValue();
    if ("android.net.conn.CONNECTIVITY_CHANGE".equals(name) && element.getParentNode() != null && element.getParentNode().getParentNode() != null && TAG_RECEIVER.equals(element.getParentNode().getParentNode().getNodeName()) && context.getMainProject().getTargetSdkVersion().getFeatureLevel() >= 24) {
        String message = "Declaring a broadcastreceiver for " + "`android.net.conn.CONNECTIVITY_CHANGE` is deprecated for apps targeting " + "N and higher. In general, apps should not rely on this broadcast and " + "instead use `JobScheduler` or `GCMNetworkManager`.";
        context.report(ISSUE, element, context.getValueLocation(attr), message);
    }
    if ("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS".equals(name) && context.getMainProject().getTargetSdkVersion().getFeatureLevel() >= 23) {
        String message = getBatteryOptimizationsErrorMessage();
        context.report(ISSUE, element, context.getValueLocation(attr), message);
    }
    if ("android.hardware.action.NEW_PICTURE".equals(name) || "android.hardware.action.NEW_VIDEO".equals(name) || "com.android.camera.NEW_PICTURE".equals(name)) {
        String message = String.format("Use of %1$s is deprecated for all apps starting " + "with the N release independent of the target SDK. Apps should not " + "rely on these broadcasts and instead use `JobScheduler`", name);
        context.report(ISSUE, element, context.getValueLocation(attr), message);
    }
}
Also used : Attr(org.w3c.dom.Attr)

Example 70 with Attr

use of org.w3c.dom.Attr in project jackrabbit by apache.

the class AbstractImportXmlTest method createSimpleDocument.

/**
     * Creates a document with some nodes and props for Namespace adding test
     * and for correct tree structure tests after having imported.
     *
     * @return
     */
public Document createSimpleDocument() {
    Document doc = dom.newDocument();
    Element root = doc.createElementNS(unusedURI, unusedPrefix + ":" + rootElem);
    root.setAttribute(XML_NS + ":" + unusedPrefix, unusedURI);
    Element child = doc.createElement(childElem);
    Element xmlElem = doc.createElement(xmltextElem);
    Element encoded = doc.createElement(encodedElemName);
    Element grandchild = doc.createElement(grandChildElem);
    Attr attr = doc.createAttribute(attributeName);
    attr.setValue(attributeValue);
    Attr encodedAttr = doc.createAttribute(encodedAttributeName);
    encodedAttr.setValue(encodedAttributeValue);
    child.appendChild(encoded);
    child.setAttributeNode(encodedAttr);
    grandchild.setAttributeNode(attr);
    xmlElem.appendChild(doc.createTextNode(xmltext));
    xmlElem.appendChild(grandchild);
    xmlElem.setAttribute(attributeName, attributeValue);
    root.appendChild(child);
    root.appendChild(xmlElem);
    doc.appendChild(root);
    return doc;
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6