Example usage for org.springframework.core.io DefaultResourceLoader getResource

List of usage examples for org.springframework.core.io DefaultResourceLoader getResource

Introduction

In this page you can find the example usage for org.springframework.core.io DefaultResourceLoader getResource.

Prototype

@Override
    public Resource getResource(String location) 

Source Link

Usage

From source file:eu.eidas.node.utils.PluginPropertyLoader.java

private void updatePropLocation() {
    if (locationProp != null && locationNames != null && locationNames.length > 0) {
        List<Resource> loadedLocations = new ArrayList<Resource>();
        DefaultResourceLoader drl = new DefaultResourceLoader();
        String locationPropValue = PropertiesUtil.getProperty(locationProp);
        for (int i = 0; i < locationNames.length && locationPropValue != null; i++) {
            String currentLocation = locationPropValue + locationNames[i];
            loadedLocations.add(drl.getResource("file:" + currentLocation.replace(File.separatorChar, '/')));
        }//from   www  .j av  a2 s.c o m
        locations = new Resource[loadedLocations.size()];
        loadedLocations.toArray(locations);
        if (isLocationReadable(locationPropValue) && locations.length > 0) {
            setLocations(locations);
        }
    }
}

From source file:com.haulmont.cuba.web.testsupport.TestContainer.java

protected void initAppProperties() {
    final Properties properties = new Properties();

    List<String> locations = getAppPropertiesFiles();
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    for (String location : locations) {
        Resource resource = resourceLoader.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                properties.load(stream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }/*from  www.  ja  v a  2s .  c  o  m*/
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }

    StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() {
        @Override
        public String lookup(String key) {
            String subst = properties.getProperty(key);
            return subst != null ? subst : System.getProperty(key);
        }
    });
    for (Object key : properties.keySet()) {
        String value = substitutor.replace(properties.getProperty((String) key));
        appProperties.put((String) key, value);
    }

    File dir;
    dir = new File(appProperties.get("cuba.confDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.logDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.tempDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.dataDir"));
    dir.mkdirs();

    AppContext.setProperty(AppConfig.CLIENT_TYPE_PROP, ClientType.WEB.toString());
}

From source file:jp.pigumer.sso.WebSecurityConfig.java

@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader.getResource(properties.getStoreFile());
    String storePass = properties.getStorePass();
    Map<String, String> passwords = new HashMap<>();
    passwords.put(properties.getDefaultKey(), properties.getPassword());
    String defaultKey = properties.getDefaultKey();
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}

From source file:org.cfr.capsicum.propertyset.CayenneRuntimeContextProvider.java

@SuppressWarnings("unchecked")
@Override/*from ww  w . j av  a2s .c o m*/
public void setup(Map<String, Object> configurationProperties) {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    if (this.cayenneRuntimeContext != null) {
        throw new RuntimeException("CayenneRuntimeContextProvider is already configured.");
    }
    ServerRuntimeFactoryBean factory = new ServerRuntimeFactoryBean();
    DataDomainDefinition dataDomainDefinition = new DataDomainDefinition();
    dataDomainDefinition.setDomainResource(resourceLoader.getResource("classpath:cayenne-propertyset.xml"));
    factory.setDataDomainDefinitions(Lists.newArrayList(dataDomainDefinition));
    dataDomainDefinition.setName(DOMAIN_NAME);

    Iterator<String> itr = configurationProperties.keySet().iterator();
    while (itr.hasNext()) {
        String key = itr.next();

        if (key.startsWith(ICayenneConfigurationProvider.DATASOURCE_PROPERTY_KEY)) {
            dataDomainDefinition.setDataSource((DataSource) configurationProperties.get(key));
            factory.setDataSource((DataSource) configurationProperties.get(key));
        }
        if (key.startsWith(ICayenneConfigurationProvider.ADAPTER_PROPERTY_KEY)) {
            try {
                dataDomainDefinition.setAdapterClass((Class<? extends DbAdapter>) ClassLoaderUtils
                        .loadClass((String) configurationProperties.get(key), this.getClass()));
            } catch (ClassNotFoundException e) {
                throw new CayenneRuntimeException(e);
            }
        }
        if (key.startsWith(ICayenneConfigurationProvider.SCHEMA_UPDATE_STRATEGY_PROPERTY_KEY)) {
            dataDomainDefinition.setSchemaUpdateStrategy(
                    (Class<? extends SchemaUpdateStrategy>) configurationProperties.get(key));
        }

    }
    try {
        factory.afterPropertiesSet();
        this.cayenneRuntimeContext = factory;

    } catch (Exception e) {
        ///CLOVER:OFF
        e.printStackTrace();
        ///CLOVER:ON
    }
}

From source file:com.haulmont.cuba.testsupport.TestContainer.java

