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:be.ibridge.kettle.trans.step.getfilenames.GetFileNames.java

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (data.filenr >= data.files.nrOfFiles()) {
        setOutputDone();//  ww w  .ja va2  s. c o  m
        return false;
    }

    Row r = new Row();

    FileObject file = data.files.getFile(data.filenr);

    Value filename = new Value("filename", KettleVFS.getFilename(file));
    filename.setLength(500, -1);
    r.addValue(filename);

    Value short_filename = new Value("short_filename", file.getName().getBaseName());
    short_filename.setLength(500, -1);
    r.addValue(short_filename);

    try {
        Value path = new Value("path", KettleVFS.getFilename(file.getParent()));
        path.setLength(500, -1);
        r.addValue(path);
    } catch (IOException e) {
        throw new KettleException(e);
    }

    data.filenr++;

    putRow(r);

    if ((linesInput > 0) && (linesInput % Const.ROWS_UPDATE) == 0)
        logBasic("linenr " + linesInput);

    return true;
}

From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java

private String unambiguousIdentifier(int index, java.util.List<FileObject> fileList) {

    FileObject candidate = fileList.get(index);
    String[] parts = candidate.getName().getPath().split("/");
    if (fileList.size() == 1) {
        return parts[parts.length - 1];
    }//from   w  w w.jav a 2 s.  com

    int maxParts = 0;

    for (int i = 0; i < fileList.size(); i++) {
        if (i == index)
            continue;
        FileObject other = fileList.get(i);
        String[] otherParts = other.getName().getPath().split("/");
        maxParts = Math.max(maxParts, numMatches(parts, otherParts));
    }

    return joinParts(parts, maxParts + 1);

}

From source file:net.sf.vfsjfilechooser.filechooser.AbstractVFSFileSystemView.java

/**
 * Type description for a file, directory, or folder as it would be displayed in
 * a system file browser. Example from Windows: the "Desktop" folder
 * is desribed as "Desktop"./*from w  w w .  ja  v  a2  s  .  c o m*/
 *
 * Override for platforms with native ShellFolder implementations.
 *
 * @param f a <code>File</code> object
 * @return the file type description as it would be displayed by a native file chooser
 * or null if no native information is available.
 * @see JFileChooser#getTypeDescription
 * @since 1.4
 */
public String getSystemTypeDescription(FileObject f) {
    return VFSUtils.getFriendlyName(f.getName().toString());
}

From source file:com.panet.imeta.trans.step.errorhandling.FileErrorHandlerMissingFiles.java

public void handleNonExistantFile(FileObject file) throws KettleException {
    handleFile(file);/*from  w w w  .  ja va2 s.  c o m*/
    try {
        getWriter(NO_PARTS).write(THIS_FILE_DOES_NOT_EXIST);
        getWriter(NO_PARTS).write(Const.CR);
    } catch (Exception e) {
        throw new KettleException(
                Messages.getString("FileErrorHandlerMissingFiles.Exception.CouldNotCreateNonExistantFile") //$NON-NLS-1$
                        + file.getName().getURI(),
                e);
    }
}

From source file:com.panet.imeta.trans.step.errorhandling.FileErrorHandlerMissingFiles.java

public void handleNonAccessibleFile(FileObject file) throws KettleException {
    handleFile(file);//from   ww w .  ja  va 2 s.  co  m
    try {
        getWriter(NO_PARTS).write(THIS_FILE_WAS_NOT_ACCESSIBLE);
        getWriter(NO_PARTS).write(Const.CR);
    } catch (Exception e) {
        throw new KettleException(
                Messages.getString("FileErrorHandlerMissingFiles.Exception.CouldNotCreateNonAccessibleFile") //$NON-NLS-1$
                        + file.getName().getURI(), e);
    }
}

From source file:net.sf.vfsjfilechooser.filechooser.AbstractVFSFileSystemView.java

/**
 * Name of a file, directory, or folder as it would be displayed in
 * a system file browser. Example from Windows: the "M:\" directory
 * displays as "CD-ROM (M:)"//from  ww w . j a  v a  2 s .c  o m
 *
 * The default implementation gets information from the ShellFolder class.
 *
 * @param f a <code>File</code> object
 * @return the file name as it would be displayed by a native file chooser
 * @see JFileChooser#getName
 * @since 1.4
 */
public String getSystemDisplayName(FileObject f) {
    String name = null;

    if (f != null) {
        name = f.getName().getBaseName();

        if (!name.trim().equals("")) {
            name = VFSUtils.getFriendlyName(f.getName() + "");
        }
    }

    return name;
}

From source file:com.adito.vfs.VFSLockManager.java

/**
 * @return <code>java.util.Collection<VFSFileLock></code> containing all the currently held locks
 *//*from  w  w w.ja  v a2 s  .c  o m*/
public synchronized Collection<VFSFileLock> getCurrentLocks() {
    Collection<VFSFileLock> lockedFiles = new TreeSet<VFSFileLock>();
    for (Map.Entry<String, Collection<Lock>> entry : locksByHandle_.entrySet()) {
        String handle = entry.getKey();
        for (Lock lock : entry.getValue()) {
            try {
                FileObject file = lock.getResource().getFile();
                if (file != null) {
                    FileName name = file.getName();
                    String baseName = name.getBaseName();
                    String friendlyURI = DAVUtilities.stripUserInfo(name.getURI().toString());
                    boolean sessionsActive = areSessionsActive(lock);
                    lockedFiles.add(new VFSFileLock(baseName, friendlyURI, sessionsActive, handle));
                }
            } catch (IOException e) {
                // ignore
            }
        }
    }
    return lockedFiles;
}

