Search in sources :

Example 56 with JDOMException

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

the class IdeaPluginDescriptorImpl method readExternal.

public void readExternal(@NotNull URL url) throws InvalidDataException, FileNotFoundException {
    try {
        Document document = JDOMUtil.loadDocument(url);
        readExternal(document, url, JDOMXIncluder.DEFAULT_PATH_RESOLVER);
    } catch (FileNotFoundException e) {
        throw e;
    } catch (IOException e) {
        throw new InvalidDataException(e);
    } catch (JDOMException e) {
        throw new InvalidDataException(e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 57 with JDOMException

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

the class JpsLoaderBase method loadRootElement.

protected static Element loadRootElement(final File file, final JpsMacroExpander macroExpander) {
    try {
        final Element element = tryLoadRootElement(file);
        macroExpander.substitute(element, SystemInfo.isFileSystemCaseSensitive);
        return element;
    } catch (JDOMException e) {
        throw new CannotLoadJpsModelException(file, "Cannot parse xml file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
    } catch (IOException e) {
        throw new CannotLoadJpsModelException(file, "Cannot read file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
    }
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 58 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 59 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 60 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)

Aggregations

JDOMException (org.jdom.JDOMException)72 IOException (java.io.IOException)59 Element (org.jdom.Element)46 Document (org.jdom.Document)27 SAXBuilder (org.jdom.input.SAXBuilder)20 File (java.io.File)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 StringReader (java.io.StringReader)9 THashMap (gnu.trove.THashMap)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 InvalidDataException (com.intellij.openapi.util.InvalidDataException)5 Path (java.nio.file.Path)4 Logger (com.intellij.openapi.diagnostic.Logger)3 Project (com.intellij.openapi.project.Project)3 StringWriter (java.io.StringWriter)3 Format (org.jdom.output.Format)3 XMLOutputter (org.jdom.output.XMLOutputter)3