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

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

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.alibaba.citrus.service.velocity.impl.VelocityConfigurationImpl.java

private String getTemplateNameOfPreloadedResource(Resource resource) {
    URL url;/*from  w  w  w  . j  a  v a 2s  .  c o  m*/

    try {
        url = resource.getURL();
    } catch (IOException e) {
        url = null;
    }

    String templateNameBase;

    if (url != null) {
        templateNameBase = "globalVMs/" + StringUtils.getFilename(url.getPath());
    } else {
        templateNameBase = "globalVMs/globalVM.vm";
    }

    String templateName = templateNameBase;

    // ??resource
    for (int i = 1; preloadedResources.containsKey(templateName)
            && !resource.equals(preloadedResources.get(templateName)); i++) {
        templateName = templateNameBase + i;
    }

    preloadedResources.put(templateName, resource);

    return templateName;
}

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   ww  w  . j av a2s .  c o 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:org.broadleafcommerce.common.config.RuntimeEnvironmentPropertiesConfigurer.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 .j  a v  a  2s .  c om*/

    // 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 SystemPropertyRuntimeEnvironmentKeyResolver();
    }

    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:org.mitre.mpf.wfm.util.MpfPropertiesConfigurationBuilder.java

private CompositeConfiguration createCompositeConfiguration() {

    if (!customPropFile.exists()) {
        try {// w  ww  .j  a va2  s  . c o m
            PropertiesUtil.createParentDir(customPropFile);
            customPropFile.getFile().createNewFile();
        } catch (IOException e) {
            throw new IllegalStateException("Cannot create " + customPropFile + ".", e);
        }
    }

    CompositeConfiguration compositeConfig = new CompositeConfiguration();

    // add resources in the order they are specified in the application context XML;
    // the first configs that are added to the composite override property values in configs that are added later
    for (Resource resource : propFiles) {
        try {
            if (resource.equals(customPropFile)) {
                mpfCustomPropertiesConfig = createFileBasedConfigurationBuilder(customPropFile)
                        .getConfiguration();
                compositeConfig.addConfiguration(mpfCustomPropertiesConfig);
            } else if (resource.exists()) {
                compositeConfig
                        .addConfiguration(createFileBasedConfigurationBuilder(resource).getConfiguration());
            }
        } catch (ConfigurationException e) {
            throw new IllegalStateException("Cannot create configuration from " + resource + ".", e);
        }
    }

    if (mpfCustomPropertiesConfig == null) {
        throw new IllegalStateException("List of configuration properties files did not contain the "
                + "custom configuration property file: " + propFiles);
    }

    return compositeConfig;
}