Example usage for org.apache.commons.vfs FileType FOLDER

List of usage examples for org.apache.commons.vfs FileType FOLDER

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileType FOLDER.

Prototype

FileType FOLDER

To view the source code for org.apache.commons.vfs FileType FOLDER.

Click Source Link

Document

A folder.

Usage

From source file:org.efaps.webdav4vfs.handler.PutHandler.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {//from   www  . ja  v  a  2s  .  c om
        if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
    } catch (LockException e) {
        response.sendError(SC_LOCKED);
        return;
    } catch (ParseException e) {
        response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        return;
    }
    // it is forbidden to write data on a folder
    if (object.exists() && FileType.FOLDER.equals(object.getType())) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    FileObject parent = object.getParent();
    if (!parent.exists()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    if (!FileType.FOLDER.equals(parent.getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    InputStream is = request.getInputStream();
    OutputStream os = object.getContent().getOutputStream();
    long bytesCopied = IOUtils.copyLarge(is, os);
    String contentLengthHeader = request.getHeader("Content-length");
    LOG.debug(String.format("sent %d/%s bytes", bytesCopied,
            contentLengthHeader == null ? "unknown" : contentLengthHeader));
    os.flush();
    object.close();

    response.setStatus(HttpServletResponse.SC_CREATED);
}

From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileObject.java

@Override()
protected void doCreateFolder() throws Exception {
    this.injectType(FileType.FOLDER);
    this.save();
}

From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileSystem.java

/**
 * @param _rootName             root file name
 * @param _fileSystemOptions    file system options
 *//*from ww w. j av  a  2 s . c o m*/
protected RamFileSystem(final FileName _rootName, final FileSystemOptions _fileSystemOptions) {
    super(_rootName, null, _fileSystemOptions);
    // create root
    final RamFileData rootData = new RamFileData(_rootName);
    rootData.setType(FileType.FOLDER);
    rootData.setLastModified(System.currentTimeMillis());
    this.cache.put(_rootName, rootData);
}

From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileSystem.java

/**
 * Moves the original file <code>_from</code> to the new file
 * <code>_to</code>.//ww w  .j a v  a2 s  .  co  m
 *
 * @param _from     original file
 * @param _to       new file.
 * @throws FileSystemException if an error occurs
 */
void rename(final RamFileObject _from, final RamFileObject _to) throws FileSystemException {
    if (!this.cache.containsKey(_from.getName())) {
        throw new FileSystemException("File does not exist: " + _from.getName());
    }
    // copy data
    _to.getData().setBuffer(_from.getData().getBuffer());
    _to.getData().setLastModified(_from.getData().getLastModified());
    _to.getData().setType(_from.getData().getType());
    _to.getData().getAttributes().clear();
    _to.getData().getAttributes().putAll(_from.getData().getAttributes());
    // fix problem that the file name of the data was cleared
    _to.getData().setName(_to.getName());

    this.save(_to);

    // copy children
    if (_from.getType() == FileType.FOLDER) {
        for (final FileObject child : _from.getChildren()) {
            final FileName newFileName = ((LocalFileName) _to.getName()).createName(
                    _to.getName().getPath() + "/" + child.getName().getBaseName(), child.getName().getType());
            this.rename((RamFileObject) child, new RamFileObject(newFileName, this));
        }
    }

    this.delete(_from);
}

From source file:org.jahia.services.content.impl.external.vfs.VFSDataSource.java

public List<String> getChildren(String path) {
    try {//w  ww. j a  v a  2s .  co m
        if (!path.endsWith("/" + Constants.JCR_CONTENT)) {
            FileObject fileObject = getFile(path);
            if (fileObject.getType() == FileType.FILE) {
                return Arrays.asList(Constants.JCR_CONTENT);
            } else if (fileObject.getType() == FileType.FOLDER) {
                List<String> children = new ArrayList<String>();
                for (FileObject object : fileObject.getChildren()) {
                    children.add(object.getName().getBaseName());
                }
                return children;
            } else {
                logger.warn("Found non file or folder entry, maybe an alias. VFS file type="
                        + fileObject.getType());
            }
        }
    } catch (FileSystemException e) {
        logger.error("Cannot get node children", e);
    }

    return new ArrayList<String>();
}

From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java

public Node getNode(String s) throws PathNotFoundException, RepositoryException {
    try {//  w  ww. j  a va 2s . co  m
        if (fileObject.getType() == FileType.FILE) {
            if ("jcr:content".equals(s)) {
                return new VFSContentNodeImpl(session, fileObject.getContent());
            } else {
                throw new PathNotFoundException(s);
            }
        } else if (fileObject.isReadable() && fileObject.getType() == FileType.FOLDER) {
            FileObject child = fileObject.getChild(s);
            if (child == null) {
                throw new PathNotFoundException(s);
            }
            return new VFSNodeImpl(child, session);
        } else if (fileObject.isReadable()) {
            logger.warn(
                    "Found non file or folder entry, maybe an alias. VFS file type=" + fileObject.getType());
            throw new PathNotFoundException(s);
        } else {
            logger.warn(
                    "Item " + fileObject.getName() + " is not readable. VFS file type=" + fileObject.getType());
            throw new PathNotFoundException(s);
        }
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
}

From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java

public NodeIterator getNodes() throws RepositoryException {
    try {/*from w w  w .  ja v a  2s. co  m*/
        if (fileObject.getType() == FileType.FILE) {
            return new VFSContentNodeIteratorImpl(session, fileObject.getContent());
        } else if (fileObject.getType() == FileType.FOLDER) {
            return new VFSNodeIteratorImpl(session, fileObject.getChildren());
        } else {
            logger.warn(
                    "Found non file or folder entry, maybe an alias. VFS file type=" + fileObject.getType());
            return VFSNodeIteratorImpl.EMPTY;
        }
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
}

From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java

public NodeIterator getNodes(String s) throws RepositoryException {
    try {/*from   w w  w  .j a va2s. co  m*/
        FileObject child = fileObject.isReadable() && fileObject.getType() == FileType.FOLDER
                ? fileObject.getChild(s)
                : null;
        return child != null ? new VFSNodeIteratorImpl(session, child) : VFSNodeIteratorImpl.EMPTY;
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
}

From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java

public boolean hasNode(String s) throws RepositoryException {
    try {/* w  ww.jav a2  s  .  c o m*/
        if (fileObject.getType() == FileType.FILE) {
            if ("jcr:content".equals(s)) {
                return true;
            }
        } else if (fileObject.isReadable() && fileObject.getType() == FileType.FOLDER) {
            FileObject child = fileObject.getChild(s);
            return child != null && child.exists();
        } else if (fileObject.isReadable()) {
            logger.warn(
                    "Found non file or folder entry, maybe an alias. VFS file type=" + fileObject.getType());
            return false;
        } else {
            logger.warn(
                    "Item " + fileObject.getName() + " is not readable. VFS file type=" + fileObject.getType());
            return false;
        }
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
    return false;
}

From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java

public boolean hasNodes() throws RepositoryException {
    try {/*from   w w  w. j  a  v  a2s. co m*/
        if (fileObject.getType() == FileType.FILE) {
            return true;
        } else if (fileObject.getType() == FileType.FOLDER) {
            return fileObject.getChildren().length > 0;
        } else {
            logger.warn(
                    "Found non file or folder entry, maybe an alias. VFS file type=" + fileObject.getType());
            return false;
        }
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
}