Search in sources :

Example 76 with JDOMException

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

the class RslUtil method getSwcPathToRslUrlsMap.

private static synchronized Map<String, List<String>> getSwcPathToRslUrlsMap(final String sdkHome) {
    final String configFilePath = sdkHome + "/frameworks/flex-config.xml";
    final File configFile = new File(configFilePath);
    if (!configFile.isFile()) {
        LOG.warn("File not found: " + configFilePath);
        ourConfigFilePathToTimestampAndSwcPathToRslUrls.remove(configFilePath);
        return Collections.emptyMap();
    }
    Pair<Long, Map<String, List<String>>> data = ourConfigFilePathToTimestampAndSwcPathToRslUrls.get(configFilePath);
    final Long currentTimestamp = configFile.lastModified();
    final Long cachedTimestamp = data == null ? null : data.first;
    if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
        ourConfigFilePathToTimestampAndSwcPathToRslUrls.remove(configFilePath);
        final Map<String, List<String>> swcPathToRslMap = new THashMap<>();
        try {
            final Element rootElement = JDOMUtil.load(configFile);
            for (Element rslElement : rootElement.getChildren("runtime-shared-library-path", rootElement.getNamespace())) {
                final Element swcPathElement = rslElement.getChild("path-element", rslElement.getNamespace());
                if (swcPathElement != null) {
                    final List<String> rslUrls = new ArrayList<>(2);
                    for (Element rslUrlElement : rslElement.getChildren("rsl-url", rootElement.getNamespace())) {
                        final String rslUrl = rslUrlElement.getTextNormalize();
                        rslUrls.add(rslUrl);
                    }
                    final String swcPath = PathUtilRt.getParentPath(configFilePath) + "/" + swcPathElement.getTextNormalize();
                    swcPathToRslMap.put(SystemInfo.isFileSystemCaseSensitive ? swcPath : swcPath.toLowerCase(), rslUrls);
                }
            }
        } catch (IOException | JDOMException e) {
            LOG.warn(configFilePath, e);
        }
        data = Pair.create(currentTimestamp, swcPathToRslMap);
        ourConfigFilePathToTimestampAndSwcPathToRslUrls.put(configFilePath, data);
    }
    return data.second;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) THashMap(gnu.trove.THashMap) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Example 77 with JDOMException

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

the class JSConditionalCompilationDefinitionsProviderImpl method getDefinitionsFromConfigFile.

private Collection<Pair<String, String>> getDefinitionsFromConfigFile(final String configFilePath) {
    if (StringUtil.isEmptyOrSpaces(configFilePath))
        return Collections.emptyList();
    final VirtualFile configFile = LocalFileSystem.getInstance().findFileByPath(configFilePath);
    if (configFile == null || configFile.isDirectory())
        return Collections.emptyList();
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document cachedDocument = documentManager.getCachedDocument(configFile);
    final Long currentTimestamp = cachedDocument != null ? cachedDocument.getModificationStamp() : configFile.getModificationCount();
    final Long cachedTimestamp = configFileToTimestamp.get(configFile);
    if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
        configFileToTimestamp.remove(configFile);
        configFileToConditionalCompilerDefinitions.remove(configFile);
        try {
            final Element rootElement = cachedDocument == null ? JDOMUtil.load(configFile.getInputStream()) : JDOMUtil.load(cachedDocument.getCharsSequence());
            final Collection<Pair<String, String>> result = new ArrayList<>();
            if (rootElement.getName().equals(FlexCompilerConfigFileUtilBase.FLEX_CONFIG)) {
                // noinspection unchecked
                for (Element compilerElement : rootElement.getChildren(FlexCompilerConfigFileUtilBase.COMPILER, rootElement.getNamespace())) {
                    // noinspection unchecked
                    for (Element defineElement : compilerElement.getChildren(DEFINE, rootElement.getNamespace())) {
                        final String name = defineElement.getChildText(NAME, rootElement.getNamespace());
                        final String value = defineElement.getChildText(VALUE, rootElement.getNamespace());
                        if (!StringUtil.isEmpty(name) && value != null) {
                            result.add(Pair.create(name, value));
                        }
                    }
                }
            }
            configFileToTimestamp.put(configFile, currentTimestamp);
            configFileToConditionalCompilerDefinitions.put(configFile, result);
            return result;
        } catch (JDOMException ignored) {
        /*ignore*/
        } catch (IOException ignored) {
        /*ignore*/
        }
        return Collections.emptyList();
    } else {
        return configFileToConditionalCompilerDefinitions.get(configFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) ArrayList(java.util.ArrayList) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) JDOMException(org.jdom.JDOMException) Pair(com.intellij.openapi.util.Pair)

