use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class FogBugzRepository method getCases.
@SuppressWarnings("unchecked")
private Task[] getCases(String q) throws Exception {
loginIfNeeded();
PostMethod method = new PostMethod(getUrl() + "/api.asp");
method.addParameter("token", myToken);
method.addParameter("cmd", "search");
method.addParameter("q", q);
method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory");
int status = getHttpClient().executeMethod(method);
if (status != 200) {
throw new Exception("Error listing cases: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
List<Element> errorNodes = XPath.newInstance("/response/error").selectNodes(document);
if (!errorNodes.isEmpty()) {
throw new Exception("Error listing cases: " + errorNodes.get(0).getText());
}
final XPath commentPath = XPath.newInstance("events/event");
final List<Element> nodes = (List<Element>) XPath.newInstance("/response/cases/case").selectNodes(document);
final List<Task> tasks = ContainerUtil.mapNotNull(nodes, (NotNullFunction<Element, Task>) element -> createCase(element, commentPath));
return tasks.toArray(new Task[tasks.size()]);
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class FogBugzRepository method login.
private void login(@NotNull PostMethod method) throws Exception {
LOG.debug("Requesting new token");
int status = getHttpClient().executeMethod(method);
if (status != 200) {
throw new Exception("Error logging in: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
XPath path = XPath.newInstance("/response/token");
Element result = (Element) path.selectSingleNode(document);
if (result == null) {
Element error = (Element) XPath.newInstance("/response/error").selectSingleNode(document);
throw new Exception(error == null ? "Error logging in" : error.getText());
}
myToken = result.getTextTrim();
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class XPathResponseHandler method selectTasksList.
@NotNull
@Override
protected List<Object> selectTasksList(@NotNull String response, int max) throws Exception {
Document document = new SAXBuilder(false).build(new StringReader(response));
Element root = document.getRootElement();
XPath xPath = lazyCompile(getSelector(TASKS).getPath());
@SuppressWarnings("unchecked") List<Object> rawTaskElements = xPath.selectNodes(root);
if (!rawTaskElements.isEmpty() && !(rawTaskElements.get(0) instanceof Element)) {
throw new Exception(String.format("Expression '%s' should match list of XML elements. Got '%s' instead.", xPath.getXPath(), rawTaskElements.toString()));
}
return rawTaskElements.subList(0, Math.min(rawTaskElements.size(), max));
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class JiraLegacyApi method processRSS.
private List<Task> processRSS(@NotNull GetMethod method) throws Exception {
// Basic authorization should be enough
int code = myRepository.getHttpClient().executeMethod(method);
if (code != HttpStatus.SC_OK) {
throw new Exception(TaskBundle.message("failure.http.error", code, method.getStatusText()));
}
Element root = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getRootElement();
Element channel = root.getChild("channel");
if (channel != null) {
List<Element> children = channel.getChildren("item");
LOG.debug("Total issues in JIRA RSS feed: " + children.size());
return ContainerUtil.map(children, element -> new JiraSoapTask(element, myRepository));
} else {
LOG.warn("JIRA channel not found");
}
return ContainerUtil.emptyList();
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class PivotalTrackerRepository method findTask.
@Nullable
@Override
public Task findTask(@NotNull final String id) throws Exception {
final String realId = getRealId(id);
if (realId == null)
return null;
final String url = API_URL + "/projects/" + myProjectId + "/stories/" + realId;
LOG.info("Retrieving issue by id: " + url);
final HttpMethod method = doREST(url, HTTPMethod.GET);
final InputStream stream = method.getResponseBodyAsStream();
final Element element = new SAXBuilder(false).build(stream).getRootElement();
return element.getName().equals("story") ? createIssue(element) : null;
}
Aggregations