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

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

Introduction

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

Prototype

FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:org.pentaho.metaverse.util.VfsDateRangeFilterTest.java

@Test
public void testAccept_startDateNull_endDateSet() throws Exception {
    filter = new VfsDateRangeFilter(format, null, end);
    FileSelectInfo fsi = mock(FileSelectInfo.class);
    FileObject fo = mock(FileObject.class);
    FileName fn = mock(FileName.class);
    when(fn.getBaseName()).thenReturn(end);
    when(fo.getType()).thenReturn(FileType.FOLDER);
    when(fo.getName()).thenReturn(fn);
    when(fsi.getFile()).thenReturn(fo);//from ww  w .  j a v  a2 s .c  o  m
    when(fsi.getDepth()).thenReturn(1);
    assertTrue("End date is not inclusive", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn("20000101");
    assertTrue("Before end date was not accepted", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn("21000101");
    assertFalse("After end date was accepted", filter.includeFile(fsi));
}

From source file:org.pentaho.metaverse.util.VfsDateRangeFilterTest.java

@Test
public void testAccept_invalidDateStringFolder() throws Exception {
    filter = new VfsDateRangeFilter(format, start, end);
    filter = new VfsDateRangeFilter(format, null, end);
    FileSelectInfo fsi = mock(FileSelectInfo.class);
    FileObject fo = mock(FileObject.class);
    FileName fn = mock(FileName.class);
    when(fn.getBaseName()).thenReturn("not a date");
    when(fo.getType()).thenReturn(FileType.FOLDER);
    when(fo.getName()).thenReturn(fn);
    when(fsi.getFile()).thenReturn(fo);//from  w  w  w  .  ja  v a 2  s  .  c  o m
    when(fsi.getDepth()).thenReturn(1);
    assertFalse("Invalid date was accepted", filter.includeFile(fsi));
}

From source file:org.pentaho.platform.repository.solution.filebased.FileObjectTestHelper.java

public static FileObject mockFile(final String contents, final boolean exists) throws FileSystemException {
    FileObject fileObject = mock(FileObject.class);
    when(fileObject.exists()).thenReturn(exists);
    FileContent fileContent = mock(FileContent.class);
    when(fileObject.getContent()).thenReturn(fileContent);
    when(fileContent.getInputStream()).thenReturn(IOUtils.toInputStream(contents));
    final FileObject parent = mock(FileObject.class);
    when(fileObject.getParent()).thenReturn(parent);
    final FileName fileName = mock(FileName.class);
    when(parent.getName()).thenReturn(fileName);
    when(fileName.getURI()).thenReturn("mondrian:/catalog");
    return fileObject;
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java

public void setSelectedView(final FileObject selectedView) {
    this.selectedView = selectedView;
    if (selectedView != null) {
        logger.debug("Setting selected view to " + selectedView);
        try {//w  w  w  . ja  v  a  2s . co m
            if (selectedView.getType() == FileType.FILE) {
                logger.debug("Setting filename in selected view to " + selectedView.getName().getBaseName());
                this.fileNameTextField
                        .setText(URLDecoder.decode(selectedView.getName().getBaseName(), "UTF-8"));
            }
        } catch (Exception e) {
            // can be ignored ..
            logger.debug("Unable to determine file type. This is not fatal.", e);
        }
        final ComboBoxModel comboBoxModel = createLocationModel(selectedView);
        this.locationCombo.setModel(comboBoxModel);
        this.table.setSelectedPath((FileObject) comboBoxModel.getSelectedItem());
    } else {
        this.fileNameTextField.setText(null);
        this.table.setSelectedPath(null);
        this.locationCombo.setModel(new DefaultComboBoxModel());
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java

protected String getSelectedFile() throws FileSystemException, UnsupportedEncodingException {
    if (StringUtils.isEmpty(fileNameTextField.getText())) {
        return null;
    }/*from  ww  w  .  j  a v a  2s  . co m*/

    if (selectedView.getType() == FileType.FILE) {
        selectedView = selectedView.getParent();
    }

    final FileObject targetFile = selectedView.resolveFile(fileNameTextField.getText().replaceAll("\\%", "%25")
            .replaceAll("\\!", "%21").replaceAll(":", "%3A"));
    return targetFile.getName().getPathDecoded();
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryPublishDialog.java

protected boolean validateInputs(final boolean onConfirm) {
    if (super.validateInputs(onConfirm) == false) {
        return false;
    }//from  w ww . j  av  a 2 s  .com

    if (onConfirm == false) {
        return true;
    }

    final String reportName = getFileNameTextField().getText();
    if (StringUtils.isEmpty(reportName) == false && reportName.endsWith(REPORT_BUNDLE_EXTENSION) == false) {
        final String safeReportName = reportName + REPORT_BUNDLE_EXTENSION;
        getFileNameTextField().setText(safeReportName);
    }

    try {
        final FileObject selectedView = getSelectedView();
        final String validateName = getSelectedFile();
        if (validateName == null || selectedView == null) {
            return false;
        }

        String filename = getFileNameTextField().getText();
        if (!PublishUtil.validateName(filename)) {
            JOptionPane.showMessageDialog(RepositoryPublishDialog.this,
                    Messages.getInstance().formatMessage("PublishToServerAction.IllegalName", filename,
                            PublishUtil.getReservedCharsDisplay()),
                    Messages.getInstance().getString("PublishToServerAction.Error.Title"),
                    JOptionPane.ERROR_MESSAGE);
            return false;
        }

        final FileObject targetFile = selectedView
                .resolveFile(URLEncoder.encodeUTF8(getFileNameTextField().getText()).replaceAll(":", "%3A")
                        .replaceAll("\\+", "%2B").replaceAll("\\!", "%21"));
        final FileObject fileObject = selectedView.getFileSystem().resolveFile(targetFile.getName());
        if (fileObject.getType() == FileType.IMAGINARY) {
            return true;
        }

        final int result = JOptionPane.showConfirmDialog(this,
                Messages.getInstance().formatMessage("PublishToServerAction.FileExistsOverride", validateName),
                Messages.getInstance().getString("PublishToServerAction.Information.Title"),
                JOptionPane.YES_NO_OPTION);
        return result == JOptionPane.YES_OPTION;
    } catch (FileSystemException fse) {
        UncaughtExceptionsModel.getInstance().addException(fse);
        return false;
    } catch (UnsupportedEncodingException uee) {
        UncaughtExceptionsModel.getInstance().addException(uee);
        return false;
    }
}

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

public int getRowCount() {
    if (selectedPath == null) {
        return 0;
    }/*from   w ww .  ja v a 2s.  c o m*/

    try {
        if (selectedPath.getType() != FileType.FOLDER) {
            return 0;
        }

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

            count += 1;
        }
        return count;
    } catch (FileSystemException fse) {
        UncaughtExceptionsModel.getInstance().addException(fse);
        return 0;
    }
}

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

public FileObject getElementForRow(final int row) {
    if (selectedPath == null) {
        return null;
    }/*from  w  w w. j  av a  2s .co m*/

    try {
        if (selectedPath.getType() != FileType.FOLDER) {
            return null;
        }

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

            if (count == row) {
                return child;
            }
            count += 1;
        }
        return null;
    } catch (FileSystemException fse) {
        UncaughtExceptionsModel.getInstance().addException(fse);
        return null;
    }
}

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

public Object getValueAt(final int row, final int column) {
    final FileObject node1 = getElementForRow(row);

    try {/*from  ww  w  . j  a  v a 2 s .c om*/
        switch (column) {
        case 0:
            return node1.getContent().getAttribute("localized-name");
        case 1:
            return URLDecoder.decode(node1.getName().getBaseName().replaceAll("\\+", "%2B"), "UTF-8");
        case 2:
            final long lastModifiedTime = node1.getContent().getLastModifiedTime();
            if (lastModifiedTime == -1) {
                return null;
            }
            return new Date(lastModifiedTime);
        case 3:
            return node1.getContent().getAttribute("description");
        default:
            throw new IndexOutOfBoundsException();
        }
    } catch (FileSystemException fse) {
        // ignre the exception, assume the file is not valid
        UncaughtExceptionsModel.getInstance().addException(fse);
        return null;
    } catch (UnsupportedEncodingException e) {
        UncaughtExceptionsModel.getInstance().addException(e);
        return null;
    }
}

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   w  w  w.  j  av  a2 s . co  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;
    }
}