use of javax.xml.parsers.DocumentBuilder in project jersey by jersey.
the class MultiPartWebAppTest method testApplicationWadl.
@Test
public void testApplicationWadl() throws Exception {
final WebTarget target = target().path("application.wadl");
final Response response = target.request().get();
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);
final XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("//wadl:resource[@path='part']/wadl:method[@name='POST']/wadl:request/wadl:representation/@mediaType", d, XPathConstants.STRING);
assertEquals("multipart/form-data", val);
}
use of javax.xml.parsers.DocumentBuilder in project NabAlive by jcheype.
the class MeteoApplication method httpCall.
public void httpCall(final String mac, final String city, final String country, final String unit, final String key, final String lang) throws UnsupportedEncodingException {
StringBuilder url = new StringBuilder(BASE_URL);
url.append("?weather=").append(URLEncoder.encode(city + "," + country, "UTF-8"));
url.append("&hl=fr");
logger.debug("making httpCall: {}", url);
try {
asyncHttpClient.prepareGet(url.toString()).execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
DocumentBuilder builder = builderLocal.get();
String responseBody = response.getResponseBody("ISO-8859-1");
StringReader reader = new StringReader(responseBody);
InputSource is = new InputSource(reader);
Document document = builder.parse(is);
NodeList forecastConditions = document.getElementsByTagName("forecast_conditions");
MeteoResult meteoResult = new MeteoResult(getNodeValue(forecastConditions.item(0).getChildNodes(), "low"), getNodeValue(forecastConditions.item(0).getChildNodes(), "high"), getNodeValue(forecastConditions.item(0).getChildNodes(), "icon"), getNodeValue(forecastConditions.item(1).getChildNodes(), "low"), getNodeValue(forecastConditions.item(1).getChildNodes(), "high"), getNodeValue(forecastConditions.item(1).getChildNodes(), "icon"), unit);
meteoCache.asMap().putIfAbsent(key, meteoResult);
sendMeteo(mac, meteoResult, lang);
return response;
}
@Override
public void onThrowable(Throwable t) {
logger.error("error in meteo, http received", t);
}
});
} catch (IOException e) {
logger.error("error in meteo, http call", e);
}
}
use of javax.xml.parsers.DocumentBuilder 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.DocumentBuilder 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.DocumentBuilder 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;
}
Aggregations