Search in sources :

Example 41 with JDOMException

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

the class FlexCompilerConfigFileUtilBase method mergeWithCustomConfigFile.

public static String mergeWithCustomConfigFile(final String generatedConfigText, final String additionalConfigFilePath, final boolean makeExternalLibsMerged, final boolean makeIncludedLibsMerged) {
    final File additionalConfigFile = new File(additionalConfigFilePath);
    if (!additionalConfigFile.isFile()) {
        return generatedConfigText;
    }
    final Element rootElement;
    try {
        rootElement = JDOMUtil.load(additionalConfigFile);
    } catch (JDOMException | IOException e) {
        return generatedConfigText;
    }
    if (!FLEX_CONFIG.equals(rootElement.getName())) {
        return generatedConfigText;
    }
    removeSwcSpecificElementsRecursively(rootElement);
    makeLibrariesMergedIntoCode(rootElement, makeExternalLibsMerged, makeIncludedLibsMerged);
    try {
        final Element otherRootElement = JDOMUtil.load(generatedConfigText);
        assert FLEX_CONFIG.equals(rootElement.getName()) : JDOMUtil.writeElement(rootElement);
        appendDocument(rootElement, otherRootElement);
    } catch (IOException | JDOMException e) {
        assert false : e.getMessage() + "\n" + generatedConfigText;
    }
    return JDOMUtil.writeElement(rootElement);
}
Also used : Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 42 with JDOMException

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

the class FlexBuilderUtils method fixInitialContent.

private static String fixInitialContent(final File descriptorFile, final String swfName) throws IOException, JDOMException {
    // hardcoded UTF-8 makes it work the same way as it worked in FlexCompilationUtils.fixInitialContent() for ages (UTF-8 is hardcoded in JDOMUtil)
    final String descriptorContent = FileUtil.loadFile(descriptorFile, "UTF-8");
    final Element rootElement = JDOMUtil.load(StringUtil.trimStart(descriptorContent, ""));
    if (!"application".equals(rootElement.getName())) {
        throw new JDOMException("incorrect root tag");
    }
    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.write(rootElement, SystemProperties.getLineSeparator());
}
Also used : Element(org.jdom.Element) JDOMException(org.jdom.JDOMException)

Example 43 with JDOMException

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

the class FlexBuilderUtils method replaceMacros.

private static String replaceMacros(final String wrapperText, final String outputFileName, final String targetPlayer, final String mainClassPath) {
    final Map<String, String> replacementMap = new THashMap<>();
    replacementMap.put(FlexCommonUtils.SWF_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.TITLE_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.APPLICATION_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.BG_COLOR_MACRO, "#ffffff");
    replacementMap.put(FlexCommonUtils.WIDTH_MACRO, "100%");
    replacementMap.put(FlexCommonUtils.HEIGHT_MACRO, "100%");
    final List<String> versionParts = StringUtil.split(targetPlayer, ".");
    replacementMap.put(FlexCommonUtils.VERSION_MAJOR_MACRO, versionParts.size() >= 1 ? versionParts.get(0) : "0");
    replacementMap.put(FlexCommonUtils.VERSION_MINOR_MACRO, versionParts.size() >= 2 ? versionParts.get(1) : "0");
    replacementMap.put(FlexCommonUtils.VERSION_REVISION_MACRO, versionParts.size() >= 3 ? versionParts.get(2) : "0");
    String swfMetadata = null;
    final File mainClassFile = new File(mainClassPath);
    if (mainClassFile.isFile()) {
        try {
            if (FileUtilRt.extensionEquals(mainClassPath, "mxml")) {
                final Element rootElement = JDOMUtil.load(mainClassFile);
                Element metadataElement = rootElement.getChild("Metadata", Namespace.getNamespace("http://www.adobe.com/2006/mxml"));
                if (metadataElement == null) {
                    metadataElement = rootElement.getChild("Metadata", Namespace.getNamespace("http://ns.adobe.com/mxml/2009"));
                }
                if (metadataElement != null) {
                    swfMetadata = getSwfMetadata(metadataElement.getTextNormalize());
                }
            } else if (FileUtilRt.extensionEquals(mainClassPath, "as")) {
                swfMetadata = getSwfMetadata(FileUtil.loadFile(mainClassFile));
            }
        } catch (JDOMException | IOException ignore) {
        /*unlucky*/
        }
    }
    final Map<String, String> attributesMap = getAttributesMap(swfMetadata);
    ContainerUtil.putIfNotNull(FlexCommonUtils.TITLE_MACRO, attributesMap.get(FlexCommonUtils.TITLE_ATTR), replacementMap);
    ContainerUtil.putIfNotNull(FlexCommonUtils.BG_COLOR_MACRO, attributesMap.get(FlexCommonUtils.BG_COLOR_ATTR), replacementMap);
    ContainerUtil.putIfNotNull(FlexCommonUtils.WIDTH_MACRO, attributesMap.get(FlexCommonUtils.WIDTH_ATTR), replacementMap);
    ContainerUtil.putIfNotNull(FlexCommonUtils.HEIGHT_MACRO, attributesMap.get(FlexCommonUtils.HEIGHT_ATTR), replacementMap);
    return FlexCommonUtils.replace(wrapperText, replacementMap);
}
Also used : THashMap(gnu.trove.THashMap) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 44 with JDOMException

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

