Example usage for org.apache.commons.vfs2 FileName getBaseName

List of usage examples for org.apache.commons.vfs2 FileName getBaseName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileName getBaseName.

Prototype

String getBaseName();

Source Link

Document

Returns the base name of this file.

Usage

From source file:pl.otros.logview.api.io.UtilsTest.java

@Test
private void testGetObjectShortName(String scheme, String url, String baseName, String output) {
    // given//from   w w  w . j a  v  a2  s.  co  m
    FileObject fileObjectMock = mock(FileObject.class);
    FileName fileNameMock = mock(FileName.class);

    when(fileObjectMock.getName()).thenReturn(fileNameMock);
    when(fileNameMock.getScheme()).thenReturn(scheme);
    when(fileNameMock.getURI()).thenReturn(url);
    when(fileNameMock.getBaseName()).thenReturn(baseName);

    // when
    String fileObjectShortName = Utils.getFileObjectShortName(fileObjectMock);

    // then
    AssertJUnit.assertEquals(output, fileObjectShortName);
}

From source file:pl.otros.logview.io.UtilsTest.java

@Test(enabled = false)
private void testGetObjectShortName(String scheme, String url, String baseName, String output) {
    // given/*  w w w .j a  v a  2 s  .  c om*/
    FileObject fileObjectMock = mock(FileObject.class);
    FileName fileNameMock = mock(FileName.class);

    when(fileObjectMock.getName()).thenReturn(fileNameMock);
    when(fileNameMock.getScheme()).thenReturn(scheme);
    when(fileNameMock.getURI()).thenReturn(url);
    when(fileNameMock.getBaseName()).thenReturn(baseName);

    // when
    String fileObjectShortName = Utils.getFileObjectShortName(fileObjectMock);

    // then
    AssertJUnit.assertEquals(output, fileObjectShortName);
}

From source file:pl.otros.vfs.browser.table.FileNameWithTypeTableCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

    JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
            column);//from www . j ava 2 s .c  o  m
    FileNameWithType fileNameWithType = (FileNameWithType) value;
    FileName fileName = fileNameWithType.getFileName();
    label.setText(fileName.getBaseName());
    label.setToolTipText(fileName.getFriendlyURI());

    FileType fileType = fileNameWithType.getFileType();
    Icon icon = null;
    Icons icons = Icons.getInstance();
    if (fileNameWithType.getFileName().getBaseName().equals(ParentFileObject.PARENT_NAME)) {
        icon = icons.getArrowTurn90();
    } else if (FileType.FOLDER.equals(fileType)) {
        icon = icons.getFolderOpen();
    } else if (VFSUtils.isArchive(fileName)) {
        if ("jar".equalsIgnoreCase(fileName.getExtension())) {
            icon = icons.getJarIcon();
        } else {
            icon = icons.getFolderZipper();
        }
    } else if (FileType.FILE.equals(fileType)) {
        icon = icons.getFile();
    } else if (FileType.IMAGINARY.equals(fileType)) {
        icon = icons.getShortCut();
    }
    label.setIcon(icon);
    return label;
}

From source file:pl.otros.vfs.browser.table.VfsTableModelHiddenFileRowFilterTest.java

@Test(dataProvider = "candidateFiles")
public void testCheckIfInclude(String path, boolean hiddenAttribute, boolean showHidden, boolean expected)
        throws Exception {
    //given//from   w ww  . ja  v a 2  s .  c  o m
    VfsTableModelHiddenFileRowFilter rowFilter = new VfsTableModelHiddenFileRowFilter(showHidden);
    FileObject fileObject = mock(FileObject.class);
    FileName fileName = mock(FileName.class);
    when(fileObject.getName()).thenReturn(fileName);
    when(fileName.getBaseName()).thenReturn(path);
    when(fileObject.isHidden()).thenReturn(hiddenAttribute);

    //when
    boolean result = rowFilter.checkIfInclude(fileObject);

    //then
    Assert.assertEquals(result, expected,
            String.format("Result for file \"%s\" with hidden attribute %s and showHidden checked %s should "
                    + "be %s, was %s", path, hiddenAttribute, showHidden, result, expected));

}

From source file:pt.webdetails.cpk.elements.impl.kettleoutputs.ResultFilesKettleOutput.java

@Override
public void processResult(KettleResult result) {
    logger.debug("Process Result Files");

    List<FileObject> files = new ArrayList<FileObject>();
    for (ResultFile resultFile : result.getFiles()) {
        files.add(resultFile.getFile());
    }/*from  ww w .j a  v a 2  s .  co m*/

    if (files.isEmpty()) {
        logger.warn("Processing result files but no files found");
        this.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
        return;
    }

    String defaultAttachmentName = this.getConfiguration().getAttachmentName();
    try {
        if (files.size() == 1 && files.get(0).getType() == FileType.FILE) {
            // Singe file
            FileObject file = files.get(0);
            InputStream fileInputStream = KettleVFS.getInputStream(file);
            FileName fileName = file.getName();
            String defaultMimeType = this.getConfiguration().getMimeType();
            String mimeType = defaultMimeType != null ? defaultMimeType
                    : MimeTypes.getMimeType(fileName.getBaseName());
            String attachmentName = defaultAttachmentName != null ? defaultAttachmentName
                    : fileName.getBaseName();

            CpkUtils.send(this.getResponse(), fileInputStream, mimeType, attachmentName,
                    this.getConfiguration().getSendResultAsAttachment());

        } else {
            // More than one file, or folder
            // Build a zip / tar and ship it over!
            ZipUtil zip = new ZipUtil();
            zip.buildZipFromFileObjectList(files);

            String attachmentName = defaultAttachmentName != null ? defaultAttachmentName
                    : zip.getZipNameToDownload();
            CpkUtils.send(this.getResponse(), zip.getZipInputStream(), MimeTypes.ZIP, attachmentName, true);
        }
    } catch (FileSystemException ex) {
        logger.error("Failed sending files from kettle result.", ex);
    }
}