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:se.inera.intyg.intygstjanst.web.service.bean.IntygBootstrapBean.java

private void addIntyg(final Resource metadata, final Resource content) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from   w  w  w .  j  a v a 2 s  . c o m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                Certificate certificate = new CustomObjectMapper().readValue(metadata.getInputStream(),
                        Certificate.class);
                certificate.setDocument(IOUtils.toString(content.getInputStream(), "UTF-8"));
                ModuleApi moduleApi = null;
                OriginalCertificate originalCertificate = new OriginalCertificate();
                try {
                    moduleApi = moduleRegistry.getModuleApi(certificate.getType());
                } catch (ModuleNotFoundException e) {
                    LOG.error("Module {} not found ", certificate.getType());
                }
                if (moduleApi != null && moduleApi.marshall(certificate.getDocument()) != null) {
                    originalCertificate.setReceived(new LocalDateTime());
                    originalCertificate.setDocument(moduleApi.marshall(certificate.getDocument()));
                    certificate.setOriginalCertificate(originalCertificate);
                    originalCertificate.setCertificate(certificate);
                } else {
                    LOG.debug("Got null while populating with original_certificate");
                    originalCertificate.setDocument(certificate.getDocument());
                }
                entityManager.persist(originalCertificate);
                entityManager.persist(certificate);
            } catch (Throwable t) {
                status.setRollbackOnly();
                LOG.error("Loading failed of {}: {}", metadata.getFilename(), t.getMessage());
            }
        }
    });

}

From source file:fr.acxio.tools.agia.tasks.ZipFilesTasklet.java

protected void zipResource(Resource sSourceResource, ZipArchiveOutputStream sZipArchiveOutputStream,
        StepContribution sContribution, ChunkContext sChunkContext) throws IOException, ZipFilesException {
    // TODO : use a queue to reduce the callstack overhead
    if (sSourceResource.exists()) {
        File aSourceFile = sSourceResource.getFile();
        String aSourcePath = aSourceFile.getCanonicalPath();

        if (!aSourcePath.startsWith(sourceBaseDirectoryPath)) {
            throw new ZipFilesException(
                    "Source file " + aSourcePath + " does not match base directory " + sourceBaseDirectoryPath);
        }//from ww w  . j a va  2s . com

        if (sContribution != null) {
            sContribution.incrementReadCount();
        }
        String aZipEntryName = aSourcePath.substring(sourceBaseDirectoryPath.length() + 1);
        sZipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(aZipEntryName));
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Zipping {} to {}", sSourceResource.getFile().getCanonicalPath(), aZipEntryName);
        }
        if (aSourceFile.isFile()) {
            InputStream aInputStream = sSourceResource.getInputStream();
            IOUtils.copy(aInputStream, sZipArchiveOutputStream);
            aInputStream.close();
            sZipArchiveOutputStream.closeArchiveEntry();
        } else {
            sZipArchiveOutputStream.closeArchiveEntry();
            for (File aFile : aSourceFile
                    .listFiles((FileFilter) (recursive ? TrueFileFilter.TRUE : FileFileFilter.FILE))) {
                zipResource(new FileSystemResource(aFile), sZipArchiveOutputStream, sContribution,
                        sChunkContext);
            }
        }
        if (sContribution != null) {
            sContribution.incrementWriteCount(1);
        }
    } else if (LOGGER.isInfoEnabled()) {
        LOGGER.info("{} does not exist", sSourceResource.getFilename());
    }
}

From source file:com.wavemaker.tools.data.DataModelConfiguration.java

public DataModelConfiguration(Resource cfgFile, FileService fileService, String serviceId,
        ExternalDataModelConfig externalConfig, ClassLoaderFactory classLoaderFactory) throws IOException {

    this.name = serviceId;
    this.cfgFile = cfgFile.getFilename();
    this.cfgPath = DesignServiceManager.getRuntimeRelativeDir(serviceId);
    this.fileService = fileService;
    this.externalConfig = externalConfig;
    this.classLoaderFactory = classLoaderFactory;
    this.springConfiguration = new DataServiceSpringConfiguration(fileService, this.cfgPath, this.cfgFile,
            serviceId);/*  w w  w.j a  v  a  2 s.co m*/
    this.projMgr = (ProjectManager) RuntimeAccess.getInstance().getSession()
            .getAttribute(DataServiceConstants.CURRENT_PROJECT_MANAGER);

    this.projectCompiler = (ProjectCompiler) RuntimeAccess.getInstance().getSpringBean("projectCompiler");
    this.fileSystem = (StudioFileSystem) RuntimeAccess.getInstance().getSpringBean("fileSystem");

    if (!serviceId.equals(CommonConstants.SALESFORCE_SERVICE)) {
        setup();
    } else {
        setup_SF();
    }
}

