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;
}
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);
}
}
}
}
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);
}
}
}
}
}
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);
}
}
}
}
}
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);
}
}
}
}
}
Aggregations