Search in sources :

Example 26 with JDOMException

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

the class RuntimeModulesGenerateConfigTask method getClonedRootElementOfMainConfigFile.

@Nullable
private static Element getClonedRootElementOfMainConfigFile(final String filePath) {
    final VirtualFile configFile = LocalFileSystem.getInstance().findFileByPath(filePath);
    if (configFile != null) {
        try {
            final Document document = JDOMUtil.loadDocument(configFile.getInputStream());
            final Element clonedRootElement = document.clone().getRootElement();
            if (clonedRootElement.getName().equals(FLEX_CONFIG)) {
                return clonedRootElement;
            }
        } catch (JDOMException ignored) {
        /*ignore*/
        } catch (IOException ignored) {
        /*ignore*/
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with JDOMException

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

the class FlashBuilderProjectLoadUtil method loadInfoFromDotActionScriptPropertiesFile.

private static void loadInfoFromDotActionScriptPropertiesFile(final FlashBuilderProject project, final VirtualFile dotProjectFile, final Map<String, String> pathReplacementMap) {
    final VirtualFile dir = dotProjectFile.getParent();
    assert dir != null;
    final VirtualFile dotActionScriptPropertiesFile = dir.findChild(FlashBuilderImporter.DOT_ACTION_SCRIPT_PROPERTIES);
    if (dotActionScriptPropertiesFile != null) {
        try {
            final Element actionScriptPropertiesElement = JDOMUtil.load(dotActionScriptPropertiesFile.getInputStream());
            if (!ACTION_SCRIPT_PROPERTIES_TAG.equals(actionScriptPropertiesElement.getName()))
                return;
            loadMainClassName(project, actionScriptPropertiesElement);
            final Element compilerElement = actionScriptPropertiesElement.getChild(COMPILER_TAG);
            if (compilerElement != null) {
                loadProjectType(project, dotProjectFile, compilerElement);
                loadSourcePaths(project, compilerElement);
                loadOutputFolderPath(project, compilerElement);
                loadTargetPlayerVersion(project, compilerElement);
                loadAdditionalCompilerArguments(project, compilerElement);
                project.setUseHtmlWrapper("true".equals(compilerElement.getAttributeValue(HTML_GENERATE_ATTR)));
                loadDependenciesAndCheckIfSdkUsed(project, compilerElement, pathReplacementMap);
                if (project.isSdkUsed()) {
                    loadSdkName(project, compilerElement);
                }
            }
            if (project.getOutputType() == OutputType.Application) {
                loadApplications(project, actionScriptPropertiesElement);
                loadModules(project, actionScriptPropertiesElement);
                loadCssFilesToCompile(project, actionScriptPropertiesElement);
                if (!project.isPureActionScript()) {
                    loadTheme(project, actionScriptPropertiesElement);
                }
            }
        } 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)

Example 28 with JDOMException

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

the class FlashBuilderProjectLoadUtil method loadProjectNameAndLinkedResources.

private static void loadProjectNameAndLinkedResources(final FlashBuilderProject project, final VirtualFile dotProjectFile) {
    try {
        final Element projectDescription = JDOMUtil.load(dotProjectFile.getInputStream());
        if (!PROJECT_DESCRIPTION_TAG.equals(projectDescription.getName()))
            return;
        final String projectName = projectDescription.getChildText(NAME_TAG, projectDescription.getNamespace());
        project.setName(StringUtil.notNullize(projectName, FlexBundle.message("unnamed")));
        //noinspection unchecked
        for (final Element linkedResourcesElement : projectDescription.getChildren(LINKED_RESOURCES_TAG, projectDescription.getNamespace())) {
            //noinspection unchecked
            for (final Element linkElement : linkedResourcesElement.getChildren(LINK_TAG, linkedResourcesElement.getNamespace())) {
                final String linkName = linkElement.getChildText(NAME_TAG, linkElement.getNamespace());
                final String linkLocation = linkElement.getChildText(LOCATION_TAG, linkElement.getNamespace());
                if (!StringUtil.isEmptyOrSpaces(linkName) && !StringUtil.isEmptyOrSpaces(linkLocation)) {
                    project.addLinkedResource(linkName, FileUtil.toSystemIndependentName(linkLocation));
                }
            }
        }
    } catch (JDOMException ignored) {
    /*ignore*/
    } catch (IOException ignored) {
    /*ignore*/
    }
}
Also used : Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 29 with JDOMException

use of org.jdom.JDOMException in project beast-mcmc by beast-dev.

the class BeautiFrame method importFiles.

private void importFiles(File[] files) {
    for (File file : files) {
        if (file == null || file.getName().equals("")) {
            JOptionPane.showMessageDialog(this, "Invalid file name", "Invalid file name", JOptionPane.ERROR_MESSAGE);
        } else {
            try {
                BEAUTiImporter beautiImporter = new BEAUTiImporter(this, options);
                beautiImporter.importFromFile(file);
                setDirty();
            //                    } catch (FileNotFoundException fnfe) {
            //                        JOptionPane.showMessageDialog(this, "Unable to open file: File not found",
            //                                "Unable to open file", JOptionPane.ERROR_MESSAGE);
            } catch (IOException ioe) {
                JOptionPane.showMessageDialog(this, "File I/O Error unable to read file: " + ioe.getMessage(), "Unable to read file", JOptionPane.ERROR_MESSAGE);
                ioe.printStackTrace();
            // there may be other files in the list so don't return
            //                    return;
            } catch (MissingBlockException ex) {
                JOptionPane.showMessageDialog(this, "TAXON, DATA or CHARACTERS block is missing in Nexus file: " + ex, "Missing Block in Nexus File", JOptionPane.ERROR_MESSAGE);
                ex.printStackTrace();
            } catch (ImportException ime) {
                JOptionPane.showMessageDialog(this, "Error parsing imported file: " + ime, "Error reading file", JOptionPane.ERROR_MESSAGE);
                ime.printStackTrace();
            } catch (JDOMException jde) {
                JOptionPane.showMessageDialog(this, "Error parsing imported file: " + jde, "Error reading file", JOptionPane.ERROR_MESSAGE);
                jde.printStackTrace();
            }
        }
    }
    if (!options.hasIdenticalTaxa()) {
        // need this to refresh panels otherwise it will throw exception
        setAllOptions();
        dataPanel.selectAll();
        dataPanel.unlinkTrees();
    }
    setAllOptions();
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) JDOMException(org.jdom.JDOMException) BEAUTiImporter(dr.app.beauti.util.BEAUTiImporter) MissingBlockException(dr.evolution.io.NexusImporter.MissingBlockException)

Example 30 with JDOMException

use of org.jdom.JDOMException in project che by eclipse.

the class EffectivePomWriter method addMavenNamespace.

/**
     * method from org.apache.maven.plugins.help.AbstractEffectiveMojo
     * Add a Pom/Settings namespaces to the effective XML content.
     *
     * @param effectiveXml not null the effective POM or Settings
     * @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
     * @return the content of the root element, i.e. &lt;project/&gt; or &lt;settings/&gt; with the Maven namespace or
     *         the original <code>effective</code> if an error occurred.
     * @see #POM_XSD_URL
     * @see #SETTINGS_XSD_URL
     */
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document document = builder.build(new StringReader(effectiveXml));
        Element rootElement = document.getRootElement();
        // added namespaces
        Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
        rootElement.setNamespace(pomNamespace);
        Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        rootElement.addNamespaceDeclaration(xsiNamespace);
        if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
            rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
        }
        ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
        for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
            Element e = (Element) i.next();
            e.setNamespace(pomNamespace);
        }
        StringWriter w = new StringWriter();
        Format format = Format.getPrettyFormat();
        XMLOutputter out = new XMLOutputter(format);
        out.output(document.getRootElement(), w);
        return w.toString();
    } catch (JDOMException e) {
        return effectiveXml;
    } catch (IOException e) {
        return effectiveXml;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StringWriter(java.io.StringWriter) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

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