use of org.w3c.dom.Element in project cucumber-jvm by cucumber.
the class JUnitFormatter method addDummyTestCase.
private void addDummyTestCase() {
Element dummy = doc.createElement("testcase");
dummy.setAttribute("classname", "dummy");
dummy.setAttribute("name", "dummy");
rootElement.appendChild(dummy);
Element skipped = doc.createElement("skipped");
skipped.setAttribute("message", "No features found");
dummy.appendChild(skipped);
}
use of org.w3c.dom.Element in project lucida by claritylab.
the class RuleBasedQuestionClassifier method loadRulesFile.
private void loadRulesFile(String fileName) {
// PARSE XML RULES FILE
log.debug("Parsing xml rules file");
Document rulesDocument;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setNamespaceAware(true);
DocumentBuilder db = factory.newDocumentBuilder();
rulesDocument = db.parse(fileName);
} catch (Exception e) {
throw new RuntimeException("Failed to parse XML patterns file", e);
}
// EXTRACT RULE DATA.
log.debug("Loading rules");
NodeList ruleList = rulesDocument.getElementsByTagName("RULE");
for (int i = 0; i < ruleList.getLength(); i++) {
Node rule = ruleList.item(i);
if (!rule.getNodeName().equals("RULE") || rule.getNodeType() != Node.ELEMENT_NODE)
continue;
rules.add(new Rule((Element) rule));
}
}
use of org.w3c.dom.Element in project checkstyle by checkstyle.
the class CheckUtil method getCheckStyleModulesReferencedInConfig.
/**
* Gets a set of names of checkstyle's checks which are referenced in checkstyle_checks.xml.
*
* @param configFilePath
* file path of checkstyle_checks.xml.
* @return names of checkstyle's checks which are referenced in checkstyle_checks.xml.
*/
private static Set<String> getCheckStyleModulesReferencedInConfig(String configFilePath) {
try {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Validations of XML file make parsing too slow, that is why we
// disable all validations.
factory.setNamespaceAware(false);
factory.setValidating(false);
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final DocumentBuilder builder = factory.newDocumentBuilder();
final Document document = builder.parse(new File(configFilePath));
// optional, but recommended
// FYI:
// http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-
// how-does-it-work
document.getDocumentElement().normalize();
final NodeList nodeList = document.getElementsByTagName("module");
final Set<String> checksReferencedInCheckstyleChecksXml = new HashSet<>();
for (int i = 0; i < nodeList.getLength(); i++) {
final Node currentNode = nodeList.item(i);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
final Element module = (Element) currentNode;
final String checkName = module.getAttribute("name");
checksReferencedInCheckstyleChecksXml.add(checkName);
}
}
return checksReferencedInCheckstyleChecksXml;
} catch (Exception exception) {
throw new IllegalStateException(exception);
}
}
use of org.w3c.dom.Element in project cw-omnibus by commonsguy.
the class WeatherFragment method buildForecasts.
private ArrayList<Forecast> buildForecasts(String raw) throws Exception {
ArrayList<Forecast> forecasts = new ArrayList<Forecast>();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(raw)));
NodeList times = doc.getElementsByTagName("start-valid-time");
for (int i = 0; i < times.getLength(); i++) {
Element time = (Element) times.item(i);
Forecast forecast = new Forecast();
forecasts.add(forecast);
forecast.setTime(time.getFirstChild().getNodeValue());
}
NodeList temps = doc.getElementsByTagName("value");
for (int i = 0; i < temps.getLength(); i++) {
Element temp = (Element) temps.item(i);
Forecast forecast = forecasts.get(i);
forecast.setTemp(Integer.valueOf(temp.getFirstChild().getNodeValue()));
}
NodeList icons = doc.getElementsByTagName("icon-link");
for (int i = 0; i < icons.getLength(); i++) {
Element icon = (Element) icons.item(i);
Forecast forecast = forecasts.get(i);
forecast.setIcon(icon.getFirstChild().getNodeValue());
}
return (forecasts);
}
use of org.w3c.dom.Element in project buck by facebook.
the class MiniAapt method processDrawables.
void processDrawables(ProjectFilesystem filesystem, Path resourceFile) throws IOException, ResourceParseException {
String filename = resourceFile.getFileName().toString();
int dotIndex = filename.indexOf('.');
String resourceName = dotIndex != -1 ? filename.substring(0, dotIndex) : filename;
// Look into the XML file.
boolean isGrayscaleImage = false;
boolean isCustomDrawable = false;
if (filename.endsWith(".xml")) {
try (InputStream stream = filesystem.newFileInputStream(resourceFile)) {
Document dom = parseXml(resourceFile, stream);
Element root = dom.getDocumentElement();
isCustomDrawable = root.getNodeName().startsWith(CUSTOM_DRAWABLE_PREFIX);
}
} else if (isGrayscaleImageProcessingEnabled) {
isGrayscaleImage = filename.endsWith(".g.png");
}
if (isCustomDrawable) {
resourceCollector.addCustomDrawableResourceIfNotPresent(RType.DRAWABLE, resourceName);
} else if (isGrayscaleImage) {
resourceCollector.addGrayscaleImageResourceIfNotPresent(RType.DRAWABLE, resourceName);
} else {
resourceCollector.addIntResourceIfNotPresent(RType.DRAWABLE, resourceName);
}
}
Aggregations