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

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

Introduction

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

Prototype

FileType FOLDER

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

Click Source Link

Document

A folder.

Usage

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTableModelTest.java

@Test
public void testGetRowCount() {
    RepositoryTableModel repoTableModel = new RepositoryTableModel();
    assertNotNull(repoTableModel);// ww w.  j  a va 2  s. co m
    assertEquals(0, repoTableModel.getRowCount());

    repoTableModel.setSelectedPath(fileObject);
    assertEquals(0, repoTableModel.getRowCount());

    try {
        doReturn(FileType.FOLDER).when(fileObject).getType();
        FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 };
        doReturn(childFileName1).when(childFile1).getName();
        doReturn(childFileName2).when(childFile2).getName();
        doReturn(childFileName3).when(childFile3).getName();
        doReturn("file1.txt").when(childFileName1).getBaseName();
        doReturn("file2.txt").when(childFileName2).getBaseName();
        doReturn("file3.txt").when(childFileName3).getBaseName();
        doReturn(childFiles).when(fileObject).getChildren();
        assertEquals(3, repoTableModel.getRowCount());
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTableModelTest.java

@Test
public void testGetElementForRow() {
    RepositoryTableModel repoTableModel = new RepositoryTableModel();
    assertNotNull(repoTableModel);/* www  . j  ava2 s .  c om*/
    repoTableModel.setSelectedPath(fileObject);

    try {
        doReturn(FileType.FOLDER).when(fileObject).getType();
        FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 };
        doReturn(childFileName1).when(childFile1).getName();
        doReturn(childFileName2).when(childFile2).getName();
        doReturn(childFileName3).when(childFile3).getName();
        doReturn("file1.txt").when(childFileName1).getBaseName();
        doReturn("file2.txt").when(childFileName2).getBaseName();
        doReturn("file3.txt").when(childFileName3).getBaseName();
        doReturn(childFiles).when(fileObject).getChildren();
        assertEquals(childFile2, repoTableModel.getElementForRow(1));
    } catch (FileSystemException e) {
        e.printStackTrace();
    }

}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTableModelTest.java

