Example usage for org.apache.commons.vfs FileObject getName

List of usage examples for org.apache.commons.vfs FileObject getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getName.

Prototype

public FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:net.sf.jvifm.ui.ZipLister.java

public void upOneDir() {
    try {/* w  w w. j a  v  a  2  s  .  co  m*/
        // if the currentFileObject is the root of the archive file, do
        // nothing.
        if (currentFileObject.getName().getPath().equals("/"))
            return;
        FileObject parentFO = currentFileObject.getParent();
        if (parentFO != null) {
            if (table.getItemCount() > 0) {
                TableItem item = table.getItem(currentRow);
                FileObject selectFO = (FileObject) item.getData("fileObject");
                historyManager.setSelectedItem(currentFileObject.getName().getPath(),
                        selectFO.getName().getBaseName());
            }

            currentFileObject = parentFO;
            changeCurrentNode();
            textLocation.setText(currentFileObject.getName().getPath());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.panet.imeta.core.plugins.PluginLoader.java

private void build(FileObject parent, boolean isJar) throws KettleConfigException {
    try {//  w  ww .  ja  v  a 2 s . c om
        FileObject xml = null;

        if (isJar) {
            FileObject exploded = explodeJar(parent);

            // try reading annotations first ...
            ResolverUtil<Plugin> resPlugins = new ResolverUtil<Plugin>();

            // grab all jar files not part of the "lib"
            File fparent = new File(exploded.getURL().getFile());
            File[] files = fparent.listFiles(new JarNameFilter());

            URL[] classpath = new URL[files.length];
            for (int i = 0; i < files.length; i++)
                classpath[i] = files[i].toURI().toURL();

            ClassLoader cl = new PDIClassLoader(classpath, Thread.currentThread().getContextClassLoader());
            resPlugins.setClassLoader(cl);

            for (FileObject couldBeJar : exploded.getChildren()) {
                if (couldBeJar.getName().getExtension().equals(JAR))
                    resPlugins.loadImplementationsInJar(Const.EMPTY_STRING, couldBeJar.getURL(),
                            tests.values().toArray(new ResolverUtil.Test[2]));
            }

            for (Class<? extends Plugin> match : resPlugins.getClasses()) {
                for (Class<? extends Annotation> cannot : tests.keySet()) {
                    Annotation annot = match.getAnnotation(cannot);
                    if (annot != null)
                        fromAnnotation(annot, exploded, match);
                }

            }

            // and we also read from the xml if present
            xml = exploded.getChild(Plugin.PLUGIN_XML_FILE);

            if (xml == null || !xml.exists())
                return;

            parent = exploded;

        } else
            xml = parent.getChild(Plugin.PLUGIN_XML_FILE);

        // then read the xml if it is there
        if (xml != null && xml.isReadable())
            fromXML(xml, parent);

    } catch (Exception e) {
        throw new KettleConfigException(e);
    }

    // throw new KettleConfigException("Unable to read plugin.xml from " +
    // parent);
}

From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java

/**
 * Renames the file. If a folder, recursively rename the children.
 *//*from w ww. ja va  2s. c om*/
@Override
protected void doRename(FileObject newfile) throws IOException {
    if (this.getType().hasChildren()) { // rename the children
        for (FileObject child : this.getChildren()) {
            String newChildPath = child.getName().getPath().replace(this.getName().getPath(),
                    newfile.getName().getPath());
            child.moveTo(resolveFile(newChildPath));
        }
        newfile.createFolder();
    } else {
        if (this.getContent().isOpen()) { // causes re-attach
            throw new IOException(this.getName() + " content is open");
        }
        GaeFileObject newGaeFile = (GaeFileObject) newfile;
        newGaeFile.metadata.setPropertiesFrom(this.metadata);

        // copy contents (blocks) to new file
        Map<Key, Entity> blocks = datastore.get(getBlockKeys(0));
        List<Entity> newBlocks = new ArrayList<Entity>(blocks.size());
        for (Entity block : blocks.values()) {
            Entity newBlock = newGaeFile.getBlock(block.getKey().getId() - 1);
            newBlock.setPropertiesFrom(block);
            newBlocks.add(newBlock);
        }
        newGaeFile.putContent(newBlocks);
    }
}

From source file:com.panet.imeta.trans.steps.propertyoutput.PropertyOutput.java

private void createParentFolder() throws KettleException {
    // Do we need to create parent folder ?
    if (meta.isCreateParentFolder()) {
        // Check for parent folder
        FileObject parentfolder = null;
        try {//from  w ww. j  a  va 2s  .co  m
            // Get parent folder
            parentfolder = KettleVFS.getFileObject(data.filename).getParent();
            if (!parentfolder.exists()) {
                if (log.isDetailed())
                    log.logDetailed(toString(), Messages.getString("PropertyOutput.Log.ParentFolderExists",
                            parentfolder.getName().toString()));
                parentfolder.createFolder();
                if (log.isDetailed())
                    log.logDetailed(toString(), Messages.getString(
                            "PropertyOutput.Log.CanNotCreateParentFolder", parentfolder.getName().toString()));
            }
        } catch (Exception e) {
            // The field is unreachable !
            logError(Messages.getString("PropertyOutput.Log.CanNotCreateParentFolder",
                    parentfolder.getName().toString()));
            throw new KettleException(Messages.getString("PropertyOutput.Log.CanNotCreateParentFolder",
                    parentfolder.getName().toString()));

        } finally {
            if (parentfolder != null) {
                try {
                    parentfolder.close();
                } catch (Exception ex) {
                }
                ;
            }
        }
    }
}

From source file:net.sf.jvifm.ui.ZipLister.java

public void enterPath() {
    FileObject fileObject = (FileObject) table.getItem(currentRow).getData("fileObject");

    try {//from   w w  w  .  j a v a 2s  . com
        if (fileObject.getType().equals(FileType.FOLDER)) {
            historyManager.setSelectedItem(currentFileObject.getName().getPath(),
                    fileObject.getName().getBaseName());
            currentFileObject = currentFileObject.getChild(fileObject.getName().getBaseName());
            changeCurrentNode();
            textLocation.setText(currentFileObject.getName().getPath());
        } else {
            editFile(fileObject);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.panet.imeta.core.plugins.PluginLoader.java

/**
 * This method does the actual plugin configuration and should be called
 * after load()/*from   www.  ja  v  a  2 s.  c  om*/
 * 
 * @return a collection containing the <code>JobPlugin</code> objects
 *         loaded.
 * @throws KettleConfigException
 */
private void doConfig() throws KettleConfigException {
    synchronized (locs) {
        String sjar = "." + JAR;

        for (PluginLocation plugin : locs) {
            // check to see if the resource type is present
            File base = new File(System.getProperty("user.dir"));
            try {
                FileSystemManager mgr = VFS.getManager();
                FileObject fobj = mgr.resolveFile(base, plugin.getLocation());
                if (fobj.isReadable()) {
                    String name = fobj.getName().getURI();
                    int jindex = name.indexOf(sjar);
                    int nlen = name.length();
                    boolean isJar = jindex == nlen - 4 || jindex == nlen - 6;

                    try {

                        if (isJar)
                            build(fobj, true);
                        else {
                            // loop thru folder
                            for (FileObject childFolder : fobj.getChildren()) {
                                boolean isAlsoJar = childFolder.getName().getURI().endsWith(sjar);

                                // ignore anything that is not a folder or a
                                // jar
                                if (!isAlsoJar && childFolder.getType() != FileType.FOLDER) {
                                    continue;
                                }

                                // ignore any subversion or CVS directories
                                if (childFolder.getName().getBaseName().equalsIgnoreCase(".svn")) {
                                    continue;
                                } else if (childFolder.getName().getBaseName().equalsIgnoreCase(".cvs")) {
                                    continue;
                                }
                                try {
                                    build(childFolder, isAlsoJar);
                                } catch (KettleConfigException e) {
                                    log.logError(Plugin.PLUGIN_LOADER, e.getMessage());
                                    continue;
                                }
                            }

                        }

                    } catch (FileSystemException e) {
                        log.logError(Plugin.PLUGIN_LOADER, e.getMessage());
                        continue;
                    } catch (KettleConfigException e) {
                        log.logError(Plugin.PLUGIN_LOADER, e.getMessage());
                        continue;
                    }

                } else {
                    log.logDebug(Plugin.PLUGIN_LOADER, fobj + " does not exist, ignoring this.");
                }
            } catch (Exception e) {
                throw new KettleConfigException(e);
            }

        }
    }
}

From source file:com.vobject.appengine.java.io.File.java

private File[] listChildrenAsFileArray(final FilenameFilter filter, final FileObject dir,
        final boolean recursive) throws FileSystemException {
    if (dir.getType() == FileType.FOLDER) {
        final FileObject[] children = dir.getChildren();
        final List list = new ArrayList();
        for (int i = 0; i < children.length; i++) {
            final FileObject child = children[i];
            final String fileName = child.getName().getBaseName();
            if (filter != null) {
                if (filter.accept(null, fileName)) {
                    list.add(new File(child));
                }/*from w ww.j ava 2 s . c om*/
            } else {
                list.add(new File(child));
            }
            if (child.getType() == FileType.FOLDER) {
                if (recursive) {
                    File[] childs = listChildrenAsFileArray(filter, child, recursive);
                    list.addAll(Arrays.asList(childs));
                }
            }
        }
        return (File[]) list.toArray(new File[0]);
    } else {
        return null;
    }
}

From source file:com.vobject.appengine.java.io.File.java

/**
 * Lists the children of a folder./*from w  ww  .  j  ava 2  s. c o m*/
 */
private String[] listChildrenAsStringArray(final FilenameFilter filter, final FileObject dir,
        final boolean recursive) throws FileSystemException {
    if (dir.getType() == FileType.FOLDER) {
        final FileObject[] children = dir.getChildren();
        final List list = new ArrayList();
        for (int i = 0; i < children.length; i++) {
            final FileObject child = children[i];
            final String fileName = child.getName().getBaseName();
            if (filter != null) {
                if (filter.accept(null, fileName)) {
                    list.add(fileName);
                }
            } else {
                list.add(fileName);
            }
            if (child.getType() == FileType.FOLDER) {
                if (recursive) {
                    String[] childNames = listChildrenAsStringArray(filter, child, recursive);
                    list.addAll(Arrays.asList(childNames));
                }
            }
        }
        return (String[]) list.toArray(new String[0]);
    } else {
        return null;
    }
}

From source file:egovframework.rte.fdl.filehandling.FilehandlingServiceTest.java

@Test
public void testUserAuthentication() throws Exception {
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null, "username", "password");
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    FileSystemManager manager = VFS.getManager();

    FileObject baseDir = manager.resolveFile(System.getProperty("user.dir"));
    FileObject file = manager.resolveFile(baseDir, "testfolder/file1.txt");
    FileObject fo = manager.resolveFile("d:" + file.getName().getPath(), opts);

    fo.createFile();/*from   ww  w. j a  v a  2s  .  co m*/

}

From source file:com.panet.imeta.core.playlist.FilePlayListReplayLineNumberFile.java

private void initialize(FileObject lineNumberFile, String encoding) throws KettleException {
    BufferedReader reader = null;
    try {//from  w  ww.j a  va 2  s . c om
        if (encoding == null)
            reader = new BufferedReader(new InputStreamReader(KettleVFS.getInputStream(lineNumberFile)));
        else
            reader = new BufferedReader(
                    new InputStreamReader(KettleVFS.getInputStream(lineNumberFile), encoding));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.length() > 0)
                lineNumbers.add(Long.valueOf(line));
        }
    } catch (Exception e) {
        throw new KettleException("Could not read line number file " + lineNumberFile.getName().getURI(), e);
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
                LogWriter.getInstance().logBasic("TextFilePlayLineNumber",
                        "Could not close line number file " + lineNumberFile.getName().getURI());
            }
    }
}