From source file:com.rapleaf.ramhdfs.RamFileSystem.java

@Override
public FileStatus[] listStatus(Path f) throws IOException {

    FileObject fo = pathToFileObject(f);

    if (!fo.exists()) {
        throw new FileNotFoundException("File " + f + " does not exist.");
    }//from  w  ww. ja v  a  2 s.  c om
    if (isFile(fo)) {
        return new FileStatus[] { getFileStatus(f) };
    }

    FileObject[] children = pathToFileObject(f).getChildren();
    FileStatus[] results = new FileStatus[children.length];
    int j = 0;
    for (int i = 0; i < children.length; i++) {
        FileObject child = children[i];
        try {
            results[j] = getFileStatus(new Path(child.getName().getPath()));
            j++;
        } catch (FileNotFoundException e) {
            // ignore the files not found since the dir list may have have changed
            // since the names[] list was generated.
        }
    }
    if (j == results.length) {
        return results;
    }
    return Arrays.copyOf(results, j);
}

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

/**
 * Resolves a URI, relative to a base file with the specified FileSystem
 * configuration options.//from  w  w w.  ja  v a 2s  .c o m
 */
@Override
public FileObject resolveFile(FileObject baseFile, String uri, FileSystemOptions opts)
        throws FileSystemException {
    // let the specified provider handle it
    if (!isCombinedLocal || isSchemeSpecified(uri)) {
        return super.resolveFile(baseFile, uri, opts);
    }

    FileObject localFile;
    FileObject gaeFile;

    if (baseFile != null) {
        // if uri starts with "/", determine if it includes the base path;
        // if it doesn't, then remove the leading "/" to create a relative
        // path; this is required to properly resolve "file://"
        uri = checkRelativity(baseFile, uri);

        FileObject fileObject = super.resolveFile(baseFile, uri, opts);
        if (fileObject.exists() && (fileObject.getType().hasContent())) {
            return fileObject; // return existing file
        }
        // fileObject doesn't exist or is a folder, check other file system
        if (fileObject.getName().getScheme().equals("gae")) {
            gaeFile = fileObject;
            FileName baseName = baseFile.getName();
            if (baseName instanceof GaeFileName) {
                String localUri = "file://" + ((GaeFileName) baseName).getRootPath() + baseName.getPath() + "/"
                        + uri;
                localFile = super.resolveFile(null, localUri, opts);
            } else {
                localFile = super.resolveFile(baseFile, "file://" + uri, opts);
            }
            if (localFile.exists() && (localFile.getType().hasContent())) {
                return localFile; // return existing local files
            }
        } else {
            localFile = fileObject;
            gaeFile = super.resolveFile(baseFile, "gae://" + uri, opts);
        }
    } else {
        // neither scheme nor baseFile specified, check local first
        localFile = super.resolveFile(null, uri, opts);
        if (localFile.exists() && (localFile.getType().hasContent())) {
            return localFile; // return existing local files
        }
        // localFile doesn't exist or is a folder, check GAE file system
        gaeFile = super.resolveFile(null, "gae://" + uri, opts);
    }

    ((GaeFileObject) gaeFile).setCombinedLocal(true);

    // when we get here we either have a non-existing file, or a folder;
    // return the GAE file/folder if it exists
    if (gaeFile.exists()) {
        return gaeFile;
    }

    // never return local folders
    if (localFile.exists()) {
        gaeFile.createFolder(); // create GAE "shadow" for existing local folder
        return gaeFile;
    }
    return gaeFile; // neither local nor GAE file/folder exists
}

From source file:com.thinkberg.webdav.PropPatchHandler.java

/**
 * Get a multistatus response for each of the property set/remove requests.
 *
 * @param object              the context object the property requests apply to
 * @param requestedProperties the properties that should be set or removed
 * @param baseUrl             the base url of this server
 * @return an XML document that is the response
 * @throws FileSystemException if there is an error setting or removing a property
 *//*w ww  . j a  v  a  2s .  co m*/
private Document getMultiStatusResponse(FileObject object, List<Element> requestedProperties, URL baseUrl)
        throws FileSystemException {
    Document propDoc = DocumentHelper.createDocument();
    propDoc.setXMLEncoding("UTF-8");

    Element multiStatus = propDoc.addElement(TAG_MULTISTATUS, NAMESPACE_DAV);
    Element responseEl = multiStatus.addElement(TAG_RESPONSE);
    try {
        URL url = new URL(baseUrl, URLEncoder.encode(object.getName().getPath(), "UTF-8"));
        responseEl.addElement(TAG_HREF).addText(url.toExternalForm());
    } catch (Exception e) {
        LOG.error("can't set HREF tag in response", e);
    }
    DavResource resource = DavResourceFactory.getInstance().getDavResource(object);
    resource.setPropertyValues(responseEl, requestedProperties);
    return propDoc;
}