Search in sources :

Example 81 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class YouTrackRepository method getIssues.

public Task[] getIssues(@Nullable String request, int max, long since) throws Exception {
    String query = getDefaultSearch();
    if (StringUtil.isNotEmpty(request)) {
        query += " " + request;
    }
    String requestUrl = "/rest/project/issues/?filter=" + encodeUrl(query) + "&max=" + max + "&updatedAfter" + since;
    HttpMethod method = doREST(requestUrl, false);
    try {
        InputStream stream = method.getResponseBodyAsStream();
        // todo workaround for http://youtrack.jetbrains.net/issue/JT-7984
        String s = StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
        for (int i = 0; i < s.length(); i++) {
            if (!XMLChar.isValid(s.charAt(i))) {
                s = s.replace(s.charAt(i), ' ');
            }
        }
        Element element;
        try {
            //InputSource source = new InputSource(stream);
            //source.setEncoding("UTF-8");
            //element = new SAXBuilder(false).build(source).getRootElement();
            element = new SAXBuilder(false).build(new StringReader(s)).getRootElement();
        } catch (JDOMException e) {
            LOG.error("Can't parse YouTrack response for " + requestUrl, e);
            throw e;
        }
        if ("error".equals(element.getName())) {
            throw new Exception("Error from YouTrack for " + requestUrl + ": '" + element.getText() + "'");
        }
        List<Element> children = element.getChildren("issue");
        final List<Task> tasks = ContainerUtil.mapNotNull(children, (NullableFunction<Element, Task>) o -> createIssue(o));
        return tasks.toArray(new Task[tasks.size()]);
    } finally {
        method.releaseConnection();
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) HttpRequests(com.intellij.util.io.HttpRequests) Tag(com.intellij.util.xmlb.annotations.Tag) Date(java.util.Date) BaseRepository(com.intellij.tasks.impl.BaseRepository) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ContainerUtil(com.intellij.util.containers.ContainerUtil) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) JDOMException(org.jdom.JDOMException) Comparing(com.intellij.openapi.util.Comparing) com.intellij.tasks(com.intellij.tasks) Logger(com.intellij.openapi.diagnostic.Logger) XMLChar(org.apache.axis.utils.XMLChar) StreamUtil(com.intellij.openapi.util.io.StreamUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) NullableFunction(com.intellij.util.NullableFunction) Set(java.util.Set) VersionComparatorUtil(com.intellij.util.text.VersionComparatorUtil) BaseRepositoryImpl(com.intellij.tasks.impl.BaseRepositoryImpl) TestOnly(org.jetbrains.annotations.TestOnly) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Nullable(org.jetbrains.annotations.Nullable) HttpMethod(org.apache.commons.httpclient.HttpMethod) AuthScope(org.apache.commons.httpclient.auth.AuthScope) List(java.util.List) StringReader(java.io.StringReader) LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) HttpClient(org.apache.commons.httpclient.HttpClient) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) TaskUtil(com.intellij.tasks.impl.TaskUtil) javax.swing(javax.swing) InputStream(java.io.InputStream) SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) JDOMException(org.jdom.JDOMException) JDOMException(org.jdom.JDOMException) StringReader(java.io.StringReader) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 82 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class YouTrackRepository method updateTimeSpent.