@Test
public void testGetValueAt() {
    final String localizedName1 = "fileName1";
    final String localizedName2 = "fileName2";
    final String localizedName3 = "fileName3";
    final String description1 = "description1";
    final String description2 = "description2";
    final String description3 = "description3";
    final long modifiedTime = System.currentTimeMillis();

    RepositoryTableModel repoTableModel = new RepositoryTableModel();
    assertNotNull(repoTableModel);//from  w  w  w.  ja v a  2s  .c o  m
    repoTableModel.setSelectedPath(fileObject);

    try {
        doReturn(FileType.FOLDER).when(fileObject).getType();
        FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 };
        doReturn(childFileName1).when(childFile1).getName();
        doReturn(childFileName2).when(childFile2).getName();
        doReturn(childFileName3).when(childFile3).getName();
        doReturn("file1.txt").when(childFileName1).getBaseName();
        doReturn("file2.txt").when(childFileName2).getBaseName();
        doReturn("file3.txt").when(childFileName3).getBaseName();
        doReturn(childFileContent1).when(childFile1).getContent();
        doReturn(childFileContent2).when(childFile2).getContent();
        doReturn(childFileContent3).when(childFile3).getContent();
        doReturn(localizedName1).when(childFileContent1).getAttribute("localized-name");
        doReturn(localizedName2).when(childFileContent2).getAttribute("localized-name");
        doReturn(localizedName3).when(childFileContent3).getAttribute("localized-name");
        doReturn(description1).when(childFileContent1).getAttribute("description");
        doReturn(description2).when(childFileContent2).getAttribute("description");
        doReturn(description3).when(childFileContent3).getAttribute("description");
        doReturn(modifiedTime).when(childFileContent1).getLastModifiedTime();
        doReturn(modifiedTime).when(childFileContent2).getLastModifiedTime();
        doReturn(modifiedTime).when(childFileContent3).getLastModifiedTime();
        doReturn(childFiles).when(fileObject).getChildren();
        assertEquals(localizedName1, repoTableModel.getValueAt(0, 0));
        assertEquals("file1.txt", repoTableModel.getValueAt(0, 1));
        assertEquals(new Date(modifiedTime), repoTableModel.getValueAt(0, 2));
        assertEquals(description1, repoTableModel.getValueAt(0, 3));
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

/**
 * Returns the child of <code>parent</code> at index <code>index</code> in the parent's child array.
 * <code>parent</code> must be a node previously obtained from this data source. This should not return
 * <code>null</code> if <code>index</code> is a valid index for <code>parent</code> (that is <code>index >= 0 && index
 * < getChildCount(parent</code>)).
 *
 * @param parent/*from   ww  w .  j a  v a2  s . c o  m*/
 *          a node in the tree, obtained from this data source
 * @return the child of <code>parent</code> at index <code>index</code>
 */
public Object getChild(Object parent, final int index) {
    if (parent instanceof RepositoryTreeRoot) {
        final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
        parent = root1.getRoot();
        if (parent == null) {
            return null;
        }
    }

    try {
        final FileObject parElement = (FileObject) parent;
        final FileObject[] children = parElement.getChildren();
        int count = 0;
        for (int i = 0; i < children.length; i++) {
            final FileObject child = children[i];
            if (isShowFoldersOnly() && child.getType() != FileType.FOLDER) {
                continue;
            }
            if (isShowHiddenFiles() == false && child.isHidden()) {
                continue;
            }
            if (child.getType() != FileType.FOLDER
                    && PublishUtil.acceptFilter(filters, child.getName().getBaseName()) == false) {
                continue;
            }

            if (count == index) {
                return child;
            }

            count += 1;
        }
        return children[index];
    } catch (FileSystemException fse) {
        logger.debug("Failed", fse);
        return null;
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

/**
 * Returns the number of children of <code>parent</code>. Returns 0 if the node is a leaf or if it has no children.
 * <code>parent</code> must be a node previously obtained from this data source.
 *
 * @param parent//from w  w  w  .  ja  v a2  s  .c om
 *          a node in the tree, obtained from this data source
 * @return the number of children of the node <code>parent</code>
 */
public int getChildCount(Object parent) {
    if (parent instanceof RepositoryTreeRoot) {
        final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
        parent = root1.getRoot();
        if (parent == null) {
            return 0;
        }
    }
    try {
        final FileObject parElement = (FileObject) parent;
        if (parElement.getType() != FileType.FOLDER) {
            return 0;
        }

        final FileObject[] children = parElement.getChildren();
        int count = 0;
        for (int i = 0; i < children.length; i++) {
            final FileObject child = children[i];
            if (isShowFoldersOnly() && child.getType() != FileType.FOLDER) {
                continue;
            }
            if (isShowHiddenFiles() == false && child.isHidden()) {
                continue;
            }
            if (child.getType() != FileType.FOLDER
                    && PublishUtil.acceptFilter(filters, child.getName().getBaseName()) == false) {
                continue;
            }

            count += 1;
        }
        return count;
    } catch (FileSystemException fse) {
        logger.debug("Failed", fse);
        return 0;
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

/**
 * Returns <code>true</code> if <code>node</code> is a leaf. It is possible for this method to return
 * <code>false</code> even if <code>node</code> has no children. A directory in a filesystem, for example, may contain
 * no files; the node representing the directory is not a leaf, but it also has no children.
 *
 * @param node/*from w ww.  ja  va  2  s.co  m*/
 *          a node in the tree, obtained from this data source
 * @return true if <code>node</code> is a leaf
 */
public boolean isLeaf(final Object node) {
    if (node instanceof RepositoryTreeRoot) {
        return false;
    }

    try {
        final FileObject parElement = (FileObject) node;
        return (parElement.getType() != FileType.FOLDER);
    } catch (FileSystemException fse) {
        logger.debug("Failed", fse);
        return false;
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

/**
 * Returns the index of child in parent. If either <code>parent</code> or <code>child</code> is <code>null</code>,
 * returns -1. If either <code>parent</code> or <code>child</code> don't belong to this tree model, returns -1.
 *
 * @param parent//from   w  ww .j a  v a2 s.  c  o  m
 *          a note in the tree, obtained from this data source
 * @param childNode
 *          the node we are interested in
 * @return the index of the child in the parent, or -1 if either <code>child</code> or <code>parent</code> are
 *         <code>null</code> or don't belong to this tree model
 */
public int getIndexOfChild(Object parent, final Object childNode) {
    if (parent instanceof RepositoryTreeRoot) {
        final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
        parent = root1.getRoot();
        if (parent == null) {
            return -1;
        }
    }

    try {
        final FileObject parChild = (FileObject) childNode;
        final FileObject parElement = (FileObject) parent;
        final FileObject[] childs = parElement.getChildren();
        int count = 0;
        for (int i = 0; i < childs.length; i++) {
            final FileObject child = childs[i];
            if (isShowFoldersOnly() && child.getType() != FileType.FOLDER) {
                continue;
            }
            if (isShowHiddenFiles() == false && child.isHidden()) {
                continue;
            }
            if (child.getType() != FileType.FOLDER
                    && PublishUtil.acceptFilter(filters, child.getName().getBaseName()) == false) {
                continue;
            }

            if (child.getName().equals(parChild.getName())) {
                return count;
            }

            count += 1;
        }

        return -1;
    } catch (FileSystemException fse) {
        logger.debug("Failed", fse);
        return -1;
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

public static FileObject findNodeByName(final FileObject node, final String name) throws FileSystemException {
    if (node.getType() != FileType.FOLDER) {
        return null;
    }/*  w  ww .  j a v  a 2  s  .co  m*/
    final FileObject child = node.getChild(name);
    if (child == null) {
        return null;
    }
    return child;
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModelTest.java

@Test
public void testGetChild() {
    RepositoryTreeModel treeModel = new RepositoryTreeModel();
    assertNotNull(treeModel);// w w w.j a va  2 s .  c  om
    assertNull(treeModel.getFileSystemRoot());
    FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 };
    try {
        doReturn(childFiles).when(repositoryRoot).getChildren();
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
    treeModel.setFileSystemRoot(repositoryRoot);
    Object value = treeModel.getChild(repositoryRoot, 1);
    assertEquals(childFile2, value);

    treeModel.setShowFoldersOnly(true);
    try {
        doReturn(FileType.FILE).when(childFile1).getType();
        doReturn(FileType.FILE).when(childFile2).getType();
        doReturn(FileType.FILE).when(childFile3).getType();
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
    value = treeModel.getChild(repositoryRoot, 0);
    assertEquals(childFile1, value);

    treeModel.setShowHiddenFiles(false);
    try {
        doReturn(FileType.FOLDER).when(childFile1).getType();
        doReturn(FileType.FOLDER).when(childFile2).getType();
        doReturn(FileType.FOLDER).when(childFile3).getType();
        doReturn(true).when(childFile1).isHidden();
        doReturn(true).when(childFile2).isHidden();
        doReturn(true).when(childFile3).isHidden();
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
    value = treeModel.getChild(repositoryRoot, 2);
    assertEquals(childFile3, value);

}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModelTest.java

@Test
public void testGetChildCount() {
    RepositoryTreeModel treeModel = new RepositoryTreeModel();
    assertNotNull(treeModel);//from   w  ww  . ja v  a2 s  . c o  m
    treeModel.setFileSystemRoot(repositoryRoot);
    assertEquals(0, treeModel.getChildCount(repositoryRoot));

    FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 };
    try {
        doReturn(childFiles).when(repositoryRoot).getChildren();
        doReturn(FileType.FOLDER).when(repositoryRoot).getType();
        doReturn(FileType.FOLDER).when(childFile1).getType();
        doReturn(FileType.FOLDER).when(childFile2).getType();
        doReturn(FileType.FOLDER).when(childFile3).getType();
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
    assertEquals(3, treeModel.getChildCount(repositoryRoot));
}