Example usage for org.apache.commons.vfs2 FileType getName

List of usage examples for org.apache.commons.vfs2 FileType getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileType getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of this type.

Usage

From source file:net.sf.jabb.web.action.VfsTreeAction.java

/**
 * It transforms FileObject into JsTreeNodeData.
 * @param file  the file whose information will be encapsulated in the node data structure.
 * @return   The node data structure which presents the file.
 * @throws FileSystemException //from w ww  .  j  a  va  2s .c  o  m
 */
protected JsTreeNodeData populateTreeNodeData(FileObject file, boolean noChild, String relativePath)
        throws FileSystemException {
    JsTreeNodeData node = new JsTreeNodeData();

    String baseName = file.getName().getBaseName();
    FileContent content = file.getContent();
    FileType type = file.getType();

    node.setData(baseName);

    Map<String, Object> attr = new HashMap<String, Object>();
    node.setAttr(attr);
    attr.put("id", relativePath);
    attr.put("rel", type.getName());
    attr.put("fileType", type.getName());
    if (content != null) {
        long fileLastModifiedTime = file.getContent().getLastModifiedTime();
        attr.put("fileLastModifiedTime", fileLastModifiedTime);
        attr.put("fileLastModifiedTimeForDisplay",
                DateFormat.getDateTimeInstance().format(new Date(fileLastModifiedTime)));
        if (file.getType() != FileType.FOLDER) {
            attr.put("fileSize", content.getSize());
            attr.put("fileSizeForDisplay", FileUtils.byteCountToDisplaySize(content.getSize()));
        }
    }

    // these fields should not appear in JSON for leaf nodes
    if (!noChild) {
        node.setState(JsTreeNodeData.STATE_CLOSED);
    }
    return node;
}