Search in sources :

Example 86 with JDOMException

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

the class MavenIndicesManager method loadUserArchetypes.

private void loadUserArchetypes() {
    try {
        Path file = getUserArchetypesFile();
        if (!PathKt.exists(file)) {
            return;
        }
        // Store artifact to set to remove duplicate created by old IDEA (https://youtrack.jetbrains.com/issue/IDEA-72105)
        Collection<MavenArchetype> result = new LinkedHashSet<>();
        List<Element> children = JdomKt.loadElement(file).getChildren(ELEMENT_ARCHETYPE);
        for (int i = children.size() - 1; i >= 0; i--) {
            Element each = children.get(i);
            String groupId = each.getAttributeValue(ELEMENT_GROUP_ID);
            String artifactId = each.getAttributeValue(ELEMENT_ARTIFACT_ID);
            String version = each.getAttributeValue(ELEMENT_VERSION);
            String repository = each.getAttributeValue(ELEMENT_REPOSITORY);
            String description = each.getAttributeValue(ELEMENT_DESCRIPTION);
            if (StringUtil.isEmptyOrSpaces(groupId) || StringUtil.isEmptyOrSpaces(artifactId) || StringUtil.isEmptyOrSpaces(version)) {
                continue;
            }
            result.add(new MavenArchetype(groupId, artifactId, version, repository, description));
        }
        ArrayList<MavenArchetype> listResult = new ArrayList<>(result);
        Collections.reverse(listResult);
        myUserArchetypes = listResult;
    } catch (IOException | JDOMException e) {
        MavenLog.LOG.warn(e);
    }
}
Also used : Path(java.nio.file.Path) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype)

Example 87 with JDOMException

use of org.jdom.JDOMException 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 88 with JDOMException

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

the class DotProjectFileHelper method saveDotProjectFile.

public static void saveDotProjectFile(@NotNull Module module, @NotNull String storageRoot) throws IOException {
    try {
        Document doc;
        if (ModuleType.get(module) instanceof JavaModuleType) {
            doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.project.xml"));
        } else {
            doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.empty.project.xml"));
        }
        doc.getRootElement().getChild(EclipseXml.NAME_TAG).setText(module.getName());
        final File projectFile = new File(storageRoot, EclipseXml.PROJECT_FILE);
        if (!FileUtil.createIfDoesntExist(projectFile)) {
            return;
        }
        EclipseJDOMUtil.output(doc.getRootElement(), projectFile, module.getProject());
        ApplicationManager.getApplication().runWriteAction(() -> {
            LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(projectFile.getPath()));
        });
    } catch (JDOMException e) {
        LOG.error(e);
    }
}
Also used : JavaModuleType(com.intellij.openapi.module.JavaModuleType) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 89 with JDOMException

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

the class XmlSerializer method deserialize.

@NotNull
public static <T> T deserialize(@NotNull URL url, Class<T> aClass) throws XmlSerializationException {
    try {
        Document document = JDOMUtil.loadDocument(url);
        document = JDOMXIncluder.resolve(document, url.toExternalForm());
        return deserialize(document.getRootElement(), aClass);
    } catch (IOException e) {
        throw new XmlSerializationException(e);
    } catch (JDOMException e) {
        throw new XmlSerializationException(e);
    }
}
Also used : IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with JDOMException

use of org.jdom.JDOMException in project aliyun-oss-java-sdk by aliyun.

the class PerftestRunner method buildScenario.

public void buildScenario(final String scenarioTypeString) {
    File confFile = new File(System.getProperty("user.dir") + File.separator + "runner_conf.xml");
    InputStream input = null;
    try {
        input = new FileInputStream(confFile);
    } catch (FileNotFoundException e) {
        log.error(e);
        Assert.fail(e.getMessage());
    }
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(input);
        Element root = doc.getRootElement();
        scenario = new TestScenario();
        scenario.setHost(root.getChildText("host"));
        scenario.setAccessId(root.getChildText("accessid"));
        scenario.setAccessKey(root.getChildText("accesskey"));
        scenario.setBucketName(root.getChildText("bucket"));
        scenario.setType(determineScenarioType(scenarioTypeString));
        Element target = root.getChild(scenarioTypeString);
        if (target != null) {
            scenario.setContentLength(Long.parseLong(target.getChildText("size")));
            scenario.setPutThreadNumber(Integer.parseInt(target.getChildText("putthread")));
            scenario.setGetThreadNumber(Integer.parseInt(target.getChildText("getthread")));
            scenario.setDurationInSeconds(Integer.parseInt(target.getChildText("time")));
            scenario.setGetQPS(Integer.parseInt(target.getChildText("getqps")));
            scenario.setPutQPS(Integer.parseInt(target.getChildText("putqps")));
        } else {
            log.error("Unable to locate XML element " + scenarioTypeString);
            Assert.fail("Unable to locate XML element " + scenarioTypeString);
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.jdom.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

JDOMException (org.jdom.JDOMException)137 IOException (java.io.IOException)103 Element (org.jdom.Element)82 Document (org.jdom.Document)49 SAXBuilder (org.jdom.input.SAXBuilder)45 File (java.io.File)22 StringReader (java.io.StringReader)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 ArrayList (java.util.ArrayList)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 List (java.util.List)9 CommandException (org.apache.oozie.command.CommandException)9 InputStream (java.io.InputStream)8 Namespace (org.jdom.Namespace)8 SAXException (org.xml.sax.SAXException)8 URL (java.net.URL)7 HashMap (java.util.HashMap)7 THashMap (gnu.trove.THashMap)6 InvalidDataException (com.intellij.openapi.util.InvalidDataException)5