@Override
public void updateTimeSpent(@NotNull LocalTask task, @NotNull String timeSpent, @NotNull String comment) throws Exception {
    checkVersion();
    String command = encodeUrl(String.format("work Today %s %s", timeSpent, comment));
    final HttpMethod method = doREST("/rest/issue/execute/" + task.getId() + "?command=" + command, true);
    try {
        if (method.getStatusCode() != 200) {
            InputStream stream = method.getResponseBodyAsStream();
            String message = new SAXBuilder(false).build(stream).getRootElement().getText();
            throw new Exception(message);
        }
    } finally {
        method.releaseConnection();
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) HttpMethod(org.apache.commons.httpclient.HttpMethod) JDOMException(org.jdom.JDOMException)

Example 83 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class LighthouseRepository method getIssues.

@Override
public Task[] getIssues(@Nullable String query, int max, long since) throws Exception {
    String url = "/projects/" + myProjectId + "/tickets.xml";
    url += "?q=" + encodeUrl("state:open sort:updated ");
    if (!StringUtil.isEmpty(query)) {
        url += encodeUrl(query);
    }
    final List<Task> tasks = new ArrayList<>();
    int page = 1;
    final HttpClient client = login();
    while (tasks.size() < max) {
        HttpMethod method = doREST(url + "&page=" + page, false, client);
        InputStream stream = method.getResponseBodyAsStream();
        Element element = new SAXBuilder(false).build(stream).getRootElement();
        if ("nil-classes".equals(element.getName()))
            break;
        if (!"tickets".equals(element.getName())) {
            LOG.warn("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode());
            throw new Exception("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode() + "\n" + element.getText());
        }
        List<Element> children = element.getChildren("ticket");
        List<Task> taskList = ContainerUtil.mapNotNull(children, (NullableFunction<Element, Task>) o -> createIssue(o));
        tasks.addAll(taskList);
        page++;
    }
    return tasks.toArray(new Task[tasks.size()]);
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) TasksIcons(icons.TasksIcons) Tag(com.intellij.util.xmlb.annotations.Tag) Date(java.util.Date) BaseRepository(com.intellij.tasks.impl.BaseRepository) SimpleDateFormat(java.text.SimpleDateFormat) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) Matcher(java.util.regex.Matcher) Comparing(com.intellij.openapi.util.Comparing) com.intellij.tasks(com.intellij.tasks) Logger(com.intellij.openapi.diagnostic.Logger) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) StringUtil(com.intellij.openapi.util.text.StringUtil) NullableFunction(com.intellij.util.NullableFunction) BaseRepositoryImpl(com.intellij.tasks.impl.BaseRepositoryImpl) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Nullable(org.jetbrains.annotations.Nullable) HttpMethod(org.apache.commons.httpclient.HttpMethod) List(java.util.List) HttpClient(org.apache.commons.httpclient.HttpClient) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Element(org.jdom.Element) javax.swing(javax.swing) InputStream(java.io.InputStream) SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) HttpClient(org.apache.commons.httpclient.HttpClient) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 84 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class LighthouseRepository method findTask.

@Nullable
@Override
public Task findTask(@NotNull String id) throws Exception {
    final String[] split = id.split("\\-");
    final String projectId = split[0];
    final String realId = split[1];
    if (!Comparing.strEqual(projectId, myProjectId))
        return null;
    HttpMethod method = doREST("/projects/" + myProjectId + "/tickets/" + realId + ".xml", false, login());
    InputStream stream = method.getResponseBodyAsStream();
    Element element = new SAXBuilder(false).build(stream).getRootElement();
    return element.getName().equals("ticket") ? 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)

Example 85 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class PivotalTrackerRepository method getStories.

private List<Element> getStories(@Nullable final String query, final int max) throws Exception {
    String url = API_URL + "/projects/" + myProjectId + "/stories";
    url += "?filter=" + encodeUrl("state:started,unstarted,unscheduled,rejected");
    if (!StringUtil.isEmpty(query)) {
        url += encodeUrl(" \"" + query + '"');
    }
    if (max >= 0) {
        url += "&limit=" + encodeUrl(String.valueOf(max));
    }
    LOG.info("Getting all the stories with url: " + url);
    final HttpMethod method = doREST(url, HTTPMethod.GET);
    final InputStream stream = method.getResponseBodyAsStream();
    final Element element = new SAXBuilder(false).build(stream).getRootElement();
    if (!"stories".equals(element.getName())) {
        LOG.warn("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode());
        throw new Exception("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode() + "\n" + element.getText());
    }
    return element.getChildren("story");
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) HttpMethod(org.apache.commons.httpclient.HttpMethod) ParseException(java.text.ParseException)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)146 Document (org.jdom.Document)110 Element (org.jdom.Element)84 IOException (java.io.IOException)61 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