use of javax.xml.parsers.DocumentBuilderFactory in project violations-plugin by jenkinsci.
the class ViolationsDOMParser method parse.
/*
* Parse a violations file.
* @param model the model to store the violations in.
* @param projectPath the project path used for resolving paths.
* @param fileName the name of the violations file to parse
* (relative to the projectPath).
* @param sourcePaths a list of source paths to resolve classes against
* @throws IOException if there is an error.
*/
public void parse(FullBuildModel model, File projectPath, String fileName, String[] sourcePaths) throws IOException {
boolean success = false;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse(new File(projectPath, fileName));
setProjectPath(projectPath);
setModel(model);
setSourcePaths(sourcePaths);
execute();
success = true;
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
throw new IOException2("Cannot parse " + fileName, ex);
} finally {
// ? terminate the parser
}
}
use of javax.xml.parsers.DocumentBuilderFactory in project violations-plugin by jenkinsci.
the class ReSharperParser method parse.
public void parse(final FullBuildModel model, final File projectPath, final String fileName, final String[] sourcePaths) throws IOException {
absoluteFileFinder.addSourcePath(projectPath.getAbsolutePath());
absoluteFileFinder.addSourcePaths(sourcePaths);
final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
final Document docElement = docBuilder.parse(new FileInputStream(new File(projectPath, fileName)));
NodeList nl = docElement.getElementsByTagName("IssueType");
if (nl == null)
return;
for (int i = 0; i < nl.getLength(); i++) {
final Element issueTypeElement = (Element) nl.item(i);
final IssueType issueType = parseIssueType(issueTypeElement);
issueTypes.put(issueType.getId(), issueType);
}
nl = docElement.getElementsByTagName("Issue");
if (nl == null)
return;
for (int i = 0; i < nl.getLength(); i++) {
final Element issueElement = (Element) nl.item(i);
final Issue issue = parseIssue(issueElement);
final IssueType issueType = issueTypes.get(issue.getTypeId());
if (// couldn't find the issue type, skip it
issueType == null)
continue;
final Violation violation = new Violation();
violation.setType("resharper");
violation.setMessage(issue.getMessage());
violation.setPopupMessage(issueType.getDescription() + " - " + issue.getMessage());
violation.setSource(issueType.getCategory());
violation.setLine(issue.getLine());
violation.setSeverity(SEVERITIES.get(issueType.getSeverity()));
violation.setSeverityLevel(Severity.getSeverityLevel(violation.getSeverity()));
final File file = absoluteFileFinder.getFileForName(issue.getFile());
final FullFileModel fullFileModel = getFileModel(model, issue.getFile().replace('\\', '/'), file);
fullFileModel.addViolation(violation);
}
} catch (final ParserConfigurationException pce) {
throw new IOException2(pce);
} catch (final SAXException se) {
throw new IOException2(se);
}
}
use of javax.xml.parsers.DocumentBuilderFactory in project jersey by jersey.
the class WadlResourceTest method extractWadlAsDocument.
/**
* Extracts WADL as {@link Document} from given {@link Response}.
*
* @param response The response to extract {@code Document} from.
* @return The extracted {@code Document}.
* @throws ParserConfigurationException In case of parser configuration issues.
* @throws SAXException In case of parsing issues.
* @throws IOException In case of IO error.
*/
static Document extractWadlAsDocument(final Response response) throws ParserConfigurationException, SAXException, IOException {
assertEquals(200, response.getStatus());
final File tmpFile = response.readEntity(File.class);
final DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
bf.setXIncludeAware(false);
}
final DocumentBuilder b = bf.newDocumentBuilder();
final Document d = b.parse(tmpFile);
Wadl5Test.printSource(new DOMSource(d));
return d;
}
use of javax.xml.parsers.DocumentBuilderFactory in project android-selector-intellij-plugin by importre.
the class AndroidSelectorDialog method createDrawableV21.
private void createDrawableV21(String filename, String color, String pressed) throws Exception {
VirtualFile child = dir.findChild(drawableV21Dir);
if (child == null) {
child = dir.createChildDirectory(null, drawableV21Dir);
}
VirtualFile newXmlFile = child.findChild(filename);
if (newXmlFile != null && newXmlFile.exists()) {
newXmlFile.delete(null);
}
newXmlFile = child.createChildData(null, filename);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("ripple");
root.setAttributeNS(nsUri, "xmlns:android", androidUri);
root.setAttribute("android:color", pressed);
doc.appendChild(root);
Element item = doc.createElement("item");
item.setAttribute("android:drawable", color);
root.appendChild(item);
OutputStream os = newXmlFile.getOutputStream(null);
PrintWriter out = new PrintWriter(os);
StringWriter writer = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(INDENT_SPACE, "4");
transformer.transform(new DOMSource(doc), new StreamResult(writer));
out.println(writer.getBuffer().toString());
out.close();
}
use of javax.xml.parsers.DocumentBuilderFactory in project languagetool by languagetool-org.
the class XMLValidator method mergeIntoSource.
private static Source mergeIntoSource(InputStream baseXmlStream, InputStream xmlStream) throws Exception {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setIgnoringComments(true);
domFactory.setValidating(false);
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document baseDoc = builder.parse(baseXmlStream);
Document ruleDoc = builder.parse(xmlStream);
// Shall this be more generic, i.e. reuse not just unification ???
NodeList unificationNodes = baseDoc.getElementsByTagName("unification");
Node ruleNode = ruleDoc.getElementsByTagName("rules").item(0);
Node firstChildRuleNode = ruleNode.getChildNodes().item(1);
for (int i = 0; i < unificationNodes.getLength(); i++) {
Node unificationNode = ruleDoc.importNode(unificationNodes.item(i), true);
ruleNode.insertBefore(unificationNode, firstChildRuleNode);
}
return new DOMSource(ruleDoc);
}
Aggregations