From source file:com.wavemaker.tools.data.DataModelConfiguration.java

public DataModelConfiguration(Resource springConfig, ExternalDataModelConfig externalConfig) {
    this.projectCompiler = (ProjectCompiler) RuntimeAccess.getInstance().getSpringBean("projectCompiler");
    this.fileSystem = (StudioFileSystem) RuntimeAccess.getInstance().getSpringBean("fileSystem");
    this.name = StringUtils.fromFirstOccurrence(springConfig.getFilename(), ".", -1);
    // this.cfgPath = ".";
    this.cfgPath = "";
    this.cfgFile = springConfig.getFilename();
    final Resource baseDir = this.fileSystem.getParent(springConfig);
    this.classLoaderFactory = new DefaultClassLoaderFactory(this.fileSystem.getParent(springConfig));
    this.externalConfig = externalConfig;
    this.fileSystem = this.fileSystem;
    this.projMgr = (ProjectManager) RuntimeAccess.getInstance().getSession()
            .getAttribute(DataServiceConstants.CURRENT_PROJECT_MANAGER);

    this.fileService = new AbstractFileService(this.fileSystem) {

        @Override//w w  w  . j a v  a  2s  .  co  m
        public Resource getFileServiceRoot() {
            return baseDir;
        }
    };

    this.springConfiguration = new DataServiceSpringConfiguration(this.fileService, this.cfgPath, this.cfgFile,
            this.name);

    setup();
}

From source file:com.wavemaker.tools.data.DataModelConfiguration.java

public DataModelConfiguration(Resource springConfig, ExternalDataModelConfig externalConfig,
        ClassLoaderFactory classLoaderFactory) {
    this.projectCompiler = (ProjectCompiler) RuntimeAccess.getInstance().getSpringBean("projectCompiler");
    this.fileSystem = (StudioFileSystem) RuntimeAccess.getInstance().getSpringBean("fileSystem");
    this.name = StringUtils.fromFirstOccurrence(springConfig.getFilename(), ".", -1);
    // this.cfgPath = ".";
    this.cfgPath = "";
    this.cfgFile = springConfig.getFilename();
    final Resource baseDir = this.fileSystem.getParent(springConfig);
    this.classLoaderFactory = classLoaderFactory;
    this.externalConfig = externalConfig;
    this.fileSystem = this.fileSystem;
    this.projMgr = (ProjectManager) RuntimeAccess.getInstance().getSession()
            .getAttribute(DataServiceConstants.CURRENT_PROJECT_MANAGER);

    this.fileService = new AbstractFileService(this.fileSystem) {

        @Override/*from www .j a  v a  2 s . co  m*/
        public Resource getFileServiceRoot() {
            return baseDir;
        }
    };

    this.springConfiguration = new DataServiceSpringConfiguration(this.fileService, this.cfgPath, this.cfgFile,
            this.name);

    setup();
}

From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java

/**
 * Create a PrefabGraphTypeDao from the properties file in sourceResource
 * If reloadable is true, add the type's reload call back to each graph,
 * otherwise don't If sourceResource is not a file-based resource, then
 * reloadable should be false NB: I didn't want to get into checking for
 * what the implementation class of Resource is, because that could break
 * in future with new classes and types that do have a File underneath
 * them. This way, it's up to the caller, who *should* be able to make a
 * sensible choice as to whether the resource is reloadable or not.
 *
 * @param type/*from  w  w w.  java 2 s .  c om*/
 * @param sourceResource
 * @param reloadable
 * @return
 */
