Example usage for org.springframework.core.io Resource getFilename

List of usage examples for org.springframework.core.io Resource getFilename

Introduction

In this page you can find the example usage for org.springframework.core.io Resource getFilename.

Prototype

@Nullable
String getFilename();

Source Link

Document

Determine a filename for this resource, i.e.

Usage

From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptResource.java

public ScriptResource(Resource resource) {
    try {//from w w  w. ja v  a2s  . c om
        this.resource = resource;
        this.name = resource.getFilename();
        this.path = URLEncodeUtils.decodeUtf8(resource.getURL().getPath());
        this.dir = StringUtils.substringBeforeLast(this.path, "/");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.javacrumbs.springws.test.lookup.SimpleResourceLookupTest.java

@Test
public void testSimple() throws IOException {
    SimpleResourceLookup lookup = new SimpleResourceLookup(new ClassPathResource("xml/valid-message2.xml"));
    Resource res = lookup.lookupResource(null, null);
    assertNotNull(res);/*from ww w  . ja va2 s  .  c  om*/
    assertEquals("valid-message2.xml", res.getFilename());
}

From source file:net.javacrumbs.springws.test.lookup.SimpleResourceLookupTest.java

@Test
public void testTemplate() throws IOException {
    SimpleResourceLookup lookup = new SimpleResourceLookup(new ClassPathResource("xml/valid-message2.xml"));
    Resource res = lookup.lookupResource(null, null);
    assertNotNull(res);/*  w  w  w.ja  v  a 2 s  .c om*/
    assertEquals("valid-message2.xml", res.getFilename());
}

From source file:org.apache.crunch.dotfile.DotfileService.java

public String[] findDotfiles(String wildCard) throws IOException {

    List<String> result = new ArrayList<String>();

    for (Resource res : getResources()) {
        if (isEligableFilename(res.getFilename(), wildCard)) {
            result.add(res.getFilename());
        }//  www .  j  ava  2 s  .c  o  m
    }

    return result.toArray(new String[result.size()]);
}

From source file:fr.acxio.tools.agia.io.IdentityResourceAwareItemReaderItemStreamTest.java

@Test
public void testRead() throws Exception {
    IdentityResourceAwareItemReaderItemStream aReader = new IdentityResourceAwareItemReaderItemStream();
    aReader.setName("testReader");

    Resource aResource = mock(Resource.class);
    when(aResource.getFilename()).thenReturn("file1");
    when(aResource.getDescription()).thenReturn("file1");
    when(aResource.exists()).thenReturn(true);

    aReader.setResource(aResource);//from ww w.j  a  v a2s .c  om

    aReader.open(new ExecutionContext());
    assertEquals(aResource, aReader.read());
    assertNull(aReader.read());
    aReader.close();
}

From source file:fr.acxio.tools.agia.io.IdentityResourceAwareItemReaderItemStreamTest.java

@Test
public void testReadNotExists() throws Exception {
    IdentityResourceAwareItemReaderItemStream aReader = new IdentityResourceAwareItemReaderItemStream();
    aReader.setName("testReader");
    aReader.setStrict(false);/*  w  ww. j  a va2s  . c om*/

    Resource aResource = mock(Resource.class);
    when(aResource.getFilename()).thenReturn("file1");
    when(aResource.getDescription()).thenReturn("file1");
    when(aResource.exists()).thenReturn(false);

    aReader.setResource(aResource);

    aReader.open(new ExecutionContext());
    assertNull(aReader.read());
    aReader.close();
}

From source file:fr.acxio.tools.agia.io.IdentityResourceAwareItemReaderItemStreamTest.java

@Test
public void testReadNotExistsStrict() throws Exception {
    exception.expect(ItemStreamException.class);
    IdentityResourceAwareItemReaderItemStream aReader = new IdentityResourceAwareItemReaderItemStream();
    aReader.setName("testReader");
    aReader.setStrict(true);/*  w ww  .j  a  v a 2s  .co  m*/

    Resource aResource = mock(Resource.class);
    when(aResource.getFilename()).thenReturn("file1");
    when(aResource.getDescription()).thenReturn("file1");
    when(aResource.exists()).thenReturn(false);

    aReader.setResource(aResource);

    aReader.open(new ExecutionContext());
    assertNull(aReader.read());
    aReader.close();
}

From source file:fr.acxio.tools.agia.io.ExpressionResourceFactoryTest.java

@Test
public void testEmptyExpression() throws Exception {
    ExpressionResourceFactory aFactory = new ExpressionResourceFactory();
    aFactory.setExpression("");
    Resource aResource = aFactory.getResource();
    assertNotNull(aResource);//  ww w  .  j  a  va2  s.c o  m
    assertEquals("", aResource.getFilename());
}

From source file:de.codecentric.boot.admin.web.servlet.resource.PreferMinifiedFilteringResourceResolver.java

private Resource findMinified(Resource resource) {
    try {/* w ww .j  a v  a  2 s. c  o  m*/
        String basename = StringUtils.stripFilenameExtension(resource.getFilename());
        String extension = StringUtils.getFilenameExtension(resource.getFilename());
        Resource minified = resource.createRelative(basename + extensionPrefix + '.' + extension);
        if (minified.exists()) {
            return minified;
        }
    } catch (IOException ex) {
        logger.trace("No minified resource for [" + resource.getFilename() + "]", ex);
    }
    return null;
}

From source file:fr.acxio.tools.agia.io.ExpressionResourceFactoryTest.java

@Test
public void testConstantExpression() throws Exception {
    ExpressionResourceFactory aFactory = new ExpressionResourceFactory();
    aFactory.setExpression("file.ext");
    Resource aResource = aFactory.getResource();
    assertNotNull(aResource);//from w ww  .j a  v  a 2  s .  c  om
    assertEquals("file.ext", aResource.getFilename());
}