Search in sources :

Example 46 with JDOMException

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

the class FlashBuilderProjectLoadUtil method loadMapFromDotFxpPropertiesFile.

private static Map<String, String> loadMapFromDotFxpPropertiesFile(final VirtualFile dotProjectFile) {
    final Map<String, String> result = new THashMap<>();
    final VirtualFile dir = dotProjectFile.getParent();
    assert dir != null;
    final VirtualFile dotFxpPropertiesFile = dir.findChild(FlashBuilderImporter.DOT_FXP_PROPERTIES);
    if (dotFxpPropertiesFile != null) {
        try {
            final Element fxpPropertiesElement = JDOMUtil.load(dotFxpPropertiesFile.getInputStream());
            if (!FXP_PROPERTIES_TAG.equals(fxpPropertiesElement.getName()))
                return Collections.emptyMap();
            final Element swcElement = fxpPropertiesElement.getChild(SWC_TAG);
            if (swcElement != null) {
                //noinspection unchecked
                for (final Element linkedElement : swcElement.getChildren(LINKED_TAG)) {
                    final String location = linkedElement.getAttributeValue(LOCATION_ATTR);
                    final String path = linkedElement.getAttributeValue(PATH_ATTR);
                    if (!StringUtil.isEmptyOrSpaces(location) && !StringUtil.isEmptyOrSpaces(path)) {
                        result.put(location, path);
                    }
                }
            }
        } catch (JDOMException ignored) {
        /*ignore*/
        } catch (IOException ignored) {
        /*ignore*/
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 47 with JDOMException

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

the class ProjectsData method serialize.

public Element serialize() {
    XStream xStream = new XStream(new DomDriver());
    String s = xStream.toXML(myStatus);
    try {
        return new SAXBuilder().build(new StringReader(s)).getRootElement();
    } catch (JDOMException e) {
        LOG.error(e.getMessage(), e);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
    return new Element("");
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) SAXBuilder(org.jdom.input.SAXBuilder) XStream(com.thoughtworks.xstream.XStream) Element(org.jdom.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 48 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 49 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 50 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)

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