Example usage for org.apache.commons.vfs2 FileSystemManager resolveFile

List of usage examples for org.apache.commons.vfs2 FileSystemManager resolveFile

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSystemManager resolveFile.

Prototype

FileObject resolveFile(URL url) throws FileSystemException;

Source Link

Document

Resolves a URL into a FileObject .

Usage

From source file:org.kalypso.ui.wizards.results.Import2DResultsOperation.java

private void importFiles(final IProgressMonitor monitor, final File outputDir,
        final ICalcUnitResultMeta calcMeta) throws InvocationTargetException {
    final FileSystemManager manager = getFileSystemManager();

    for (final File file : m_files) {
        final String filename = file.getName();
        monitor.subTask(String.format(Messages.getString("Import2DResultsOperation_3"), filename)); //$NON-NLS-1$
        try {/* ww  w  .  j  a va2s.c  o  m*/
            final FileObject file2d = manager.resolveFile(file.toURI().toString());
            importFile(file2d, outputDir, calcMeta, new SubProgressMonitor(monitor, 1));
        } catch (final FileSystemException e) {
            m_stati.add(IStatus.ERROR, Messages.getString("Import2DResultsOperation_4"), e, filename); //$NON-NLS-1$
        }
    }
}

From source file:org.nanoko.coffee.mill.mojos.others.WatchMojo.java

private void setupMonitor(MavenProject project) throws FileSystemException {
    File baseDir = project.getBasedir();
    getLog().info("Set up file monitor on " + baseDir);
    FileSystemManager fsManager = VFS.getManager();
    FileObject dir = fsManager.resolveFile(baseDir.getAbsolutePath());

    DefaultFileMonitor fm = new DefaultFileMonitor(this);
    fm.setRecursive(true);/*from w ww . j ava2 s  .com*/
    fm.addFile(dir);
    fm.start();
}

From source file:org.onehippo.forge.content.pojo.model.ContentProperty.java

/**
 * Creates a {@link BinaryValue} instance from the given stringified value
 * which can be either a <code>data:</code> URL or any other external URL to be read.
 * @param stringifiedValue stringfieid binary value, either a <code>data:</code> URL or any other external URL to be read
 * @return a {@link BinaryValue} instance
 *//*from w  ww . ja v a2s  .c o m*/
private BinaryValue createBinaryValue(String stringifiedValue) {
    BinaryValue binaryValue = null;

    if (StringUtils.startsWith(stringifiedValue, "data:")) {
        binaryValue = BinaryValue.fromDataURI(stringifiedValue);
    } else {
        try {
            FileSystemManager fsManager = VFS.getManager();
            FileObject fileObject = fsManager.resolveFile(stringifiedValue);
            binaryValue = new BinaryValue(fileObject);
        } catch (FileSystemException e) {
            throw new IllegalArgumentException("Unresolvable VFS url.");
        }
    }

    return binaryValue;
}

From source file:org.openmrs.module.omodreloader.OmodReloaderActivator.java

/**
 * @see Activator#startup()/*from  w w  w . j  a v  a2 s.c  o m*/
 */
