Search in sources :

Example 6 with SAXBuilder

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

the class ClientPropertiesManager method checkInitDefaultManager.

private static void checkInitDefaultManager() {
    synchronized (DEFAULT_MANAGER_LOCK) {
        // in Upsource projectOpened can be executed concurrently for 2 projects
        if (ourDefaultManager == null) {
            ourDefaultManager = new ClientPropertiesManager();
            try {
                //noinspection HardCodedStringLiteral
                final Document document = new SAXBuilder().build(ClientPropertiesManager.class.getResource("/" + COMPONENT_NAME + ".xml"));
                final Element child = document.getRootElement();
                ourDefaultManager.readExternal(child);
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 7 with SAXBuilder

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

the class YouTrackRepository method getAvailableTaskStates.

@NotNull
@Override
public Set<CustomTaskState> getAvailableTaskStates(@NotNull Task task) throws Exception {
    final HttpMethod method = doREST("/rest/issue/" + task.getId() + "/execute/intellisense?command=" + encodeUrl("state: "), false);
    try {
        final InputStream stream = method.getResponseBodyAsStream();
        final Element element = new SAXBuilder(false).build(stream).getRootElement();
        return ContainerUtil.map2Set(element.getChild("suggest").getChildren("item"), element1 -> {
            final String stateName = element1.getChildText("option");
            return new CustomTaskState(stateName, stateName);
        });
    } finally {
        method.releaseConnection();
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) HttpMethod(org.apache.commons.httpclient.HttpMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with SAXBuilder

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

the class YouTrackRepository method checkVersion.

private void checkVersion() throws Exception {
    HttpMethod method = doREST("/rest/workflow/version", false);
    try {
        InputStream stream = method.getResponseBodyAsStream();
        Element element = new SAXBuilder(false).build(stream).getRootElement();
        final boolean timeTrackingAvailable = element.getName().equals("version") && VersionComparatorUtil.compare(element.getChildText("version"), "4.1") >= 0;
        if (!timeTrackingAvailable) {
            throw new Exception("Time tracking is not supported in this version of Youtrack");
        }
    } finally {
        method.releaseConnection();
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) HttpMethod(org.apache.commons.httpclient.HttpMethod) JDOMException(org.jdom.JDOMException)

Example 9 with SAXBuilder

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

the class YouTrackRepository method doREST.

HttpMethod doREST(String request, boolean post) throws Exception {
    HttpClient client = login(new PostMethod(getUrl() + "/rest/user/login"));
    String uri = getUrl() + request;
    HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri);
    configureHttpMethod(method);
    int status = client.executeMethod(method);
    if (status == 400) {
        InputStream string = method.getResponseBodyAsStream();
        Element element = new SAXBuilder(false).build(string).getRootElement();
        TaskUtil.prettyFormatXmlToLog(LOG, element);
        if ("error".equals(element.getName())) {
            throw new Exception(element.getText());
        }
    }
    return method;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) PostMethod(org.apache.commons.httpclient.methods.PostMethod) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) Element(org.jdom.Element) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod) JDOMException(org.jdom.JDOMException)

Example 10 with SAXBuilder

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

the class PivotalTrackerRepository method setTaskState.

@Override
public void setTaskState(@NotNull Task task, @NotNull TaskState state) throws Exception {
    final String realId = getRealId(task.getId());
    if (realId == null)
        return;
    final String stateName;
    switch(state) {
        case IN_PROGRESS:
            stateName = "started";
            break;
        case RESOLVED:
            stateName = "finished";
            break;
        // may add some others in future
        default:
            return;
    }
    String url = API_URL + "/projects/" + myProjectId + "/stories/" + realId;
    url += "?" + encodeUrl("story[current_state]") + "=" + encodeUrl(stateName);
    LOG.info("Updating issue state by id: " + url);
    final HttpMethod method = doREST(url, HTTPMethod.PUT);
    final InputStream stream = method.getResponseBodyAsStream();
    final Element element = new SAXBuilder(false).build(stream).getRootElement();
    if (!element.getName().equals("story")) {
        if (element.getName().equals("errors")) {
            throw new Exception(extractErrorMessage(element));
        } else {
            // unknown error, probably our fault
            LOG.warn("Error setting state for: " + url + ", HTTP status code: " + method.getStatusCode());
            throw new Exception(String.format("Cannot set state '%s' for issue.", stateName));
        }
    }
}
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)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