Search in sources :

Example 86 with Element

use of org.w3c.dom.Element in project sonarqube by SonarSource.

the class XpathParser method getChildElements.

public List<Element> getChildElements(Element base, String elementName) {
    List<Element> rtrVal = new ArrayList<>();
    NodeList childrens = base.getElementsByTagName(elementName);
    for (int i = 0; i < childrens.getLength(); i++) {
        Node nde = childrens.item(i);
        if (nde.getNodeType() == Node.ELEMENT_NODE) {
            rtrVal.add((Element) nde);
        }
    }
    return rtrVal;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 87 with Element

use of org.w3c.dom.Element in project atlas by alibaba.

the class Configuration method readXmlConfig.

/**
     * read args from xml
     **/
void readXmlConfig(File xmlConfigFile) throws IOException, ParserConfigurationException, SAXException {
    if (!xmlConfigFile.exists()) {
        return;
    }
    System.out.printf("reading config file, %s\n", xmlConfigFile.getAbsolutePath());
    BufferedInputStream input = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        input = new BufferedInputStream(new FileInputStream(xmlConfigFile));
        InputSource source = new InputSource(input);
        factory.setNamespaceAware(false);
        factory.setValidating(false);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(source);
        NodeList issues = document.getElementsByTagName(TAG_ISSUE);
        for (int i = 0, count = issues.getLength(); i < count; i++) {
            Node node = issues.item(i);
            Element element = (Element) node;
            String id = element.getAttribute(ATTR_ID);
            if (id.length() == 0) {
                System.err.println("Invalid config file: Missing required issue id attribute");
                continue;
            }
            if (id.equals(PROPERTY_ISSUE)) {
                readPropertyFromXml(node);
            } else if (id.equals(DEX_ISSUE)) {
                readDexPatternsFromXml(node);
            } else if (id.equals(SO_ISSUE)) {
                readLibPatternsFromXml(node);
            } else if (id.equals(RES_ISSUE)) {
                readResPatternsFromXml(node);
            } else if (id.equals(PACKAGE_CONFIG_ISSUE)) {
                readPackageConfigFromXml(node);
            } else if (id.equals(SIGN_ISSUE)) {
                if (mUseSignAPk) {
                    readSignFromXml(node);
                }
            } else {
                System.err.println("unknown issue " + id);
            }
        }
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                System.exit(-1);
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) BufferedInputStream(java.io.BufferedInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream)

Example 88 with Element

use of org.w3c.dom.Element in project atlas by alibaba.

the class Configuration method readSignFromXml.

private void readSignFromXml(Node node) throws IOException {
    if (mSignatureFile != null) {
        System.err.println("already set the sign info from command line, ignore this");
        return;
    }
    NodeList childNodes = node.getChildNodes();
    if (childNodes.getLength() > 0) {
        for (int j = 0, n = childNodes.getLength(); j < n; j++) {
            Node child = childNodes.item(j);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                Element check = (Element) child;
                String tagName = check.getTagName();
                String value = check.getAttribute(ATTR_VALUE);
                if (value.length() == 0) {
                    throw new IOException(String.format("Invalid config file: Missing required attribute %s\n", ATTR_VALUE));
                }
                if (tagName.equals(ATTR_SIGN_FILE_PATH)) {
                    mSignatureFile = new File(value);
                    if (!mSignatureFile.exists()) {
                        throw new IOException(String.format("the signature file do not exit, raw path= %s\n", mSignatureFile.getAbsolutePath()));
                    }
                } else if (tagName.equals(ATTR_SIGN_FILE_STOREPASS)) {
                    mStorePass = value;
                    mStorePass = mStorePass.trim();
                } else if (tagName.equals(ATTR_SIGN_FILE_KEYPASS)) {
                    mKeyPass = value;
                    mKeyPass = mKeyPass.trim();
                } else if (tagName.equals(ATTR_SIGN_FILE_ALIAS)) {
                    mStoreAlias = value;
                    mStoreAlias = mStoreAlias.trim();
                } else {
                    System.err.println("unknown sign tag " + tagName);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IOException(java.io.IOException) File(java.io.File)

Example 89 with Element

use of org.w3c.dom.Element in project atlas by alibaba.

the class Configuration method readLibPatternsFromXml.

private void readLibPatternsFromXml(Node node) throws IOException {
    NodeList childNodes = node.getChildNodes();
    if (childNodes.getLength() > 0) {
        for (int j = 0, n = childNodes.getLength(); j < n; j++) {
            Node child = childNodes.item(j);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                Element check = (Element) child;
                String tagName = check.getTagName();
                String value = check.getAttribute(ATTR_VALUE);
                if (tagName.equals(ATTR_PATTERN)) {
                    addToPatterns(value, mSoFilePattern);
                } else {
                    System.err.println("unknown dex tag " + tagName);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 90 with Element

use of org.w3c.dom.Element in project atlas by alibaba.

the class Configuration method readPackageConfigFromXml.

private void readPackageConfigFromXml(Node node) throws IOException {
    NodeList childNodes = node.getChildNodes();
    if (childNodes.getLength() > 0) {
        for (int j = 0, n = childNodes.getLength(); j < n; j++) {
            Node child = childNodes.item(j);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                Element check = (Element) child;
                String tagName = check.getTagName();
                String value = check.getAttribute(ATTR_VALUE);
                String name = check.getAttribute(ATTR_NAME);
                if (tagName.equals(ATTR_CONFIG_FIELD)) {
                    mPackageFields.put(name, value);
                } else {
                    System.err.println("unknown package config tag " + tagName);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Aggregations

Element (org.w3c.dom.Element)9072 Document (org.w3c.dom.Document)2651 NodeList (org.w3c.dom.NodeList)2103 Node (org.w3c.dom.Node)1855 ArrayList (java.util.ArrayList)957 DocumentBuilder (javax.xml.parsers.DocumentBuilder)793 IOException (java.io.IOException)732 Test (org.junit.Test)693 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)591 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)489 HashMap (java.util.HashMap)434 SAXException (org.xml.sax.SAXException)406 File (java.io.File)358 Attr (org.w3c.dom.Attr)333 InputStream (java.io.InputStream)309 QName (javax.xml.namespace.QName)292 Map (java.util.Map)285 JAXBElement (javax.xml.bind.JAXBElement)285 NamedNodeMap (org.w3c.dom.NamedNodeMap)266 List (java.util.List)264