private PrefabGraphTypeDao createPrefabGraphType(String type, Resource sourceResource, boolean reloadable) {
    InputStream in = null;
    try {
        in = sourceResource.getInputStream();
        Properties properties = new Properties();
        properties.load(in);
        PrefabGraphTypeDao t = new PrefabGraphTypeDao();
        t.setName(type);

        t.setCommandPrefix(getProperty(properties, "command.prefix"));
        t.setOutputMimeType(getProperty(properties, "output.mime"));

        t.setDefaultReport(properties.getProperty("default.report", "none"));

        String includeDirectoryString = properties.getProperty("include.directory");
        t.setIncludeDirectory(includeDirectoryString);

        if (includeDirectoryString != null) {
            Resource includeDirectoryResource;

            File includeDirectoryFile = new File(includeDirectoryString);
            if (includeDirectoryFile.isAbsolute()) {
                includeDirectoryResource = new FileSystemResource(includeDirectoryString);
            } else {
                includeDirectoryResource = sourceResource.createRelative(includeDirectoryString);
            }

            File includeDirectory = includeDirectoryResource.getFile();

            if (includeDirectory.isDirectory()) {
                t.setIncludeDirectoryResource(includeDirectoryResource);
            } else {
                // Just warn; no need to throw a hissy fit or otherwise fail to load
                LOG.warn("includeDirectory '{}' specified in '{}' is not a directory",
                        includeDirectoryFile.getAbsolutePath(), sourceResource.getFilename());
            }
        }

        // Default to 5 minutes; it's up to users to specify a shorter
        // time if they don't mind OpenNMS spamming on that directory
        int interval;
        try {
            interval = Integer.parseInt(properties.getProperty("include.directory.rescan", "300000"));
        } catch (NumberFormatException e) {
            // Default value if one was specified but it wasn't an integer
            interval = 300000;
            LOG.warn(
                    "The property 'include.directory.rescan' in {} was not able to be parsed as an integer.  Defaulting to {}ms",
                    sourceResource, interval, e);
        }

        t.setIncludeDirectoryRescanInterval(interval);

        List<PrefabGraph> graphs = loadPrefabGraphDefinitions(t, properties);

        for (PrefabGraph graph : graphs) {
            //The graphs list may contain nulls; see loadPrefabGraphDefinitions for reasons
            if (graph != null) {
                FileReloadContainer<PrefabGraph> container;
                if (reloadable) {
                    container = new FileReloadContainer<PrefabGraph>(graph, sourceResource, t.getCallback());
                } else {
                    container = new FileReloadContainer<PrefabGraph>(graph);
                }

                t.addPrefabGraph(container);
            }
        }

        //This *must* come after loading the main graph file, to ensure overrides are correct
        this.scanIncludeDirectory(t);
        return t;

    } catch (IOException e) {
        LOG.error("Failed to load prefab graph configuration of type {} from {}", type, sourceResource, e);
        return null;
    } finally {
        IOUtils.closeQuietly(in);
    }

}

From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java

public void afterPropertiesSet() throws IOException {
    // If no environment override has been specified, used the default environments
    if (environments == null || environments.size() == 0) {
        environments = defaultEnvironments;
    }//from  w w w  .ja  v  a 2  s  .  co  m

    // Prepend the default property locations to the specified property locations (if any)
    Set<Resource> combinedLocations = new LinkedHashSet<Resource>();
    if (!CollectionUtils.isEmpty(overridableProperyLocations)) {
        combinedLocations.addAll(overridableProperyLocations);
    }

    if (!CollectionUtils.isEmpty(propertyLocations)) {
        combinedLocations.addAll(propertyLocations);
    }
    propertyLocations = combinedLocations;

    if (!environments.contains(defaultEnvironment)) {
        throw new AssertionError(
                "Default environment '" + defaultEnvironment + "' not listed in environment list");
    }

    if (keyResolver == null) {
        keyResolver = new RuntimePropertyEnvironmentKeyResolver();
    }

    String environment = determineEnvironment();
    ArrayList<Resource> allLocations = new ArrayList<Resource>();

    /* Process configuration in the following order (later files override earlier files
     * common-shared.properties
     * [environment]-shared.properties
     * common.properties
     * [environment].properties
     * -Dproperty-override-shared specified value, if any
     * -Dproperty-override specified value, if any  */
    Set<Set<Resource>> testLocations = new LinkedHashSet<Set<Resource>>();
    testLocations.add(propertyLocations);
    testLocations.add(defaultPropertyLocations);

    for (Resource resource : createBroadleafResource()) {
        if (resource.exists()) {
            allLocations.add(resource);
        }
    }

    for (Set<Resource> locations : testLocations) {
        for (Resource resource : createSharedCommonResource(locations)) {
            if (resource.exists()) {
                allLocations.add(resource);
            }
        }

        for (Resource resource : createSharedPropertiesResource(environment, locations)) {
            if (resource.exists()) {
                allLocations.add(resource);
            }
        }

        for (Resource resource : createCommonResource(locations)) {
            if (resource.exists()) {
                allLocations.add(resource);
            }
        }

        for (Resource resource : createPropertiesResource(environment, locations)) {
            if (resource.exists()) {
                allLocations.add(resource);
            }
        }
    }

    Resource sharedPropertyOverride = createSharedOverrideResource();
    if (sharedPropertyOverride != null) {
        allLocations.add(sharedPropertyOverride);
    }

    Resource propertyOverride = createOverrideResource();
    if (propertyOverride != null) {
        allLocations.add(propertyOverride);
    }

    Properties props = new Properties();
    for (Resource resource : allLocations) {
        if (resource.exists()) {
            // We will log source-control managed properties with trace and overrides with info
            if (((resource.equals(sharedPropertyOverride) || resource.equals(propertyOverride)))
                    || LOG.isTraceEnabled()) {
                props = new Properties(props);
                props.load(resource.getInputStream());
                for (Entry<Object, Object> entry : props.entrySet()) {
                    //                        if (resource.equals(sharedPropertyOverride) || resource.equals(propertyOverride)) {
                    //                            logger.support("Read " + entry.getKey() + " from " + resource.getFilename());
                    //                        } else {
                    LOG.trace("Read " + entry.getKey() + " from " + resource.getFilename());
                    //                        }
                }
            }
        } else {
            LOG.debug("Unable to locate resource: " + resource.getFilename());
        }
    }

    setLocations(allLocations.toArray(new Resource[] {}));
}

