Search in sources :

Example 1 with SAXBuilder

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()]);
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) TasksIcons(icons.TasksIcons) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Tag(com.intellij.util.xmlb.annotations.Tag) StringUtil(com.intellij.openapi.util.text.StringUtil) Date(java.util.Date) NotNullFunction(com.intellij.util.NotNullFunction) BaseRepository(com.intellij.tasks.impl.BaseRepository) PostMethod(org.apache.commons.httpclient.methods.PostMethod) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ContainerUtil(com.intellij.util.containers.ContainerUtil) BaseRepositoryImpl(com.intellij.tasks.impl.BaseRepositoryImpl) XPath(org.jdom.xpath.XPath) Nullable(org.jetbrains.annotations.Nullable) Document(org.jdom.Document) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) com.intellij.tasks(com.intellij.tasks) PasswordUtil(com.intellij.openapi.util.PasswordUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) javax.swing(javax.swing) SAXBuilder(org.jdom.input.SAXBuilder) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Element(org.jdom.Element) List(java.util.List) Document(org.jdom.Document) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException)

Example 2 with SAXBuilder

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();
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException)

Example 3 with SAXBuilder

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));
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SAXBuilder

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();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element)

Example 5 with SAXBuilder

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) HttpMethod(org.apache.commons.httpclient.HttpMethod) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)145 Document (org.jdom.Document)109 Element (org.jdom.Element)84 IOException (java.io.IOException)60 JDOMException (org.jdom.JDOMException)50 StringReader (java.io.StringReader)35 InputStream (java.io.InputStream)29 File (java.io.File)18 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ArrayList (java.util.ArrayList)12 XPath (org.jdom.xpath.XPath)11 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XMLOutputter (org.jdom.output.XMLOutputter)10 URL (java.net.URL)9 List (java.util.List)8 GoraException (org.apache.gora.util.GoraException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 Namespace (org.jdom.Namespace)6 StringWriter (java.io.StringWriter)5