Search in sources :

Example 56 with Attr

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

the class ResourceVisitor method visitElement.

private void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    List<Detector.XmlScanner> elementChecks = mElementToCheck.get(element.getTagName());
    if (elementChecks != null) {
        assert elementChecks instanceof RandomAccess;
        for (XmlScanner check : elementChecks) {
            check.visitElement(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElement(context, element);
        }
    }
    if (!mAttributeToCheck.isEmpty() || !mAllAttributeDetectors.isEmpty()) {
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            String name = attribute.getLocalName();
            if (name == null) {
                name = attribute.getName();
            }
            List<Detector.XmlScanner> list = mAttributeToCheck.get(name);
            if (list != null) {
                for (XmlScanner check : list) {
                    check.visitAttribute(context, attribute);
                }
            }
            if (!mAllAttributeDetectors.isEmpty()) {
                for (XmlScanner check : mAllAttributeDetectors) {
                    check.visitAttribute(context, attribute);
                }
            }
        }
    }
    // Visit children
    NodeList childNodes = element.getChildNodes();
    for (int i = 0, n = childNodes.getLength(); i < n; i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            visitElement(context, (Element) child);
        }
    }
    // Post hooks
    if (elementChecks != null) {
        for (XmlScanner check : elementChecks) {
            check.visitElementAfter(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElementAfter(context, element);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XmlScanner(com.android.tools.klint.detector.api.Detector.XmlScanner) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RandomAccess(java.util.RandomAccess) Attr(org.w3c.dom.Attr)

Example 57 with Attr

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

the class ApiDetector method checkElement.

/** Checks whether the given element is the given tag, and if so, whether it satisfied
     * the minimum version that the given tag is supported in */
private void checkElement(@NonNull XmlContext context, @NonNull Element element, @NonNull String tag, int api, @Nullable String gradleVersion, @NonNull Issue issue) {
    if (tag.equals(element.getTagName())) {
        int minSdk = getMinSdk(context);
        if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(element) && !featureProvidedByGradle(context, gradleVersion)) {
            Location location = context.getLocation(element);
            // For the <drawable> tag we report it against the class= attribute
            if ("drawable".equals(tag)) {
                Attr attribute = element.getAttributeNode(ATTR_CLASS);
                if (attribute == null) {
                    return;
                }
                location = context.getLocation(attribute);
                tag = ATTR_CLASS;
            }
            String message;
            if (issue == UNSUPPORTED) {
                message = String.format("`<%1$s>` requires API level %2$d (current min is %3$d)", tag, api, minSdk);
                if (gradleVersion != null) {
                    message += String.format(" or building with Android Gradle plugin %1$s or higher", gradleVersion);
                } else if (tag.contains(".")) {
                    message = String.format("Custom drawables requires API level %1$d (current min is %2$d)", api, minSdk);
                }
            } else {
                assert issue == UNUSED : issue;
                message = String.format("`<%1$s>` is only used in API level %2$d and higher " + "(current min is %3$d)", tag, api, minSdk);
            }
            context.report(issue, element, location, message);
        }
    }
}
Also used : Attr(org.w3c.dom.Attr)

Example 58 with Attr

use of org.w3c.dom.Attr in project jangaroo-tools by CoreMedia.

the class ExmlToModelParser method fillModelAttributes.

private void fillModelAttributes(ExmlModel model, JsonObject jsonObject, Element componentNode, ConfigClass configClass) {
    NamedNodeMap attributes = componentNode.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attribute = (Attr) attributes.item(i);
        String attributeName = attribute.getLocalName();
        String attributeValue = attribute.getValue();
        ConfigAttribute configAttribute = getCfgByName(configClass, attributeName);
        jsonObject.set(attributeName, getAttributeValue(attributeValue, configAttribute == null ? null : configAttribute.getType()));
    }
    fillModelAttributesFromSubElements(model, jsonObject, componentNode, configClass);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) ConfigAttribute(net.jangaroo.exml.model.ConfigAttribute) Attr(org.w3c.dom.Attr)

Example 59 with Attr

use of org.w3c.dom.Attr in project OpenAM by OpenRock.

the class AMModuleProperties method getAttribute.

//end of walk
private String getAttribute(Node node, String name) {
    NamedNodeMap nnm = node.getAttributes();
    if (nnm != null) {
        int len = nnm.getLength();
        Attr attr;
        for (int i = 0; i < len; i++) {
            attr = (Attr) nnm.item(i);
            if (attr.getNodeName().equals(name)) {
                return attr.getNodeValue();
            }
        }
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 60 with Attr

use of org.w3c.dom.Attr in project OpenClinica by OpenClinica.

the class OpenRosaServices method applyXformAttributes.

public String applyXformAttributes(String xform, NamedNodeMap attribs) throws Exception {
    String defaultNamespace = null;
    for (int i = 0; i < attribs.getLength(); i++) {
        Attr attrib = (Attr) attribs.item(i);
        if (attrib.getName().equals("xmlns"))
            defaultNamespace = attrib.getValue();
    }
    String[] xformArray = xform.split("html", 2);
    String modifiedXform = xformArray[0] + "html xmlns=\"" + defaultNamespace + "\" " + xformArray[1];
    return modifiedXform;
}
Also used : 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