Search in sources :

Example 51 with JDOMException

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

the class SchemeImportUtil method loadSchemeDom.

@NotNull
public static Element loadSchemeDom(@NotNull VirtualFile file) throws SchemeImportException {
    InputStream inputStream = null;
    try {
        inputStream = file.getInputStream();
        final Document document = JDOMUtil.loadDocument(inputStream);
        final Element root = document.getRootElement();
        inputStream.close();
        return root;
    } catch (IOException | JDOMException e) {
        throw new SchemeImportException("Can't read from" + file.getName() + ", " + e.getMessage());
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) FileElement(com.intellij.openapi.fileChooser.FileElement) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with JDOMException

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

the class CoreProjectLoader method loadDirectoryProject.

private static void loadDirectoryProject(MockProject project, @NotNull VirtualFile dotIdea) throws IOException, JDOMException {
    VirtualFile modulesXml = dotIdea.findChild("modules.xml");
    if (modulesXml == null)
        throw new FileNotFoundException("Missing 'modules.xml' in " + dotIdea.getPath());
    TreeMap<String, Element> storageData = loadStorageFile(project, modulesXml);
    final Element moduleManagerState = storageData.get("ProjectModuleManager");
    if (moduleManagerState == null) {
        throw new JDOMException("cannot find ProjectModuleManager state in modules.xml");
    }
    final CoreModuleManager moduleManager = (CoreModuleManager) ModuleManager.getInstance(project);
    moduleManager.loadState(moduleManagerState);
    VirtualFile miscXml = dotIdea.findChild("misc.xml");
    if (miscXml != null) {
        storageData = loadStorageFile(project, miscXml);
        final Element projectRootManagerState = storageData.get("ProjectRootManager");
        if (projectRootManagerState == null) {
            throw new JDOMException("cannot find ProjectRootManager state in misc.xml");
        }
        ((ProjectRootManagerImpl) ProjectRootManager.getInstance(project)).loadState(projectRootManagerState);
    }
    VirtualFile libraries = dotIdea.findChild("libraries");
    if (libraries != null) {
        Map<String, Element> data = DirectoryStorageUtil.loadFrom(libraries, PathMacroManager.getInstance(project));
        Element libraryTable = DefaultStateSerializer.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
        ((LibraryTableBase) ProjectLibraryTable.getInstance(project)).loadState(libraryTable);
    }
    moduleManager.loadModules();
    project.projectOpened();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectRootManagerImpl(com.intellij.openapi.roots.impl.ProjectRootManagerImpl) Element(org.jdom.Element) FileNotFoundException(java.io.FileNotFoundException) LibraryTableBase(com.intellij.openapi.roots.impl.libraries.LibraryTableBase) JDOMException(org.jdom.JDOMException)

Example 53 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 54 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, "*/", "&#42;&#47;");
    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 55 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)

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