Example usage for org.apache.commons.vfs FileContent getContentInfo

List of usage examples for org.apache.commons.vfs FileContent getContentInfo

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileContent getContentInfo.

Prototype

public FileContentInfo getContentInfo() throws FileSystemException;

Source Link

Document

get the content info.

Usage

From source file:com.thinkberg.moxo.dav.GetHandler.java

void setHeader(HttpServletResponse response, FileContent content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(content.getLastModifiedTime()));
    response.setHeader("Content-Type", content.getContentInfo().getContentType());
}

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

void setHeader(HttpServletResponse response, FileContent content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(content.getLastModifiedTime()));
    response.setHeader("Content-Type", content.getContentInfo().getContentType());
    response.setHeader("ETag", Util.getETag(content.getFile()));
}

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

void setHeader(final HttpServletResponse response, final FileContent _content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(_content.getLastModifiedTime()));
    response.setHeader("Content-Type", _content.getContentInfo().getContentType());
    response.setHeader("ETag", Util.getETag(_content.getFile()));
}

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

private ExternalData getFileContent(final FileContent content) throws FileSystemException {
    Map<String, String[]> properties = new HashMap<String, String[]>();

    String s1 = content.getContentInfo().getContentType();
    if (s1 == null) {
        s1 = JCRContentUtils.getMimeType(content.getFile().getName().getBaseName());
    }//from w w  w .j  ava  2s  .  c  o m
    if (s1 == null) {
        s1 = "application/octet-stream";
    }
    properties.put(Constants.JCR_MIMETYPE, new String[] { s1 });

    Map<String, Binary[]> binaryProperties = new HashMap<String, Binary[]>();
    binaryProperties.put(Constants.JCR_DATA, new Binary[] { new VFSBinaryImpl(content) });

    String path = content.getFile().getName().getPath().substring(rootPath.length());

    ExternalData externalData = new ExternalData(path + "/" + Constants.JCR_CONTENT,
            path + "/" + Constants.JCR_CONTENT, Constants.NT_RESOURCE, properties);
    externalData.setBinaryProperties(binaryProperties);
    return externalData;
}

From source file:org.jboss.dashboard.ui.formatters.FileNavigationFileListFormatter.java

protected void renderFiles(List sortedChildren) throws FileSystemException {
    if (!sortedChildren.isEmpty()) {
        renderFragment("outputStart");
        for (int i = 0; i < sortedChildren.size(); i++) {
            FileObject fileObject = (FileObject) sortedChildren.get(i);
            FileContent content = fileObject.getContent();
            setAttribute("fileObject", fileObject);
            setAttribute("name", fileObject.getName().getBaseName());
            setAttribute("fileSize", content.getSize());
            String path = fileObject.getName().getPath();
            setAttribute("path", path);
            setAttribute("current", path.equals(getFileNavigationHandler().getCurrentFilePath()));
            String contentType = content.getContentInfo().getContentType();
            String extension = fileObject.getName().getExtension();
            if (contentType == null) {
                contentType = extension;
            }//  w w w . j  a v a  2s .c  om
            setAttribute("contentType", contentType);
            setAttribute("imageURL",
                    getFileNavigationHandler().getFilesystemManager().getThumbnailPath(extension));
            renderFragment("output");
        }
        renderFragment("outputEnd");
    }

}

From source file:org.sonatype.gshell.commands.text.CatCommand.java

public Object execute(final CommandContext context) throws Exception {
    assert context != null;
    IO io = context.getIo();/*from www.  java  2  s  . c om*/

    //
    // TODO: Support multi-path cat, and the special '-' token (which is the default if no paths are given)
    //

    FileObject file = resolveFile(context, path);

    new FileObjectAssert(file).exists();
    ensureFileHasContent(file);

    org.apache.commons.vfs.FileContent content = file.getContent();
    FileContentInfo info = content.getContentInfo();
    log.debug("Content type: {}", info.getContentType());
    log.debug("Content encoding: {}", info.getContentEncoding());

    //
    // TODO: Only cat files which we think are text, or warn if its not, allow flag to force
    //

    log.debug("Displaying file: {}", file.getName());

    BufferedReader reader = new BufferedReader(new InputStreamReader(content.getInputStream()));
    try {
        cat(reader, io);
    } finally {
        Closer.close(reader);
    }

    FileObjects.close(file);

    return Result.SUCCESS;
}

From source file:org.sonatype.gshell.commands.vfs.FileInfoCommand.java

public Object execute(final CommandContext context) throws Exception {
    assert context != null;
    IO io = context.getIo();//from   ww w . j  a va  2s . c  om

    FileObject file = resolveFile(context, path);

    io.println("URL: {}", file.getURL());
    io.println("Name: {}", file.getName());
    io.println("BaseName: {}", file.getName().getBaseName());
    io.println("Extension: {}", file.getName().getExtension());
    io.println("Path: {}", file.getName().getPath());
    io.println("Scheme: {}", file.getName().getScheme());
    io.println("URI: {}", file.getName().getURI());
    io.println("Root URI: {}", file.getName().getRootURI());
    io.println("Parent: {}", file.getName().getParent());
    io.println("Type: {}", file.getType());
    io.println("Exists: {}", file.exists());
    io.println("Readable: {}", file.isReadable());
    io.println("Writeable: {}", file.isWriteable());
    io.println("Root path: {}", file.getFileSystem().getRoot().getName().getPath());

    if (file.exists()) {
        FileContent content = file.getContent();
        FileContentInfo contentInfo = content.getContentInfo();
        io.println("Content type: {}", contentInfo.getContentType());
        io.println("Content encoding: {}", contentInfo.getContentEncoding());

        try {
            // noinspection unchecked
            Map<String, Object> attrs = content.getAttributes();
            if (attrs != null && !attrs.isEmpty()) {
                io.println("Attributes:");
                for (Map.Entry<String, Object> entry : attrs.entrySet()) {
                    io.println("    {}='{}'", entry.getKey(), entry.getValue());
                }
            }
        } catch (FileSystemException e) {
            io.println("File attributes are NOT supported");
        }

        try {
            Certificate[] certs = content.getCertificates();
            if (certs != null && certs.length != 0) {
                io.println("Certificate:");
                for (Certificate cert : certs) {
                    io.println("    {}", cert);
                }
            }
        } catch (FileSystemException e) {
            io.println("File certificates are NOT supported");
        }

        if (file.getType().equals(FileType.FILE)) {
            io.println("Size: {} bytes", content.getSize());
        } else if (file.getType().hasChildren() && file.isReadable()) {
            FileObject[] children = file.getChildren();
            io.println("Directory with {} files", children.length);

            for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
                io.println("#{}:{}", iterChildren, children[iterChildren].getName());
                if (iterChildren > 5) {
                    break;
                }
            }
        }

        io.println("Last modified: {}",
                DateFormat.getInstance().format(new Date(content.getLastModifiedTime())));
    } else {
        io.println("The file does not exist");
    }

    FileObjects.close(file);

    return Result.SUCCESS;
}