public void startup() {
    log.info("Starting Omod Reloader Module");

    try {
        FileSystemManager fsManager = VFS.getManager();

        String pathsToScan = System.getProperty("omodreloader.paths");
        if (StringUtils.isBlank(pathsToScan)) {
            return;
        }

        String[] paths = pathsToScan.split(";");

        fileMonitor = new DefaultFileMonitor(new ModuleFileListener());
        fileMonitor.setRecursive(false);
        for (String path : paths) {
            FileObject file = fsManager.resolveFile(path);
            fileMonitor.addFile(file);
        }
        fileMonitor.start();
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipperZIPTest.java

@Test
public void testUnzipEmptyContent() throws IOException, InterruptedException {
    Files.createFile(archivePath);

    FileSystemManager fsManager = VFS.getManager();

    VFSZipper.ZIP.unzip(Files.newInputStream(archivePath), fsManager.resolveFile(outputPath.toUri()));

    assertThat(outputPath.toFile().listFiles()).isNull();
}

From source file:org.pentaho.googledrive.vfs.test.GoogleDriveFileObjectTest.java

@Test
public void testFileObject() throws Exception {
    FileSystemManager manager = mock(FileSystemManager.class);
    GoogleDriveFileObject fileObjectMock = mock(GoogleDriveFileObject.class);
    when(manager.resolveFile(FOLDER)).thenReturn(fileObjectMock);
    when(fileObjectMock.isFolder()).thenReturn(true);
    when(fileObjectMock.exists()).thenReturn(true);
    when(fileObjectMock.delete()).thenReturn(true);
    FileObject fileObject = manager.resolveFile(FOLDER);
    fileObject.createFolder();//from   w  w w  . j  a va  2s .  co  m
    assertTrue(fileObject.isFolder());
    assertTrue(fileObject.exists());
    assertTrue(fileObject.delete());
    assertNull(fileObject.getChildren());
}

From source file:org.pentaho.metaverse.impl.VfsLineageWriterTest.java

/**
 * @throws FileSystemException//from   w  ww.  j a  v  a2 s  .  com
 * @throws java.lang.Exception
 */
@After
public void tearDown() throws FileSystemException {
    FileSystemManager fsManager = VFS.getManager();
    fsManager.resolveFile(BAD_OUTPUT_FOLDER).deleteAll();
    fsManager.resolveFile(GOOD_OUTPUT_FOLDER).deleteAll();
}

From source file:org.pentaho.platform.pdi.vfs.MetadataToMondrianVfsTest.java

@Test
public void testVfs() throws Exception {

    ((DefaultFileSystemManager) VFS.getManager()).addProvider("mtm", new MetadataToMondrianVfs());

    FileSystemManager fsManager = VFS.getManager();
    FileObject fobj = fsManager.resolveFile("mtm:src/test/resources/example_olap.xmi");
    StringBuilder buf = new StringBuilder(1000);
    InputStream in = fobj.getContent().getInputStream();
    int n;// w  w  w .j a  v a 2s.  co m
    while ((n = in.read()) != -1) {
        buf.append((char) n);
    }
    in.close();
    String results = buf.toString();
    Assert.assertTrue(results.indexOf("<Cube name=\"customer2 Table\">") >= 0);
}

From source file:org.pentaho.vfs.test.FileChooserTest.java

public static void main(String args[]) {
    FileSystemManager fsManager = null;
    FileObject maybeRootFile = null;
    try {// ww w.  j av  a2  s. com
        fsManager = VFS.getManager();
        if (fsManager instanceof DefaultFileSystemManager) {
            File f = new File("."); //$NON-NLS-1$
            try {
                ((DefaultFileSystemManager) fsManager).setBaseFile(f.getCanonicalFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //maybeRootFile = fsManager.resolveFile("jar:lib/mail-1.3.2.jar"); //$NON-NLS-1$
        // rootFile = fsManager.resolveFile("file:/home/mdamour/workspace/apache-vfs-browser");
        maybeRootFile = fsManager.resolveFile("file:///c:/");
        // maybeRootFile = fsManager.resolveFile("jar:lib/mail.jar");
        // maybeRootFile = fsManager.resolveFile("ftp://ftpgolden.pentaho.org/");

        // maybeRootFile.getFileSystem().getParentLayer().

        // maybeRootFile.getFileSystem().getFileSystemManager().gets

    } catch (Exception e) {
        e.printStackTrace();
    }
    final FileObject rootFile = maybeRootFile;
    final Shell applicationShell = new Shell(SWT.SHELL_TRIM | SWT.CLOSE | SWT.MIN | SWT.MAX);
    applicationShell.setLayout(new FillLayout());
    applicationShell.setText(Messages.getString("FileChooserTest.application")); //$NON-NLS-1$
    applicationShell.setSize(640, 400);
    Menu bar = new Menu(applicationShell, SWT.BAR);
    applicationShell.setMenuBar(bar);
    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText(Messages.getString("FileChooserTest.file")); //$NON-NLS-1$
    fileItem.setAccelerator(SWT.CTRL + 'F');
    Menu fileSubMenu = new Menu(applicationShell, SWT.DROP_DOWN);
    fileItem.setMenu(fileSubMenu);
    MenuItem fileOpenItem = new MenuItem(fileSubMenu, SWT.CASCADE);
    fileOpenItem.setText(Messages.getString("FileChooserTest.open")); //$NON-NLS-1$
    fileOpenItem.setAccelerator(SWT.CTRL + 'O');
    final String filters[] = new String[] { "*.*", "*.xml;*.XML;", "*.class", "*.map" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    final String filterNames[] = new String[] { Messages.getString("FileChooserTest.allFiles"), //$NON-NLS-1$
            Messages.getString("FileChooserTest.xmlFiles"), Messages.getString("FileChooserTest.javaFiles"), //$NON-NLS-1$//$NON-NLS-2$
            Messages.getString("FileChooserTest.mapFiles") }; //$NON-NLS-1$
    fileOpenItem.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            FileObject initialFile = rootFile;
            // try {
            // // initialFile = rootFile.resolveFile("/home/mdamour");
            // } catch (FileSystemException e) {
            // e.printStackTrace();
            // }
            try {
                VfsFileChooserDialog fileOpenDialog = new VfsFileChooserDialog(applicationShell,
                        VFS.getManager(), rootFile, initialFile);
                fileOpenDialog.addVFSUIPanel(buildHDFSPanel("HDFS", fileOpenDialog));
                fileOpenDialog.addVFSUIPanel(buildHDFSPanel("S3", fileOpenDialog));
                fileOpenDialog.addVFSUIPanel(buildHDFSPanel("file", fileOpenDialog));
                FileObject selectedFile = fileOpenDialog.open(applicationShell, null, filters, filterNames,
                        VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
                if (selectedFile != null) {
                    System.out.println(
                            Messages.getString("FileChooserTest.selectedFileEquals") + selectedFile.getName()); //$NON-NLS-1$
                } else {
                    System.out.println(Messages.getString("FileChooserTest.noFileSelected")); //$NON-NLS-1$
                }
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    MenuItem saveAsOpenItem = new MenuItem(fileSubMenu, SWT.CASCADE);
    saveAsOpenItem.setText(Messages.getString("FileChooserTest.saveAs")); //$NON-NLS-1$
    saveAsOpenItem.setAccelerator(SWT.CTRL + 'A');
    saveAsOpenItem.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            FileObject initialFile = null;
            try {
                initialFile = rootFile.resolveFile("/home/mdamour"); //$NON-NLS-1$
            } catch (FileSystemException e) {
                e.printStackTrace();
            }
            try {
                VfsFileChooserDialog fileOpenDialog = new VfsFileChooserDialog(applicationShell,
                        VFS.getManager(), rootFile, initialFile);
                FileObject selectedFile = fileOpenDialog.open(applicationShell,
                        Messages.getString("FileChooserTest.untitled"), filters, filterNames, //$NON-NLS-1$
                        VfsFileChooserDialog.VFS_DIALOG_SAVEAS);
                if (selectedFile != null) {
                    System.out.println(
                            Messages.getString("FileChooserTest.selectedFileEquals") + selectedFile.getName()); //$NON-NLS-1$
                } else {
                    System.out.println(Messages.getString("FileChooserTest.noFileSelected")); //$NON-NLS-1$
                }
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    applicationShell.open();
    while (!applicationShell.isDisposed()) {
        if (!applicationShell.getDisplay().readAndDispatch())
            applicationShell.getDisplay().sleep();
    }
}

From source file:org.pentaho.vfs.test.VfsBrowserTest.java

public static void main(String args[]) {
    FileSystemManager fsManager = null;
    FileObject rootFile = null;/* ww  w. j a  v  a 2 s  . c  om*/
    try {
        fsManager = VFS.getManager();
        if (fsManager instanceof DefaultFileSystemManager) {
            File f = new File("."); //$NON-NLS-1$
            try {
                ((DefaultFileSystemManager) fsManager).setBaseFile(f.getCanonicalFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // rootFile = fsManager.resolveFile("jar:lib/jdom.jar2");
        // rootFile = fsManager.resolveFile("file:/home/mdamour/workspace/apache-vfs-browser");
        rootFile = fsManager.resolveFile("file:///"); //$NON-NLS-1$
    } catch (Exception e) {
        e.printStackTrace();
    }
    Shell s = new Shell();
    s.setLayout(new FillLayout());
    VfsBrowser browser = new VfsBrowser(s, SWT.MIN | SWT.MAX | SWT.CLOSE | SWT.RESIZE, rootFile, null, false,
            false);
    s.setVisible(true);
    while (!s.isDisposed()) {
        try {
            if (!s.getDisplay().readAndDispatch())
                s.getDisplay().sleep();
        } catch (SWTException e) {
        }
    }
}