Example 78 with JDOMException

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

the class FlexCompilationUtils method fixInitialContent.

private static String fixInitialContent(final VirtualFile descriptorFile, final String swfName) throws FlexCompilerException {
    try {
        final Document document;
        try {
            document = JDOMUtil.loadDocument(descriptorFile.getInputStream());
        } catch (IOException e) {
            throw new FlexCompilerException("Failed to read AIR descriptor content: " + e.getMessage(), descriptorFile.getUrl(), -1, -1);
        }
        final Element rootElement = document.getRootElement();
        if (!"application".equals(rootElement.getName())) {
            throw new FlexCompilerException("AIR descriptor file has incorrect root tag", descriptorFile.getUrl(), -1, -1);
        }
        Element initialWindowElement = rootElement.getChild("initialWindow", rootElement.getNamespace());
        if (initialWindowElement == null) {
            initialWindowElement = new Element("initialWindow", rootElement.getNamespace());
            rootElement.addContent(initialWindowElement);
        }
        Element contentElement = initialWindowElement.getChild("content", rootElement.getNamespace());
        if (contentElement == null) {
            contentElement = new Element("content", rootElement.getNamespace());
            initialWindowElement.addContent(contentElement);
        }
        contentElement.setText(swfName);
        return JDOMUtil.writeDocument(document, SystemProperties.getLineSeparator());
    } catch (JDOMException e) {
        throw new FlexCompilerException("AIR descriptor file has incorrect format: " + e.getMessage(), descriptorFile.getUrl(), -1, -1);
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 79 with JDOMException

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

the class SchemeImportUtil method loadSchemeDom.

@NotNull
public static Element loadSchemeDom(@NotNull VirtualFile file) throws SchemeImportException {
    InputStream inputStream = null;
    try {
        inputStream = file.getInputStream();
        final Document document = JDOMUtil.loadDocument(inputStream);
        final Element root = document.getRootElement();
        inputStream.close();
        return root;
    } catch (IOException | JDOMException e) {
        throw new SchemeImportException("Can't read from" + file.getName() + ", " + e.getMessage());
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) FileElement(com.intellij.openapi.fileChooser.FileElement) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with JDOMException

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

the class CoreProjectLoader method loadDirectoryProject.

private static void loadDirectoryProject(MockProject project, @NotNull VirtualFile dotIdea) throws IOException, JDOMException {
    VirtualFile modulesXml = dotIdea.findChild("modules.xml");
    if (modulesXml == null)
        throw new FileNotFoundException("Missing 'modules.xml' in " + dotIdea.getPath());
    TreeMap<String, Element> storageData = loadStorageFile(project, modulesXml);
    final Element moduleManagerState = storageData.get("ProjectModuleManager");
    if (moduleManagerState == null) {
        throw new JDOMException("cannot find ProjectModuleManager state in modules.xml");
    }
    final CoreModuleManager moduleManager = (CoreModuleManager) ModuleManager.getInstance(project);
    moduleManager.loadState(moduleManagerState);
    VirtualFile miscXml = dotIdea.findChild("misc.xml");
    if (miscXml != null) {
        storageData = loadStorageFile(project, miscXml);
        final Element projectRootManagerState = storageData.get("ProjectRootManager");
        if (projectRootManagerState == null) {
            throw new JDOMException("cannot find ProjectRootManager state in misc.xml");
        }
        ((ProjectRootManagerImpl) ProjectRootManager.getInstance(project)).loadState(projectRootManagerState);
    }
    VirtualFile libraries = dotIdea.findChild("libraries");
    if (libraries != null) {
        Map<String, Element> data = DirectoryStorageUtil.loadFrom(libraries, PathMacroManager.getInstance(project));
        Element libraryTable = DefaultStateSerializer.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
        ((LibraryTableBase) ProjectLibraryTable.getInstance(project)).loadState(libraryTable);
    }
    moduleManager.loadModules();
    project.projectOpened();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectRootManagerImpl(com.intellij.openapi.roots.impl.ProjectRootManagerImpl) Element(org.jdom.Element) FileNotFoundException(java.io.FileNotFoundException) LibraryTableBase(com.intellij.openapi.roots.impl.libraries.LibraryTableBase) JDOMException(org.jdom.JDOMException)

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