Search in sources :

Example 81 with JDOMException

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

the class ProjectUtil method openProject.

@Nullable
public static Project openProject(final String path, @Nullable Project projectToClose, boolean forceOpenInNewFrame) {
    File file = new File(path);
    if (!file.exists()) {
        Messages.showErrorDialog(IdeBundle.message("error.project.file.does.not.exist", path), CommonBundle.getErrorTitle());
        return null;
    }
    if (file.isDirectory()) {
        File dir = new File(file, Project.DIRECTORY_STORE_FOLDER);
        if (!dir.exists()) {
            String message = IdeBundle.message("error.project.file.does.not.exist", dir.getPath());
            Messages.showErrorDialog(message, CommonBundle.getErrorTitle());
            return null;
        }
    }
    Project existing = findAndFocusExistingProjectForPath(path);
    if (existing != null)
        return existing;
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    if (!forceOpenInNewFrame && openProjects.length > 0) {
        int exitCode = confirmOpenNewProject(false);
        if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) {
            final Project toClose = projectToClose != null ? projectToClose : openProjects[openProjects.length - 1];
            if (!closeAndDispose(toClose))
                return null;
        } else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) {
            return null;
        }
    }
    if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(path)) {
        if (!confirmLoadingFromRemotePath(path, "warning.load.project.from.share", "title.load.project.from.share")) {
            return null;
        }
    }
    ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    Project project = null;
    try {
        project = projectManager.loadAndOpenProject(path);
    } catch (IOException e) {
        Messages.showMessageDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
    } catch (JDOMException | InvalidDataException e) {
        LOG.info(e);
        Messages.showMessageDialog(IdeBundle.message("error.project.file.is.corrupted"), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
    }
    return project;
}
Also used : Project(com.intellij.openapi.project.Project) InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Nullable(org.jetbrains.annotations.Nullable)

Example 82 with JDOMException

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

the class JavaDocInfoGenerator method generatePackageHtmlJavaDoc.

private void generatePackageHtmlJavaDoc(final StringBuilder buffer, final PsiFile packageHtmlFile, boolean generatePrologueAndEpilogue) {
    String htmlText = packageHtmlFile.getText();
    try {
        final Document document = JDOMUtil.loadDocument(new ByteArrayInputStream(htmlText.getBytes(CharsetToolkit.UTF8_CHARSET)));
        final Element rootTag = document.getRootElement();
        final Element subTag = rootTag.getChild("body");
        if (subTag != null) {
            htmlText = subTag.getValue();
        }
    } catch (JDOMException | IOException ignore) {
    }
    htmlText = StringUtil.replace(htmlText, "*/", "*/");
    final String fileText = "/** " + htmlText + " */";
    final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(packageHtmlFile.getProject()).getElementFactory();
    final PsiDocComment docComment;
    try {
        docComment = elementFactory.createDocCommentFromText(fileText);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
        return;
    }
    if (generatePrologueAndEpilogue)
        generatePrologue(buffer);
    generateCommonSection(buffer, docComment);
    if (generatePrologueAndEpilogue)
        generateEpilogue(buffer);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jdom.Element) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 83 with JDOMException

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

the class InspectionProfileConvertor method renameOldDefaultsProfile.

private static void renameOldDefaultsProfile() {
    Path directoryPath = Paths.get(PathManager.getConfigPath(), InspectionProfileManager.INSPECTION_DIR);
    if (!PathKt.exists(directoryPath)) {
        return;
    }
    File[] files = directoryPath.toFile().listFiles(pathname -> pathname.getPath().endsWith(File.separator + DEFAULT_XML));
    if (files == null || files.length != 1 || !files[0].isFile() || files[0].length() == 0) {
        return;
    }
    try {
        Element root = JdomKt.loadElement(files[0].toPath());
        if (root.getAttributeValue(VERSION_ATT) == null) {
            JdomKt.write(root, directoryPath.resolve(OLD_DEFAUL_PROFILE + XML_EXTENSION));
            FileUtil.delete(files[0]);
        }
    } catch (IOException | JDOMException e) {
        LOG.error(e);
    }
}
Also used : Path(java.nio.file.Path) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 84 with JDOMException

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

the class IdeaPluginDescriptorImpl method readExternal.

public void readExternal(@NotNull URL url) throws InvalidDataException, FileNotFoundException {
    try {
        Document document = JDOMUtil.loadDocument(url);
        readExternal(document, url, JDOMXIncluder.DEFAULT_PATH_RESOLVER);
    } catch (FileNotFoundException e) {
        throw e;
    } catch (IOException e) {
        throw new InvalidDataException(e);
    } catch (JDOMException e) {
        throw new InvalidDataException(e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 85 with JDOMException

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

the class JpsLoaderBase method loadRootElement.

protected static Element loadRootElement(final File file, final JpsMacroExpander macroExpander) {
    try {
        final Element element = tryLoadRootElement(file);
        macroExpander.substitute(element, SystemInfo.isFileSystemCaseSensitive);
        return element;
    } catch (JDOMException e) {
        throw new CannotLoadJpsModelException(file, "Cannot parse xml file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
    } catch (IOException e) {
        throw new CannotLoadJpsModelException(file, "Cannot read file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
    }
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) Element(org.jdom.Element) IOException(java.io.IOException) 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