Example usage for org.apache.commons.io FilenameUtils FilenameUtils

List of usage examples for org.apache.commons.io FilenameUtils FilenameUtils

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils FilenameUtils.

Prototype

public FilenameUtils() 

Source Link

Document

Instances should NOT be constructed in standard programming.

Usage

From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTaskletTest.java

@Test
public void testSplit() throws Exception {
    SplitPDFTasklet aTasklet = new SplitPDFTasklet();

    PageSplittingPDDocumentFactory aDocumentFactory = new PageSplittingPDDocumentFactory();
    aDocumentFactory.setSplitAtPage(1);/*ww w .  j  ava 2 s.  co  m*/
    aTasklet.setDocumentFactory(aDocumentFactory);

    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:src/test/resources/testFiles/content*.pdf");

    aTasklet.setSourceFactory(aSourceFactory);

    StandardEvaluationContextFactory aContextFactory = new StandardEvaluationContextFactory();

    Map<String, Object> aCommonObjects = new HashMap<String, Object>();
    aCommonObjects.put("fu", new FilenameUtils());

    DateToStringConverter aDTSConverter = new DateToStringConverter();
    aDTSConverter.setDestinationPattern("yyyyMMddhhmmssSSS");

    aCommonObjects.put("dc", aDTSConverter);

    aCommonObjects.put("sr", new SecureRandom());

    aContextFactory.setCommonObjects(aCommonObjects);

    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setEvaluationContextFactory(aContextFactory);
    aDestinationFactory.setExpression(
            "target/ST-N-@{#fu.getBaseName(#in.SOURCE.filename)}-@{#dc.convert(new java.util.Date())}-@{#sr.nextInt(10000)}.pdf");

    aTasklet.setDestinationFactory(aDestinationFactory);
    aTasklet.setForceReplace(false);

    StepContribution aStepContribution = mock(StepContribution.class);

    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));

    Collection<File> aFilesTocheck = FileUtils.listFiles(new File("target"),
            new WildcardFileFilter("ST-N-*.pdf"), null);
    assertEquals(4, aFilesTocheck.size());

    verify(aStepContribution, times(2)).incrementReadCount();
    verify(aStepContribution, times(1)).incrementWriteCount(1); // content1.pdf
    verify(aStepContribution, times(1)).incrementWriteCount(3); // content2.pdf
}

From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTaskletTest.java

@Test
public void testSplitOverwriteException() throws Exception {
    exception.expect(SplitPDFException.class);
    SplitPDFTasklet aTasklet = new SplitPDFTasklet();

    PageSplittingPDDocumentFactory aDocumentFactory = new PageSplittingPDDocumentFactory();
    aDocumentFactory.setSplitAtPage(1);/* w ww  .  jav  a2  s  .  com*/
    aTasklet.setDocumentFactory(aDocumentFactory);

    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:src/test/resources/testFiles/*.pdf");

    aTasklet.setSourceFactory(aSourceFactory);

    StandardEvaluationContextFactory aContextFactory = new StandardEvaluationContextFactory();

    Map<String, Object> aCommonObjects = new HashMap<String, Object>();
    aCommonObjects.put("fu", new FilenameUtils());

    DateToStringConverter aDTSConverter = new DateToStringConverter();
    aDTSConverter.setDestinationPattern("yyyyMMddhhmm");

    aCommonObjects.put("dc", aDTSConverter);

    aContextFactory.setCommonObjects(aCommonObjects);

    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setEvaluationContextFactory(aContextFactory);
    aDestinationFactory.setExpression(
            "target/ST-OE-@{#fu.getBaseName(#in.SOURCE.filename)}-@{#dc.convert(new java.util.Date())}.pdf");

    aTasklet.setDestinationFactory(aDestinationFactory);
    aTasklet.setForceReplace(false);

    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(null, null));
}

From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTaskletTest.java

@Test
public void testSplitOverwrite() throws Exception {
    SplitPDFTasklet aTasklet = new SplitPDFTasklet();

    PageSplittingPDDocumentFactory aDocumentFactory = new PageSplittingPDDocumentFactory();
    aDocumentFactory.setSplitAtPage(1);/* w w w  . jav  a  2s  .c  o m*/
    aTasklet.setDocumentFactory(aDocumentFactory);

    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:src/test/resources/testFiles/*.pdf");

    aTasklet.setSourceFactory(aSourceFactory);

    StandardEvaluationContextFactory aContextFactory = new StandardEvaluationContextFactory();

    Map<String, Object> aCommonObjects = new HashMap<String, Object>();
    aCommonObjects.put("fu", new FilenameUtils());

    aContextFactory.setCommonObjects(aCommonObjects);

    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setEvaluationContextFactory(aContextFactory);
    aDestinationFactory.setExpression("target/ST-O-@{#fu.getBaseName(#in.SOURCE.filename)}-1.pdf");

    aTasklet.setDestinationFactory(aDestinationFactory);
    aTasklet.setForceReplace(true);

    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(null, null));

    Collection<File> aFilesTocheck = FileUtils.listFiles(new File("target"),
            new WildcardFileFilter("ST-O-*.pdf"), null);
    assertEquals(2, aFilesTocheck.size());
}

From source file:org.jenkinsci.plugins.skytap.SkytapUtils.java

/**
 * Prepends the workspace path to a save file name as a default if user has
 * not provided a full path./*from w  w w  . jav  a  2  s . c o m*/
 * 
 * @param build
 * @param savefile
 * 
 * @return fullpath
 * 
 */
public static String convertFileNameToFullPath(AbstractBuild build, String savefile) {

    FilenameUtils fu = new FilenameUtils();

    // if its just a filename with no path, prepend workspace dir

    if (fu.getPath(savefile).equals("")) {
        JenkinsLogger.log(
                "File: " + savefile + " was specified without a path. Defaulting path to Jenkins workspace.");
        String workspacePath = SkytapUtils.expandEnvVars(build, "${WORKSPACE}");

        savefile = workspacePath + "/" + savefile;
        savefile = fu.separatorsToSystem(savefile);
        return savefile;

    } else {
        return fu.separatorsToSystem(savefile);
    }

}