Search in sources :

Example 1 with JDOMException

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

the class XPathResponseHandler method lazyCompile.

@NotNull
private XPath lazyCompile(@NotNull String path) throws Exception {
    XPath xPath = myCompiledCache.get(path);
    if (xPath == null) {
        try {
            xPath = XPath.newInstance(path);
            myCompiledCache.put(path, xPath);
        } catch (JDOMException e) {
            throw new Exception(String.format("Malformed XPath expression '%s'", path));
        }
    }
    return xPath;
}
Also used : XPath(org.jdom.xpath.XPath) JDOMException(org.jdom.JDOMException) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JDOMException

use of org.jdom.JDOMException in project ideavim by JetBrains.

the class VimPlugin method setupStatisticsReporter.

/**
   * Reports statistics about installed IdeaVim and enabled Vim emulation.
   *
   * See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/commit/5182ab4a1d01ad37f6786268a2fe5e908575a217
   */
private void setupStatisticsReporter(@NotNull EventFacade eventFacade) {
    final Application application = ApplicationManager.getApplication();
    eventFacade.addEditorFactoryListener(new EditorFactoryAdapter() {

        @Override
        public void editorCreated(@NotNull EditorFactoryEvent event) {
            final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
            final long lastUpdate = propertiesComponent.getOrInitLong(IDEAVIM_STATISTICS_TIMESTAMP_KEY, 0);
            final boolean outOfDate = lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1);
            if (outOfDate && isEnabled()) {
                application.executeOnPooledThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            final String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
                            final String pluginId = IDEAVIM_PLUGIN_ID;
                            final String version = URLEncoder.encode(getVersion(), CharsetToolkit.UTF8);
                            final String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
                            final String uid = UpdateChecker.getInstallationUID(PropertiesComponent.getInstance());
                            final String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + version + "&os=" + os + "&uuid=" + uid;
                            PropertiesComponent.getInstance().setValue(IDEAVIM_STATISTICS_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                            HttpRequests.request(url).connect(new HttpRequests.RequestProcessor<Object>() {

                                @Override
                                public Object process(@NotNull HttpRequests.Request request) throws IOException {
                                    LOG.info("Sending statistics: " + url);
                                    try {
                                        JDOMUtil.load(request.getInputStream());
                                    } catch (JDOMException e) {
                                        LOG.warn(e);
                                    }
                                    return null;
                                }
                            });
                        } catch (IOException e) {
                            LOG.warn(e);
                        }
                    }
                });
            }
        }
    }, application);
}
Also used : EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) HttpRequests(com.intellij.util.io.HttpRequests) Application(com.intellij.openapi.application.Application) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 3 with JDOMException

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

the class CoreModuleManager method createAndLoadModule.

@NotNull
@Override
protected ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) throws IOException {
    final ModuleEx module = createModule(filePath);
    try {
        ModuleRootManagerImpl.ModuleRootManagerState state = new ModuleRootManagerImpl.ModuleRootManagerState();
        state.readExternal(CoreProjectLoader.loadStorageFile(module, file).get("NewModuleRootManager"));
        ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).loadState(state);
    } catch (JDOMException e) {
        throw new IOException(e);
    }
    return module;
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) ModuleEx(com.intellij.openapi.module.impl.ModuleEx) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JDOMException

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

the class PathManagerEx method getCommunityModules.

private static synchronized Set<String> getCommunityModules() {
    if (ourCommunityModules != null) {
        return ourCommunityModules;
    }
    ourCommunityModules = new THashSet<>();
    File modulesXml = findFileUnderCommunityHome(Project.DIRECTORY_STORE_FOLDER + "/modules.xml");
    if (!modulesXml.exists()) {
        throw new IllegalStateException("Cannot obtain test data path: " + modulesXml.getAbsolutePath() + " not found");
    }
    try {
        Element element = JDomSerializationUtil.findComponent(JDOMUtil.load(modulesXml), ModuleManagerImpl.COMPONENT_NAME);
        assert element != null;
        for (ModulePath file : ModuleManagerImpl.getPathsToModuleFiles(element)) {
            ourCommunityModules.add(file.getModuleName());
        }
        return ourCommunityModules;
    } catch (JDOMException | IOException e) {
        throw new RuntimeException("Cannot read modules from " + modulesXml.getAbsolutePath(), e);
    }
}
Also used : ModulePath(com.intellij.openapi.module.impl.ModulePath) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 5 with JDOMException

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

the class MigrationMapSet method loadMaps.

private void loadMaps() {
    myMaps = new ArrayList<>();
    File dir = getMapDirectory();
    copyPredefinedMaps(dir);
    File[] files = getMapFiles(dir);
    for (int i = 0; i < files.length; i++) {
        try {
            MigrationMap map = readMap(files[i]);
            if (map != null) {
                map.setFileName(FileUtil.getNameWithoutExtension(files[i]));
                myMaps.add(map);
            }
        } catch (InvalidDataException | JDOMException e) {
            LOG.error("Invalid data in file: " + files[i].getAbsolutePath());
        } catch (IOException e) {
            LOG.error(e);
        }
    }
}
Also used : InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File)

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