List of usage examples for org.springframework.core.io.support ResourcePatternResolver getResource
Resource getResource(String location);
From source file:org.nekorp.workflow.desktop.view.resource.imp.IconProviderImp.java
@Override public JPanel getIcon(String name) { BufferedImage img = cache.get(name); if (img == null) { try {//from w ww . j a va2s . c om ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); Resource r = resourceResolver.getResource("/icon/" + name); img = ImageIO.read(r.getInputStream()); this.cache.put(name, img); } catch (IOException ex) { throw new IllegalArgumentException("el icono no se logro cargar", ex); } } ImagenViewer panel = new ImagenViewer(img); panel.setOpaque(false); return panel; }
From source file:net.opentsdb.contrib.tsquare.support.TsWebApplicationContextInitializer.java
private TsdbConfigPropertySource loadTsdbConfig(final ResourcePatternResolver resolver) throws IOException { Resource configResource = null; for (final String location : OVERRIDE_SEARCH_LOCATIONS) { final String fullLoc = String.format("%s%s", location, CONFIG_FILENAME); log.debug("Searching for TSDB config in {}", fullLoc); final Resource res = resolver.getResource(fullLoc); if (res != null && res.exists()) { configResource = res;/*from w w w .j a va2s. co m*/ log.info("Found TSDB config file using {} ", fullLoc); break; } } if (configResource == null) { return new TsdbConfigPropertySource(PROPERTY_SOURCE_NAME, new Config(true)); } else if (configResource.isReadable()) { return new TsdbConfigPropertySource(PROPERTY_SOURCE_NAME, new Config(configResource.getFile().getAbsolutePath())); } else { throw new IllegalStateException("Unable to locate any TSDB config files!"); } }
From source file:com.hp.security.jauth.core.filter.SystemInit.java
public void initMessageProperties(ResourcePatternResolver resolver) throws IOException { //finding system messages. Resource jauthCoreMessages = resolver.getResource("jauth-core-message.properties"); Properties jauthCoreProp = new Properties(); jauthCoreProp.load(jauthCoreMessages.getInputStream()); Set<Object> jauthCoreKeys = jauthCoreProp.keySet(); for (Object k : jauthCoreKeys) { String key = k.toString(); String value = jauthCoreProp.get(key).toString(); MessageContext.messages.put(key, value); }// ww w .jav a 2 s. c o m log.info("loaded jauth core messages."); try { Resource jauthAdminMessages = resolver.getResource("jauth-admin-message.properties"); Properties jauthAdminProp = new Properties(); jauthAdminProp.load(jauthAdminMessages.getInputStream()); Set<Object> jauthAdminKeys = jauthAdminProp.keySet(); for (Object k : jauthAdminKeys) { String key = k.toString(); String value = jauthAdminProp.get(key).toString(); MessageContext.messages.put(key, value); } log.info("loaded jauth admin messages."); } catch (FileNotFoundException e) { log.info("didn't find any jauth admin messages."); } try { Resource jauthSoapMessages = resolver.getResource("jauth-soap-message.properties"); Properties jauthSoapProp = new Properties(); jauthSoapProp.load(jauthSoapMessages.getInputStream()); Set<Object> jauthSoapKeys = jauthSoapProp.keySet(); for (Object k : jauthSoapKeys) { String key = k.toString(); String value = jauthSoapProp.get(key).toString(); MessageContext.messages.put(key, value); } log.info("loaded jauth soap messages."); } catch (FileNotFoundException e) { log.info("didn't find any jauth soap messages."); } //finding custom messages. try { Resource customMessages = resolver.getResource("message.properties"); Properties customProp = new Properties(); customProp.load(customMessages.getInputStream()); Set<Object> customKeys = customProp.keySet(); for (Object k : customKeys) { String key = k.toString(); String value = customProp.get(key).toString(); MessageContext.messages.put(key, value); } log.info("loaded jauth custom messages."); } catch (FileNotFoundException e) { log.info("didn't find any jauth custom messages."); } //finding jauth properties try { Resource jauth = resolver.getResource("jauth.properties"); Properties jauthProp = new Properties(); jauthProp.load(jauth.getInputStream()); authActive = jauthProp.get(Constants.CONFIG_KEY_ACTIVE) == null ? configService.findByKey(Constants.CONFIG_KEY_ACTIVE).getValue() : jauthProp.get(Constants.CONFIG_KEY_ACTIVE).toString(); authorizationCheck = jauthProp.get(Constants.CONFIG_AUTHORIZATION_CHECK) == null ? configService.findByKey(Constants.CONFIG_AUTHORIZATION_CHECK).getValue() : jauthProp.get(Constants.CONFIG_AUTHORIZATION_CHECK).toString(); arithmeticIndex = jauthProp.get(Constants.CONFIG_KEY_ARITHMETIC) == null ? configService.findByKey(Constants.CONFIG_KEY_ARITHMETIC).getValue() : jauthProp.get(Constants.CONFIG_KEY_ARITHMETIC).toString(); sessionID = jauthProp.get(Constants.CONFIG_KEY_SESSION_ID) == null ? configService.findByKey(Constants.CONFIG_KEY_SESSION_ID).getValue() : jauthProp.get(Constants.CONFIG_KEY_SESSION_ID).toString(); sessionACL = jauthProp.get(Constants.CONFIG_KEY_SESSION_ACL) == null ? configService.findByKey(Constants.CONFIG_KEY_SESSION_ACL).getValue() : jauthProp.get(Constants.CONFIG_KEY_SESSION_ACL).toString(); rules = jauthProp.get(Constants.CONFIG_KEY_RULES) == null ? configService.findByKey(Constants.CONFIG_KEY_RULES).getValue() : jauthProp.get(Constants.CONFIG_KEY_RULES).toString(); accessiblePage = jauthProp.get(Constants.CONFIG_KEY_ACCESSIBLE_PAGE) == null ? configService.findByKey(Constants.CONFIG_KEY_ACCESSIBLE_PAGE).getValue() : jauthProp.get(Constants.CONFIG_KEY_ACCESSIBLE_PAGE).toString(); accessibleHost = jauthProp.get(Constants.CONFIG_KEY_ACCESSIBLE_HOST) == null ? configService.findByKey(Constants.CONFIG_KEY_ACCESSIBLE_HOST).getValue() : jauthProp.get(Constants.CONFIG_KEY_ACCESSIBLE_HOST).toString(); exceptionPage = jauthProp.get(Constants.CONFIG_KEY_EXCEPTION) == null ? configService.findByKey(Constants.CONFIG_KEY_EXCEPTION).getValue() : jauthProp.get(Constants.CONFIG_KEY_EXCEPTION).toString(); loginPage = jauthProp.get(Constants.CONFIG_KEY_LOGIN_PAGE) == null ? configService.findByKey(Constants.CONFIG_KEY_LOGIN_PAGE).getValue() : jauthProp.get(Constants.CONFIG_KEY_LOGIN_PAGE).toString(); soapEnabled = jauthProp.get(Constants.CONFIG_KEY_SOAP_ENABLED) == null ? configService.findByKey(Constants.CONFIG_KEY_SOAP_ENABLED).getValue() : jauthProp.get(Constants.CONFIG_KEY_SOAP_ENABLED).toString(); protectWSDL = jauthProp.get(Constants.CONFIG_KEY_PROTECT_WSDL) == null ? configService.findByKey(Constants.CONFIG_KEY_PROTECT_WSDL).getValue() : jauthProp.get(Constants.CONFIG_KEY_PROTECT_WSDL).toString(); dbLogEnabled = jauthProp.get(Constants.CONFIG_KEY_DB_LOG_ENABLED) == null ? configService.findByKey(Constants.CONFIG_KEY_DB_LOG_ENABLED).getValue() : jauthProp.get(Constants.CONFIG_KEY_DB_LOG_ENABLED).toString(); logPath = jauthProp.get(Constants.CONFIG_KEY_LOG_PATH) == null ? configService.findByKey(Constants.CONFIG_KEY_LOG_PATH).getValue() : jauthProp.get(Constants.CONFIG_KEY_LOG_PATH).toString(); if (logPath.length() > 0) { File logDir = new File(logPath); if (!logDir.exists()) { logDir.mkdirs(); } } log.info("loaded jauth.properties."); } catch (FileNotFoundException e) { log.info("didn't find jauth.properties."); } }
From source file:org.obiba.onyx.core.domain.participant.ParticipantMetadata.java
/** * Loads (or re-loads) configuration information stored in the configuration file. * /* w ww . j a v a2 s . c om*/ * @throws IOException on an I/O error */ public void initConfig() throws IOException { ResourcePatternResolver resolver = (ResourcePatternResolver) this.resourceLoader; Resource[] resources = null; Resource configPath = resolver.getResource(onyxConfigPath); // Load essential participant attributes. if (configPath != null && configPath.exists()) { // Load from a user/admin configured file, if it exists... resources = resolver.getResources(onyxConfigPath + "/" + ESSENTIAL_PARTICIPANT_ATTRIBUTES_FILENAME); } if (!resources[0].exists()) { // ...if not load from within the onyx-core.jar file. resources = resolver.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/" + ESSENTIAL_PARTICIPANT_ATTRIBUTES_FILENAME); } initEssentialAttributes(resources); // Load configured participant attributes. if (configPath != null && configPath.exists()) { resources = resolver.getResources(onyxConfigPath + "/" + PARTICIPANT_ATTRIBUTES_FILENAME); initConfiguredAttributes(resources); } }
From source file:org.obiba.onyx.engine.ActionDefinitionConfiguration.java
/** * Finds and loads action-definition.xml to build the cache of {@code ActionDefinition} instances. * @throws IOException//from w w w. j a va2 s .com */ protected void findDefinitions() throws IOException { ResourcePatternResolver resolver = (ResourcePatternResolver) this.resourceLoader; // Find definitions in onyx jar files (including module jar files) String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/" + ACTION_DEFINITION_FILENAME; Resource[] resources = resolver.getResources(pattern); loadDefinitions(resources); Resource configPath = resolver.getResource(onyxConfigPath); if (configPath != null && configPath.exists()) { // Find definitions in the configuration directory resources = resolver.getResources(onyxConfigPath + "/" + ACTION_DEFINITION_FILENAME); loadDefinitions(resources); // Find definitions in the module configuration directory resources = resolver.getResources(onyxConfigPath + "/*/" + ACTION_DEFINITION_FILENAME); loadDefinitions(resources); } }
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.bootstrap.SchemaBootstrap.java
/** * Replaces the dialect placeholder in the script URL and attempts to find a file for * it. If not found, the dialect hierarchy will be walked until a compatible script is * found. This makes it possible to have scripts that are generic to all dialects. * * @return Returns an input stream onto the script, otherwise null *//*w w w . ja v a2 s . co m*/ private InputStream getScriptInputStream(Class<?> dialectClazz, String scriptUrl) throws Exception { // replace the dialect placeholder String dialectScriptUrl = scriptUrl.replaceAll(PLACEHOLDER_SCRIPT_DIALECT, dialectClazz.getName()); // get a handle on the resource ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader()); Resource resource = rpr.getResource(dialectScriptUrl); if (!resource.exists()) { // it wasn't found. Get the superclass of the dialect and try again Class<?> superClazz = dialectClazz.getSuperclass(); if (Dialect.class.isAssignableFrom(superClazz)) { // we still have a Dialect - try again return getScriptInputStream(superClazz, scriptUrl); } else { // we have exhausted all options return null; } } else { // we have a handle to it return resource.getInputStream(); } }
From source file:org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.java
private void doPostResourceConfiguration(GrailsApplication app, RuntimeSpringConfiguration springConfig) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String resourceName = null;/*from w w w . ja v a 2s.c om*/ try { Resource springResources; if (app.isWarDeployed()) { resourceName = GrailsRuntimeConfigurator.SPRING_RESOURCES_XML; springResources = parent.getResource(resourceName); } else { resourceName = DEVELOPMENT_SPRING_RESOURCES_XML; ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(); springResources = patternResolver.getResource(resourceName); } if (springResources != null && springResources.exists()) { if (LOG.isDebugEnabled()) LOG.debug( "[RuntimeConfiguration] Configuring additional beans from " + springResources.getURL()); DefaultListableBeanFactory xmlBf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xmlBf).loadBeanDefinitions(springResources); xmlBf.setBeanClassLoader(classLoader); String[] beanNames = xmlBf.getBeanDefinitionNames(); if (LOG.isDebugEnabled()) LOG.debug("[RuntimeConfiguration] Found [" + beanNames.length + "] beans to configure"); for (String beanName : beanNames) { BeanDefinition bd = xmlBf.getBeanDefinition(beanName); final String beanClassName = bd.getBeanClassName(); Class<?> beanClass = beanClassName == null ? null : ClassUtils.forName(beanClassName, classLoader); springConfig.addBeanDefinition(beanName, bd); String[] aliases = xmlBf.getAliases(beanName); for (String alias : aliases) { springConfig.addAlias(alias, beanName); } if (beanClass != null) { if (BeanFactoryPostProcessor.class.isAssignableFrom(beanClass)) { ((ConfigurableApplicationContext) springConfig.getUnrefreshedApplicationContext()) .addBeanFactoryPostProcessor( (BeanFactoryPostProcessor) xmlBf.getBean(beanName)); } } } } else if (LOG.isDebugEnabled()) { LOG.debug("[RuntimeConfiguration] " + resourceName + " not found. Skipping configuration."); } } catch (Exception ex) { LOG.error("[RuntimeConfiguration] Unable to perform post initialization config: " + resourceName, ex); } GrailsRuntimeConfigurator.loadSpringGroovyResources(springConfig, app); }
From source file:org.grails.web.servlet.context.support.GrailsRuntimeConfigurator.java
protected void doPostResourceConfiguration(GrailsApplication app, RuntimeSpringConfiguration springConfig) { ClassLoader classLoader = app.getClassLoader(); String resourceName = null;/*from w w w . j av a2 s .c om*/ try { Resource springResources; if (app.isWarDeployed()) { resourceName = GrailsRuntimeConfigurator.SPRING_RESOURCES_XML; springResources = parent.getResource(resourceName); } else { resourceName = DEVELOPMENT_SPRING_RESOURCES_XML; ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(); springResources = patternResolver.getResource(resourceName); } if (springResources != null && springResources.exists()) { if (LOG.isDebugEnabled()) LOG.debug( "[RuntimeConfiguration] Configuring additional beans from " + springResources.getURL()); DefaultListableBeanFactory xmlBf = new OptimizedAutowireCapableBeanFactory(); new XmlBeanDefinitionReader(xmlBf).loadBeanDefinitions(springResources); xmlBf.setBeanClassLoader(classLoader); String[] beanNames = xmlBf.getBeanDefinitionNames(); if (LOG.isDebugEnabled()) LOG.debug("[RuntimeConfiguration] Found [" + beanNames.length + "] beans to configure"); for (String beanName : beanNames) { BeanDefinition bd = xmlBf.getBeanDefinition(beanName); final String beanClassName = bd.getBeanClassName(); Class<?> beanClass = beanClassName == null ? null : ClassUtils.forName(beanClassName, classLoader); springConfig.addBeanDefinition(beanName, bd); String[] aliases = xmlBf.getAliases(beanName); for (String alias : aliases) { springConfig.addAlias(alias, beanName); } if (beanClass != null) { if (BeanFactoryPostProcessor.class.isAssignableFrom(beanClass)) { ((ConfigurableApplicationContext) springConfig.getUnrefreshedApplicationContext()) .addBeanFactoryPostProcessor( (BeanFactoryPostProcessor) xmlBf.getBean(beanName)); } } } } else if (LOG.isDebugEnabled()) { LOG.debug("[RuntimeConfiguration] " + resourceName + " not found. Skipping configuration."); } } catch (Exception ex) { LOG.error("[RuntimeConfiguration] Unable to perform post initialization config: " + resourceName, ex); } GrailsRuntimeConfigurator.loadSpringGroovyResources(springConfig, app); }