Search in sources :

Example 21 with JDOMException

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

the class SwcCatalogXmlUtil method parseTimestampsFromCatalogXml.

@SuppressWarnings({ "unchecked" })
private static THashMap<String, TObjectLongHashMap<String>> parseTimestampsFromCatalogXml(@NotNull final VirtualFile catalogFile) {
    //  <swc xmlns="http://www.adobe.com/flash/swccatalog/9">
    //    <libraries>
    //      <library path="library.swf">                                                                    take swf name here
    //        <script name="flash/sampler/StackFrame" mod="1256700285949" signatureChecksum="121164004" >   name attribute is not FQN, take only mod here
    //          <def id="flash.sampler:Sample" />                                                           multiple defs possible
    //          <def id="flash.sampler:clearSamples" />
    //          ...
    final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = new THashMap<>(1);
    try {
        final Element rootElement = JDOMUtil.load(catalogFile.getInputStream());
        if (rootElement != null && "swc".equals(rootElement.getName())) {
            for (final Element librariesElement : rootElement.getChildren("libraries", rootElement.getNamespace())) {
                for (final Element libraryElement : librariesElement.getChildren("library", librariesElement.getNamespace())) {
                    final String swfName = libraryElement.getAttributeValue("path");
                    if (StringUtil.isEmpty(swfName)) {
                        continue;
                    }
                    final TObjectLongHashMap<String> qNameWithTimestampMap = new TObjectLongHashMap<>();
                    swfNameToQnameWithTimestampMap.put(swfName, qNameWithTimestampMap);
                    for (final Element scriptElement : libraryElement.getChildren("script", libraryElement.getNamespace())) {
                        final String mod = scriptElement.getAttributeValue("mod");
                        if (StringUtil.isEmpty(mod)) {
                            continue;
                        }
                        try {
                            final long timestamp = Long.parseLong(mod);
                            for (final Element defElement : scriptElement.getChildren("def", scriptElement.getNamespace())) {
                                final String id = defElement.getAttributeValue("id");
                                if (!StringUtil.isEmpty(id)) {
                                    final String fqn = id.replace(':', '.');
                                    qNameWithTimestampMap.put(fqn, timestamp);
                                }
                            }
                        } catch (NumberFormatException ignored) {
                        /*ignore*/
                        }
                    }
                }
            }
        }
    } catch (JDOMException ignored) {
    /*ignore*/
    } catch (IOException ignored) {
    /*ignore*/
    }
    return swfNameToQnameWithTimestampMap;
}
Also used : TObjectLongHashMap(gnu.trove.TObjectLongHashMap) THashMap(gnu.trove.THashMap) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 22 with JDOMException

use of org.jdom.JDOMException 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)

Example 23 with JDOMException

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

the class FlexCommonUtils method findXMLElement.

@Nullable
public static String findXMLElement(final InputStream is, final String xmlElement) {
    // xmlElement has format "<root_tag><child_tag>"
    final List<String> elementNames = StringUtil.split(StringUtil.replace(xmlElement, ">", ""), "<");
    if (elementNames.isEmpty())
        return null;
    try {
        final Element root = JDOMUtil.load(is);
        if (!root.getName().equals(elementNames.get(0))) {
            return null;
        }
        Element element = root;
        int depth = 0;
        while (elementNames.size() > ++depth) {
            element = element.getChild(elementNames.get(depth), element.getNamespace());
            if (element == null) {
                return null;
            }
        }
        return element.getTextNormalize();
    } catch (JDOMException | IOException ignore) {
    /**/
    }
    return null;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) Element(org.jdom.Element) JDOMException(org.jdom.JDOMException) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with JDOMException

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

the class InfoFromConfigFile method getInfoFromConfigFile.

@NotNull
public static InfoFromConfigFile getInfoFromConfigFile(final String configFilePath) {
    final File configFile = configFilePath.isEmpty() ? null : new File(configFilePath);
    if (configFile == null || !configFile.isFile()) {
        ourCache.remove(configFilePath);
        return DEFAULT;
    }
    String canonicalPath;
    try {
        canonicalPath = configFile.getCanonicalPath();
    } catch (IOException e) {
        canonicalPath = configFile.getPath();
    }
    Pair<Long, InfoFromConfigFile> data = ourCache.get(canonicalPath);
    final Long currentTimestamp = configFile.lastModified();
    final Long cachedTimestamp = data == null ? null : data.first;
    if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
        ourCache.remove(canonicalPath);
        String mainClassPath = null;
        String outputPath = null;
        String targetPlayer = null;
        try {
            final Element rootElement = JDOMUtil.load(configFile);
            final Element fileSpecsElement = rootElement.getChild("file-specs", rootElement.getNamespace());
            mainClassPath = fileSpecsElement == null ? null : fileSpecsElement.getChildTextNormalize("path-element", rootElement.getNamespace());
            outputPath = rootElement.getChildTextNormalize("output", rootElement.getNamespace());
            if (outputPath != null && !FileUtil.isAbsolute(outputPath)) {
                try {
                    outputPath = FileUtil.toSystemIndependentName(new File(configFile.getParent(), outputPath).getCanonicalPath());
                } catch (IOException e) {
                    outputPath = FileUtil.toSystemIndependentName(new File(configFile.getParent(), outputPath).getAbsolutePath());
                }
            }
            targetPlayer = rootElement.getChildTextNormalize("target-player", rootElement.getNamespace());
        } catch (IOException | JDOMException ignore) {
        /*ignore*/
        }
        final String outputFileName = outputPath == null ? null : PathUtilRt.getFileName(outputPath);
        final String outputFolderPath = outputPath == null ? null : PathUtilRt.getParentPath(outputPath);
        data = Pair.create(currentTimestamp, new InfoFromConfigFile(configFile, mainClassPath, outputFileName, outputFolderPath, targetPlayer));
        ourCache.put(canonicalPath, data);
    }
    return data.second;
}
Also used : Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with JDOMException

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

the class FlexCommonUtils method parseAirVersionFromDescriptorFile.

@Nullable
public static String parseAirVersionFromDescriptorFile(final String descriptorFilePath) {
    if (StringUtil.isEmpty(descriptorFilePath))
        return null;
    try {
        final Element rootElement = JDOMUtil.load(new File(descriptorFilePath));
        final String localName = rootElement.getName();
        final Namespace namespace = rootElement.getNamespace();
        if ("application".equals(localName) && namespace != null && namespace.getURI().startsWith(AIR_NAMESPACE_BASE)) {
            return namespace.getURI().substring(AIR_NAMESPACE_BASE.length());
        }
    } catch (JDOMException | IOException e) {
    /*unlucky*/
    }
    return null;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) Element(org.jdom.Element) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JDOMException (org.jdom.JDOMException)67 IOException (java.io.IOException)55 Element (org.jdom.Element)44 Document (org.jdom.Document)22 File (java.io.File)17 SAXBuilder (org.jdom.input.SAXBuilder)15 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 StringReader (java.io.StringReader)8 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