Search in sources :

Example 21 with Document

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

the class ProductivityFeaturesRegistryImpl method readFromXml.

private void readFromXml(String path) throws JDOMException, IOException {
    final Document document = JDOMUtil.loadResourceDocument(new URL(path));
    final Element root = document.getRootElement();
    readGroups(root);
    readFilters(root);
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document) URL(java.net.URL)

Example 22 with Document

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

the class SearchableOptionsRegistrarImpl method loadHugeFilesIfNecessary.

private void loadHugeFilesIfNecessary() {
    if (allTheseHugeFilesAreLoaded) {
        return;
    }
    allTheseHugeFilesAreLoaded = true;
    try {
        //index
        final URL indexResource = ResourceUtil.getResource(SearchableOptionsRegistrar.class, "/search/", "searchableOptions.xml");
        if (indexResource == null) {
            LOG.info("No /search/searchableOptions.xml found, settings search won't work!");
            return;
        }
        Document document = JDOMUtil.loadDocument(indexResource);
        Element root = document.getRootElement();
        List configurables = root.getChildren("configurable");
        for (final Object o : configurables) {
            final Element configurable = (Element) o;
            final String id = configurable.getAttributeValue("id");
            final String groupName = configurable.getAttributeValue("configurable_name");
            final List options = configurable.getChildren("option");
            for (Object o1 : options) {
                Element optionElement = (Element) o1;
                final String option = optionElement.getAttributeValue("name");
                final String path = optionElement.getAttributeValue("path");
                final String hit = optionElement.getAttributeValue("hit");
                putOptionWithHelpId(option, id, groupName, hit, path);
            }
        }
        //synonyms
        document = JDOMUtil.loadDocument(ResourceUtil.getResource(SearchableOptionsRegistrar.class, "/search/", "synonyms.xml"));
        root = document.getRootElement();
        configurables = root.getChildren("configurable");
        for (final Object o : configurables) {
            final Element configurable = (Element) o;
            final String id = configurable.getAttributeValue("id");
            final String groupName = configurable.getAttributeValue("configurable_name");
            final List synonyms = configurable.getChildren("synonym");
            for (Object o1 : synonyms) {
                Element synonymElement = (Element) o1;
                final String synonym = synonymElement.getTextNormalize();
                if (synonym != null) {
                    Set<String> words = getProcessedWords(synonym);
                    for (String word : words) {
                        putOptionWithHelpId(word, id, groupName, synonym, null);
                    }
                }
            }
            final List options = configurable.getChildren("option");
            for (Object o1 : options) {
                Element optionElement = (Element) o1;
                final String option = optionElement.getAttributeValue("name");
                final List list = optionElement.getChildren("synonym");
                for (Object o2 : list) {
                    Element synonymElement = (Element) o2;
                    final String synonym = synonymElement.getTextNormalize();
                    if (synonym != null) {
                        Set<String> words = getProcessedWords(synonym);
                        for (String word : words) {
                            putOptionWithHelpId(word, id, groupName, synonym, null);
                        }
                        final Couple<String> key = Couple.of(option, id);
                        Set<String> foundSynonyms = myHighlightOption2Synonym.get(key);
                        if (foundSynonyms == null) {
                            foundSynonyms = new THashSet<>();
                            myHighlightOption2Synonym.put(key, foundSynonyms);
                        }
                        foundSynonyms.add(synonym);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error(e);
    }
    ApplicationInfoEx applicationInfo = ApplicationInfoEx.getInstanceEx();
    for (IdeaPluginDescriptor plugin : PluginManagerCore.getPlugins()) {
        if (applicationInfo.isEssentialPlugin(plugin.getPluginId().getIdString())) {
            continue;
        }
        final String pluginName = plugin.getName();
        final Set<String> words = getProcessedWordsWithoutStemming(pluginName);
        final String description = plugin.getDescription();
        if (description != null) {
            words.addAll(getProcessedWordsWithoutStemming(description));
        }
        for (String word : words) {
            addOption(word, null, pluginName, PluginManagerConfigurable.ID, PluginManagerConfigurable.DISPLAY_NAME);
        }
    }
}
Also used : ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) Element(org.jdom.Element) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) Document(org.jdom.Document) URL(java.net.URL) IOException(java.io.IOException)

Example 23 with Document

use of org.jdom.Document in project android by JetBrains.

the class GuiTestRule method cleanUpProjectForImport.

public void cleanUpProjectForImport(@NotNull File projectPath) {
    File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
    if (dotIdeaFolderPath.isDirectory()) {
        File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
        if (modulesXmlFilePath.isFile()) {
            SAXBuilder saxBuilder = new SAXBuilder();
            try {
                Document document = saxBuilder.build(modulesXmlFilePath);
                XPath xpath = XPath.newInstance("//*[@fileurl]");
                //noinspection unchecked
                List<Element> modules = xpath.selectNodes(document);
                int urlPrefixSize = "file://$PROJECT_DIR$/".length();
                for (Element module : modules) {
                    String fileUrl = module.getAttributeValue("fileurl");
                    if (!StringUtil.isEmpty(fileUrl)) {
                        String relativePath = FileUtil.toSystemDependentName(fileUrl.substring(urlPrefixSize));
                        File imlFilePath = new File(projectPath, relativePath);
                        if (imlFilePath.isFile()) {
                            FileUtilRt.delete(imlFilePath);
                        }
                        // It is likely that each module has a "build" folder. Delete it as well.
                        File buildFilePath = new File(imlFilePath.getParentFile(), "build");
                        if (buildFilePath.isDirectory()) {
                            FileUtilRt.delete(buildFilePath);
                        }
                    }
                }
            } catch (Throwable ignored) {
            // if something goes wrong, just ignore. Most likely it won't affect project import in any way.
            }
        }
        FileUtilRt.delete(dotIdeaFolderPath);
    }
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 24 with Document

use of org.jdom.Document in project intellij-plugins by JetBrains.

the class FlexConversionTest method toString.

@SuppressWarnings("UnusedDeclaration")
private static String toString(Element e) {
    Element clone = e.clone();
    ConversionHelper.collapsePaths(clone);
    return JDOMUtil.writeDocument(new Document(clone), "\n");
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document)

Example 25 with Document

use of org.jdom.Document in project intellij-plugins by JetBrains.

the class P2PNetworkXmlMessage method processResponse.

void processResponse() {
    if (myMessage == null || !myMessage.needsResponse())
        return;
    try {
        final String response = getResponse().toString();
        if (!com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces(response)) {
            Document document = new SAXBuilder().build(new StringReader(response));
            myMessage.processResponse(document.getRootElement());
        }
    } catch (JDOMException e) {
        LOG.error(e.getMessage(), e);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Aggregations

Document (org.jdom.Document)144 Element (org.jdom.Element)102 SAXBuilder (org.jdom.input.SAXBuilder)51 IOException (java.io.IOException)49 JDOMException (org.jdom.JDOMException)29 File (java.io.File)27 ArrayList (java.util.ArrayList)22 XMLOutputter (org.jdom.output.XMLOutputter)22 List (java.util.List)16 StringReader (java.io.StringReader)15 Format (org.jdom.output.Format)12 VCDocument (org.vcell.util.document.VCDocument)11 XPath (org.jdom.xpath.XPath)10 StringWriter (java.io.StringWriter)9 InputStream (java.io.InputStream)8 URL (java.net.URL)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5