From source file:com.epam.catgenome.manager.FeatureIndexManagerTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testIndexUpdateOnProjectOperations() throws Exception {
    Resource gffResource = context.getResource(CLASSPATH_TEMPLATES_GENES_SORTED);

    FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest();
    request.setReferenceId(referenceId);
    request.setPath(gffResource.getFile().getAbsolutePath());
    request.setName("testGeneFile");

    GeneFile geneFile = gffManager.registerGeneFile(request);
    Assert.assertNotNull(geneFile);//from ww w . java 2 s. c  om
    Assert.assertNotNull(geneFile.getId());

    referenceGenomeManager.updateReferenceGeneFileId(testReference.getId(), geneFile.getId());

    Resource vcfResource = context.getResource(CLASSPATH_TEMPLATES_FELIS_CATUS_VCF);

    request = new FeatureIndexedFileRegistrationRequest();
    request.setReferenceId(referenceId);
    request.setPath(vcfResource.getFile().getAbsolutePath());
    request.setName("testVcf");

    VcfFile vcfFile = vcfManager.registerVcfFile(request);

    Project project = new Project();
    project.setName(TEST_PROJECT_NAME + 1);
    project.setItems(Arrays.asList(new ProjectItem(new BiologicalDataItem(vcfFile.getBioDataItemId())),
            new ProjectItem(new BiologicalDataItem(geneFile.getBioDataItemId())),
            new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId()))));

    projectManager.saveProject(project); // Index is created when vcf file is added

    VcfFilterForm vcfFilterForm = new VcfFilterForm();
    vcfFilterForm.setVcfFileIds(Collections.singletonList(vcfFile.getId()));
    vcfFilterForm.setChromosomeIds(Collections.singletonList(testChromosome.getId()));
    vcfFilterForm
            .setGenes(new VcfFilterForm.FilterSection<>(Collections.singletonList(TEST_GENE_PREFIX), false));
    vcfFilterForm.setVariationTypes(
            new VcfFilterForm.FilterSection<>(Arrays.asList(VariationType.MNP, VariationType.SNV), false));
    IndexSearchResult<VcfIndexEntry> entryList = featureIndexManager.filterVariations(vcfFilterForm,
            project.getId());
    Assert.assertFalse(entryList.getEntries().isEmpty());

    // try to add an vcf item
    request = new FeatureIndexedFileRegistrationRequest();
    request.setReferenceId(referenceId);
    request.setPath(vcfResource.getFile().getAbsolutePath());
    request.setName(vcfResource.getFilename() + "2");
    VcfFile vcfFile2 = vcfManager.registerVcfFile(request);

    project = projectManager.addProjectItem(project.getId(), vcfFile2.getBioDataItemId());

    entryList = featureIndexManager.filterVariations(vcfFilterForm, project.getId());
    Assert.assertFalse(entryList.getEntries().isEmpty());
    Assert.assertTrue(
            entryList.getEntries().stream().allMatch(e -> e.getFeatureFileId().equals(vcfFile.getId())));

    VcfFilterForm vcfFilterForm2 = new VcfFilterForm();
    vcfFilterForm2.setVcfFileIds(Collections.singletonList(vcfFile2.getId()));
    vcfFilterForm.setChromosomeIds(Collections.singletonList(testChromosome.getId()));
    vcfFilterForm2
            .setGenes(new VcfFilterForm.FilterSection<>(Collections.singletonList(TEST_GENE_PREFIX), false));
    vcfFilterForm2.setVariationTypes(
            new VcfFilterForm.FilterSection<>(Arrays.asList(VariationType.MNP, VariationType.SNV), false));
    IndexSearchResult<VcfIndexEntry> entryList2 = featureIndexManager.filterVariations(vcfFilterForm2,
            project.getId());
    Assert.assertFalse(entryList2.getEntries().isEmpty());
    Assert.assertEquals(entryList.getEntries().size(), entryList2.getEntries().size());

    Assert.assertTrue(
            entryList2.getEntries().stream().allMatch(e -> e.getFeatureFileId().equals(vcfFile2.getId())));

    // test no vcfFileIds
    vcfFilterForm2.setVcfFileIds(null);
    entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId());
    Assert.assertFalse(entryList2.getEntries().isEmpty());
    Assert.assertEquals(entryList2.getEntries().size(), entryList.getEntries().size() * 2);

    // test with multiple vcfFileIds
    vcfFilterForm2.setVcfFileIds(Arrays.asList(vcfFile.getId(), vcfFile2.getId()));
    entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId());
    Assert.assertFalse(entryList2.getEntries().isEmpty());
    Assert.assertEquals(entryList2.getEntries().size(), entryList.getEntries().size() * 2);

    // try to remove a vcf item by save - should be not indexed
    project.setItems(project.getItems().stream()
            .filter(i -> !(i.getBioDataItem() instanceof VcfFile)
                    || !((VcfFile) i.getBioDataItem()).getId().equals(vcfFile2.getId()))
            .collect(Collectors.toList()));

    project = projectManager.saveProject(project);

    vcfFilterForm2.setVcfFileIds(Collections.singletonList(vcfFile2.getId()));
    entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId());
    Assert.assertTrue(entryList2.getEntries().isEmpty());

    // try to remove gene file
    project.setItems(project.getItems().stream().filter(i -> !(i.getBioDataItem() instanceof GeneFile))
            .collect(Collectors.toList()));
    project = projectManager.saveProject(project);

    vcfFilterForm.setGenes(null);
    entryList = featureIndexManager.filterVariations(vcfFilterForm, project.getId());
    Assert.assertFalse(entryList.getEntries().isEmpty());

    // add multiple files
    project.getItems().clear();
    projectManager.saveProject(project);
    Project loadedProject = projectManager.loadProject(project.getId());
    Assert.assertTrue(loadedProject.getItems().isEmpty());
    entryList2 = featureIndexManager.filterVariations(new VcfFilterForm(), project.getId());
    Assert.assertTrue(entryList2.getEntries().isEmpty());

    project.setItems(Arrays.asList(new ProjectItem(new BiologicalDataItem(vcfFile.getBioDataItemId())),
            new ProjectItem(new BiologicalDataItem(vcfFile2.getBioDataItemId())),
            new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId()))));
    projectManager.saveProject(project);
    entryList2 = featureIndexManager.filterVariations(new VcfFilterForm(), project.getId());
    Assert.assertTrue(
            entryList2.getEntries().stream().anyMatch(e -> e.getFeatureFileId().equals(vcfFile.getId())));
    Assert.assertTrue(
            entryList2.getEntries().stream().anyMatch(e -> e.getFeatureFileId().equals(vcfFile2.getId())));
}

