Package org.openide.filesystems

Examples of org.openide.filesystems.FileObject


        uis = Lookup.getDefault().lookupAll(ImporterUI.class).toArray(new ImporterUI[0]);
        wizardUis = Lookup.getDefault().lookupAll(ImporterWizardUI.class).toArray(new ImporterWizardUI[0]);
    }

    public FileImporter getFileImporter(File file) {
        FileObject fileObject = FileUtil.toFileObject(file);
        fileObject = getArchivedFile(fileObject);   //Unzip and return content file
        FileImporterBuilder builder = getMatchingImporter(fileObject);
        if (fileObject != null && builder != null) {
            FileImporter fi = builder.buildImporter();
            if (fileObject.getPath().startsWith(System.getProperty("java.io.tmpdir"))) {
                try {
                    fileObject.delete();
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
            return fi;
View Full Code Here


        }
        return null;
    }

    public Container importFile(File file) throws FileNotFoundException {
        FileObject fileObject = FileUtil.toFileObject(file);
        if (fileObject != null) {
            fileObject = getArchivedFile(fileObject);   //Unzip and return content file
            FileImporterBuilder builder = getMatchingImporter(fileObject);
            if (fileObject != null && builder != null) {
                Container c = importFile(fileObject.getInputStream(), builder.buildImporter());
                if (fileObject.getPath().startsWith(System.getProperty("java.io.tmpdir"))) {
                    try {
                        fileObject.delete();
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
                return c;
View Full Code Here

        }
        return null;
    }

    public Container importFile(File file, FileImporter importer) throws FileNotFoundException {
        FileObject fileObject = FileUtil.toFileObject(file);
        if (fileObject != null) {
            fileObject = getArchivedFile(fileObject);   //Unzip and return content file
            if (fileObject != null) {
                Container c = importFile(fileObject.getInputStream(), importer);
                if (fileObject.getPath().startsWith(System.getProperty("java.io.tmpdir"))) {
                    try {
                        fileObject.delete();
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
                return c;
View Full Code Here

        }
        return list.toArray(new FileType[0]);
    }

    public boolean isFileSupported(File file) {
        FileObject fileObject = FileUtil.toFileObject(file);
        for (FileImporterBuilder im : fileImporterBuilders) {
            if (im.isMatchingImporter(fileObject)) {
                return true;
            }
        }
        if (fileObject.getExt().equalsIgnoreCase("zip")
                || fileObject.getExt().equalsIgnoreCase("gz")
                || fileObject.getExt().equalsIgnoreCase("bz2")) {
            return true;
        }
        return false;
    }
View Full Code Here

        boolean useTempFile = false;
        File writeFile = null;
        try {
            Progress.start(progressTicket);
            Progress.setDisplayName(progressTicket, NbBundle.getMessage(SaveTask.class, "SaveTask.name"));
            FileObject fileObject = FileUtil.toFileObject(file);
            writeFile = file;
            if (writeFile.exists()) {
                useTempFile = true;
                String tempFileName = writeFile.getName() + "_temp";
                writeFile = new File(writeFile.getParent(), tempFileName);
            }

            //Stream
            int zipLevel = NbPreferences.forModule(SaveTask.class).getInt(ZIP_LEVEL_PREFERENCE, 9);
            FileOutputStream outputStream = new FileOutputStream(writeFile);
            zipOut = new ZipOutputStream(outputStream);
            zipOut.setLevel(zipLevel);

            zipOut.putNextEntry(new ZipEntry("Project"));
            gephiWriter = new GephiWriter();

            //Create Writer and write project
            XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
            outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
            BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(zipOut);
            XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bufferedOutputStream, "UTF-8");
            gephiWriter.writeAll(project, writer);
            writer.close();

            //Close
            zipOut.closeEntry();
            zipOut.finish();
            bufferedOutputStream.close();



            //Clean and copy
            if (useTempFile && !cancel) {
                String name = fileObject.getName();
                String ext = fileObject.getExt();

                //Delete original file
                fileObject.delete();

                //Rename temp file
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                FileLock lock = tempFileObject.lock();
                tempFileObject.rename(lock, name, ext);
                lock.releaseLock();
            } else if (cancel) {
                //Delete temp file
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                tempFileObject.delete();
            }
            Progress.finish(progressTicket);
        } catch (Exception ex) {
            ex.printStackTrace();
            if (zipOut != null) {
View Full Code Here

            for (int i = 0; i < filenameList.size(); i++) {
                File file = new File(filenameList.get(i));
                if (!file.isAbsolute()) {
                    file = new File(env.getCurrentDirectory(), filenameList.get(i));
                }
                FileObject fileObject = FileUtil.toFileObject(file);
                if (!file.exists()) {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                    return;
                }
                if (fileObject.hasExt(GEPHI_EXTENSION)) {
                    ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                    try {
                        pc.openProject(file);
                    } catch (Exception ew) {
                        ew.printStackTrace();
View Full Code Here

                    return false;
                }
                try {
                    List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                    File file = (File) data.get(0);
                    FileObject fileObject = FileUtil.toFileObject(file);
                    if(!file.exists()) {
                        return false;
                    }
                    if (fileObject.hasExt(GEPHI_EXTENSION)) {

                        ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                        try {
                            pc.openProject(file);
                        } catch (Exception ew) {
View Full Code Here

    public void run() {
        try {
            Progress.start(progressTicket);
            Progress.setDisplayName(progressTicket, NbBundle.getMessage(SaveTask.class, "LoadTask.name"));
            FileObject fileObject = FileUtil.toFileObject(file);
            if (FileUtil.isArchiveFile(fileObject)) {
                //Unzip
                fileObject = FileUtil.getArchiveRoot(fileObject).getChildren()[0];
            }

            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
                inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
            }
            inputFactory.setXMLReporter(new XMLReporter() {

                @Override
                public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
                    System.out.println("Error:" + errorType + ", message : " + message);
                }
            });
            XMLStreamReader reader = inputFactory.createXMLStreamReader(fileObject.getInputStream());

            if (!cancel) {
                //Project instance
                Project project = new ProjectImpl();
                project.getLookup().lookup(ProjectInformationImpl.class).setFile(file);
View Full Code Here

        openAction = new AbstractAction("", ImageUtilities.loadImageIcon("org/gephi/desktop/welcome/resources/gephifile20.png", false)) {

            public void actionPerformed(ActionEvent e) {
                JXHyperlink link = (JXHyperlink) e.getSource();
                File file = (File) link.getClientProperty(LINK_PATH);
                FileObject fileObject = FileUtil.toFileObject(file);
                if (fileObject.hasExt(GEPHI_EXTENSION)) {
                    ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                    try {
                        pc.openProject(file);
                    } catch (Exception ex) {
                        ex.printStackTrace();
View Full Code Here

                final String fileName = file.getName();
                JMenuItem menuItem = new JMenuItem(new AbstractAction(fileName) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        FileObject fileObject = FileUtil.toFileObject(file);
                        if (fileObject.hasExt(GEPHI_EXTENSION)) {
                            ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                            try {
                                pc.openProject(file);
                            } catch (Exception ex) {
                                Exceptions.printStackTrace(ex);
View Full Code Here

TOP

Related Classes of org.openide.filesystems.FileObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.