the class FlashBuilderSdkFinder method loadSdkInfoDocument.

@Nullable
private static Element loadSdkInfoDocument(final String flashBuilderWorkspacePath) {
    try {
        final VirtualFile projectPrefsFile = LocalFileSystem.getInstance().findFileByPath(flashBuilderWorkspacePath + FlashBuilderProjectFinder.PROJECT_PREFS_RELATIVE_PATH);
        if (projectPrefsFile == null)
            return null;
        final Properties projectPrefsProperties = new Properties();
        projectPrefsProperties.load(projectPrefsFile.getInputStream());
        final String xmlString = projectPrefsProperties.getProperty(FLEX_SDK_PROPERTY);
        if (xmlString == null)
            return null;
        return JDOMUtil.load(xmlString);
    } catch (IOException e) {
    /*ignore*/
    } catch (JDOMException e) {
    /*ignore*/
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with JDOMException

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

the class FlashBuilderProjectLoadUtil method loadInfoFromDotFlexLibPropertiesFile.

private static void loadInfoFromDotFlexLibPropertiesFile(final FlashBuilderProject project, final VirtualFile dotProjectFile) {
    final VirtualFile dotFlexLibPropertiesFile = dotProjectFile.getParent().findChild(FlashBuilderImporter.DOT_FLEX_LIB_PROPERTIES);
    if (dotFlexLibPropertiesFile != null) {
        try {
            final Element flexLibPropertiesElement = JDOMUtil.load(dotFlexLibPropertiesFile.getInputStream());
            if (!FLEX_LIB_PROPERTIES_TAG.equals(flexLibPropertiesElement.getName()))
                return;
            if (project.getTargetPlatform() == TargetPlatform.Desktop && "true".equals(flexLibPropertiesElement.getAttributeValue(USE_MULTIPLATFORM_CONFIG_ATTR))) {
                project.setTargetPlatform(TargetPlatform.Mobile);
            }
            //noinspection unchecked
            for (final Element namespaceManifestsElement : flexLibPropertiesElement.getChildren(NAMESPACE_MANIFESTS_TAG, flexLibPropertiesElement.getNamespace())) {
                //noinspection unchecked
                for (final Element namespaceManifestEntryElement : namespaceManifestsElement.getChildren(NAMESPACE_MANIFEST_ENTRY_TAG, namespaceManifestsElement.getNamespace())) {
                    final String namespace = namespaceManifestEntryElement.getAttributeValue(NAMESPACE_ATTR);
                    final String manifestPath = namespaceManifestEntryElement.getAttributeValue(MANIFEST_ATTR);
                    if (!StringUtil.isEmpty(manifestPath) && !StringUtil.isEmpty(namespace)) {
                        project.addNamespaceAndManifestPath(namespace, FileUtil.toSystemIndependentName(manifestPath));
                    }
                }
            }
            //noinspection unchecked
            for (final Element includeResourcesElement : flexLibPropertiesElement.getChildren(INCLUDE_RESOURCES_ELEMENT, flexLibPropertiesElement.getNamespace())) {
                //noinspection unchecked
                for (final Element resourceEntryElement : includeResourcesElement.getChildren(RESOURCE_ENTRY_ELEMENT, includeResourcesElement.getNamespace())) {
                    final String sourcePath = resourceEntryElement.getAttributeValue(SOURCE_PATH_ATTR);
                    if (!StringUtil.isEmpty(sourcePath)) {
                        project.addFileIncludedInSwc(FileUtil.toSystemIndependentName(sourcePath));
                    }
                }
            }
        } catch (JDOMException ignored) {
        /*ignore*/
        } catch (IOException ignored) {
        /*ignore*/
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) IOException(java.io.IOException) 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