From source file:org.parancoe.web.util.ReloadableResourceBundleMessageSource.java

/**
 * Refresh the PropertiesHolder for the given bundle filename. The holder can be
 * <code>null</code> if not cached before, or a timed-out cache entry (potentially getting
 * re-validated against the current last-modified timestamp).
 *
 * @param filename the bundle filename (basename + Locale)
 * @param propHolder the current PropertiesHolder for the bundle
 */// w w w . j a v a 2 s. co m
protected ReloadableResourceBundleMessageSource.PropertiesHolder refreshProperties(String filename,
        ReloadableResourceBundleMessageSource.PropertiesHolder propHolder) {
    long refreshTimestamp = (this.cacheMillis < 0) ? -1 : System.currentTimeMillis();

    Resource[] resources = null;
    try {
        if (this.resourceLoader instanceof ResourcePatternResolver) {
            resources = ((ResourcePatternResolver) this.resourceLoader)
                    .getResources(filename + PROPERTIES_SUFFIX);
            if (resources == null || resources.length == 0) {
                resources = ((ResourcePatternResolver) this.resourceLoader).getResources(filename + XML_SUFFIX);
            }
        } else {
            Resource resource = this.resourceLoader.getResource(filename + PROPERTIES_SUFFIX);
            if (!resource.exists()) {
                resource = this.resourceLoader.getResource(filename + XML_SUFFIX);
            }
            resources = new Resource[1];
            resources[0] = resource;
        }
        if (resources != null && resources.length > 0) {
            propHolder = new ReloadableResourceBundleMessageSource.PropertiesHolder();
            for (Resource resource : resources) {
                if (resource.exists()) {
                    long fileTimestamp = -1;
                    if (this.cacheMillis >= 0) {
                        // Last-modified timestamp of file will just be read if caching with timeout.
                        try {
                            fileTimestamp = resource.lastModified();
                            if (propHolder != null && propHolder.getFileTimestamp() == fileTimestamp) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("Re-caching properties for filename [" + filename
                                            + "] - file hasn't been modified");
                                }
                                propHolder.setRefreshTimestamp(refreshTimestamp);
                                return propHolder;
                            }
                        } catch (IOException ex) {
                            // Probably a class path resource: cache it forever.
                            if (logger.isDebugEnabled()) {
                                logger.debug(resource
                                        + " could not be resolved in the file system - assuming that is hasn't changed",
                                        ex);
                            }
                            fileTimestamp = -1;
                        }
                    }
                    try {
                        Properties props = loadProperties(resource, filename);
                        if (propHolder.getProperties() != null) {
                            propHolder.getProperties().putAll(props);
                        } else {
                            propHolder.properties = props;
                        }
                        propHolder.fileTimestamp = fileTimestamp;
                    } catch (IOException ex) {
                        if (logger.isWarnEnabled()) {
                            logger.warn("Could not parse properties file [" + resource.getFilename() + "]", ex);
                        }
                    }
                } else {
                    // Resource does not exist.
                    if (logger.isDebugEnabled()) {
                        logger.debug("No properties file found for [" + resource.getFilename()
                                + "] - neither plain properties nor XML");
                    }
                }
            }
        } else {
            // Resource does not exist.
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "No properties files found for [" + filename + "] - neither plain properties nor XML");
            }
            // Empty holder representing "not found".
            propHolder = new ReloadableResourceBundleMessageSource.PropertiesHolder();
        }
    } catch (IOException iOException) {
        if (logger.isWarnEnabled()) {
            logger.warn("Could not match pattern [" + filename + "]", iOException);
        }
        // Empty holder representing "not valid".
        propHolder = new ReloadableResourceBundleMessageSource.PropertiesHolder();
    }

    propHolder.setRefreshTimestamp(refreshTimestamp);
    this.cachedProperties.put(filename, propHolder);
    return propHolder;
}

From source file:org.activiti.dmn.spring.autodeployment.AbstractAutoDeploymentStrategy.java

/**
 * Determines the name to be used for the provided resource.
 * //from www. j  a va 2  s  . c  o  m
 * @param resource
 *          the resource to get the name for
 * @return the name of the resource
 */
protected String determineResourceName(final Resource resource) {
    String resourceName = null;

    if (resource instanceof ContextResource) {
        resourceName = ((ContextResource) resource).getPathWithinContext();

    } else if (resource instanceof ByteArrayResource) {
        resourceName = resource.getDescription();

    } else {
        try {
            resourceName = resource.getFile().getAbsolutePath();
        } catch (IOException e) {
            resourceName = resource.getFilename();
        }
    }
    return resourceName;
}