protected void initAppProperties() {
    final Properties properties = new Properties();

    List<String> locations = getAppPropertiesFiles();
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    for (String location : locations) {
        Resource resource = resourceLoader.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                properties.load(stream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }//from  ww w.java  2 s. c  o  m
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }

    StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() {
        @Override
        public String lookup(String key) {
            String subst = properties.getProperty(key);
            return subst != null ? subst : System.getProperty(key);
        }
    });
    for (Object key : properties.keySet()) {
        String value = substitutor.replace(properties.getProperty((String) key));
        appProperties.put((String) key, value);
    }

    File dir;
    dir = new File(appProperties.get("cuba.confDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.logDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.tempDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.dataDir"));
    dir.mkdirs();
}

From source file:com.vdenotaris.spring.boot.security.saml.web.config.WebSecurityConfig.java

@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader.getResource("classpath:/saml/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}

From source file:com.naveen.demo.config.Saml2SSOConfig.java

@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader.getResource("classpath:/encryption/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}

From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java

/**
 * Returns the current test bundle manifest. The method tries to read the
 * manifest from the given location; in case the location is
 * <code>null</code> (default), it will search for
 * <code>META-INF/MANIFEST.MF</code> file in jar content (as specified
 * through the patterns) and, if it cannot find the file,
 * <em>automatically</em> create a <code>Manifest</code> object
 * containing default entries.//from  ww w .j  av  a 2  s .c  o m
 * 
 * <p/> Subclasses can override this method to enhance the returned
 * Manifest.
 * 
 * @return Manifest used for this test suite.
 * 
 * @see #createDefaultManifest()
 */
protected Manifest getManifest() {
    // return cached manifest
    if (manifest != null)
        return manifest;

    String manifestLocation = getManifestLocation();
    if (StringUtils.hasText(manifestLocation)) {
        logger.info("Using Manifest from specified location=[" + getManifestLocation() + "]");
        DefaultResourceLoader loader = new DefaultResourceLoader();
        manifest = createManifestFrom(loader.getResource(manifestLocation));
    }

    else {
        // set root path
        jarCreator.setRootPath(getRootPath());
        // add the content pattern
        jarCreator.setContentPattern(getBundleContentPattern());

        // see if the manifest already exists in the classpath
        // to resolve the patterns
        jarEntries = jarCreator.resolveContent();

        for (Iterator iterator = jarEntries.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            if (META_INF_JAR_LOCATION.equals(entry.getKey())) {
                logger.info("Using Manifest from the test bundle content=[/META-INF/MANIFEST.MF]");
                manifest = createManifestFrom((Resource) entry.getValue());
            }
        }
        // fallback to default manifest creation

        if (manifest == null) {
            logger.info("Automatically creating Manifest for the test bundle");
            manifest = createDefaultManifest();
        }
    }

    return manifest;
}

From source file:com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.java

protected void initAppProperties(ServletContext sc) {
    // get properties from web.xml
    String appProperties = sc.getInitParameter(APP_PROPS_PARAM);
    if (appProperties != null) {
        StrTokenizer tokenizer = new StrTokenizer(appProperties);
        for (String str : tokenizer.getTokenArray()) {
            int i = str.indexOf("=");
            if (i < 0)
                continue;
            String name = StringUtils.substring(str, 0, i);
            String value = StringUtils.substring(str, i + 1);
            if (!StringUtils.isBlank(name)) {
                AppContext.setProperty(name, value);
            }/*w  w  w  .j  a  v  a2s . c  o m*/
        }
    }

    // get properties from a set of app.properties files defined in web.xml
    String propsConfigName = getAppPropertiesConfig(sc);
    if (propsConfigName == null)
        throw new IllegalStateException(APP_PROPS_CONFIG_PARAM + " servlet context parameter not defined");

    final Properties properties = new Properties();

    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    StrTokenizer tokenizer = new StrTokenizer(propsConfigName);
    tokenizer.setQuoteChar('"');
    for (String str : tokenizer.getTokenArray()) {
        log.trace("Processing properties location: {}", str);
        str = StrSubstitutor.replaceSystemProperties(str);
        InputStream stream = null;
        try {
            if (ResourceUtils.isUrl(str) || str.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
                Resource resource = resourceLoader.getResource(str);
                if (resource.exists())
                    stream = resource.getInputStream();
            } else {
                stream = sc.getResourceAsStream(str);
            }

            if (stream != null) {
                log.info("Loading app properties from {}", str);
                try (Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
                    properties.load(reader);
                }
            } else {
                log.trace("Resource {} not found, ignore it", str);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }

    for (Object key : properties.keySet()) {
        AppContext.setProperty((String) key, properties.getProperty((String) key).trim());
    }
}

From source file:it.infn.mw.iam.config.saml.SamlConfig.java

@Bean
public KeyManager keyManager() {

    Map<String, String> passwords = new HashMap<>();
    passwords.put(samlProperties.getKeyId(), samlProperties.getKeyPassword());

    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader.getResource(samlProperties.getKeystore());

    return new JKSKeyManager(storeFile, samlProperties.getKeystorePassword(), passwords,
            samlProperties.getKeyId());//w ww  .ja va 2 s.  c  o m
}