List of usage examples for org.springframework.core.io UrlResource UrlResource
public UrlResource(String path) throws MalformedURLException
From source file:org.apache.camel.builder.script.ScriptBuilder.java
/** * Creates a script builder for the named language and script {@link URL} * * @param language the language to use for the script * @param scriptURL the URL used to load the script * @return the builder/*from ww w. j a v a2 s . co m*/ */ public static ScriptBuilder script(String language, URL scriptURL) { return new ScriptBuilder(language, new UrlResource(scriptURL)); }
From source file:org.apache.camel.builder.script.ScriptBuilder.java
/** * Creates a script builder for the groovy script {@link URL} * * @param scriptURL the URL used to load the script * @return the builder//from w w w . j a va 2 s .c o m */ public static ScriptBuilder groovy(URL scriptURL) { return new ScriptBuilder("groovy", new UrlResource(scriptURL)); }
From source file:org.apache.camel.builder.script.ScriptBuilder.java
/** * Creates a script builder for the JavaScript/ECMAScript script {@link URL} * * @param scriptURL the URL used to load the script * @return the builder/* ww w. j a v a 2s . c o m*/ */ public static ScriptBuilder javaScript(URL scriptURL) { return new ScriptBuilder("js", new UrlResource(scriptURL)); }
From source file:org.apache.camel.builder.script.ScriptBuilder.java
/** * Creates a script builder for the PHP script {@link URL} * * @param scriptURL the URL used to load the script * @return the builder//w w w . java 2 s . com */ public static ScriptBuilder php(URL scriptURL) { return new ScriptBuilder("php", new UrlResource(scriptURL)); }
From source file:org.apache.camel.builder.script.ScriptBuilder.java
/** * Creates a script builder for the Python script {@link URL} * * @param scriptURL the URL used to load the script * @return the builder// ww w . j a v a 2s . co m */ public static ScriptBuilder python(URL scriptURL) { return new ScriptBuilder("python", new UrlResource(scriptURL)); }
From source file:org.apache.camel.builder.script.ScriptBuilder.java
/** * Creates a script builder for the Ruby/JRuby script {@link URL} * * @param scriptURL the URL used to load the script * @return the builder/* w ww . jav a 2s .c o m*/ */ public static ScriptBuilder ruby(URL scriptURL) { return new ScriptBuilder("jruby", new UrlResource(scriptURL)); }
From source file:org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.java
protected ApplicationContext getDefaultsContext() { URL config = DefaultModuleDefinitionSet.class.getResource(DEFAULT_CONFIG_XML); URL additional = DefaultModuleDefinitionSet.class.getResource(DEFAULT_CONFIG_XML_ADDITION); Resource[] configs = additional == null ? new Resource[] { new UrlResource(config) } : new Resource[] { new UrlResource(config), new UrlResource(additional) }; ResourceApplicationContext context = new ResourceApplicationContext(configs); context.setApplicationName("/defaults"); context.refresh();//from w w w . j a v a2 s. c o m @SuppressWarnings("unchecked") final List<Resource> resources = (List<Resource>) context.getBean(DEFAULT_CONFIG_RESOURCES); withModule(new WithModule() { @Override public void with(ModuleDefinition def, Stack<ModuleDefinition> parents) { for (Resource defaults : def.getConfigLocations()) { resources.add(defaults); } } }); configProperties = (Properties) context.getBean(DEFAULT_CONFIG_PROPERTIES); for (Resource resource : resources) { load(resource, configProperties); } Properties newProps = new Properties(); newProps.putAll(configProperties); configProperties = newProps; for (Resource resource : (Resource[]) context.getBean(MODULE_PROPERITES)) { load(resource, configProperties); } configProperties.putAll(System.getProperties()); configProperties.putAll(getEnvValues()); String[] profiles = configProperties.getProperty(SERVER_PROFILE, "").trim().split("\\s*,\\s*"); if (profiles.length > 0) { for (String profile : profiles) { Resource resource = context.getResource(String.format(SERVER_PROFILE_FORMAT, profile)); load(resource, configProperties); } } parseExcludes(); parseProfiles(); return context; }
From source file:org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.java
/** * @param url XML file URL./*from ww w. ja v a 2s.c om*/ * @return Context. * @throws IgniteCheckedException In case of error. */ private ApplicationContext initContext(URL url) throws IgniteCheckedException { GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url)); springCtx.refresh(); } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) " + "[springUrl=" + url + ']', e); else throw new IgniteCheckedException("Failed to instantiate Spring XML application context [springUrl=" + url + ", err=" + e.getMessage() + ']', e); } return springCtx; }
From source file:org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.java
/** * Creates Spring application context. Optionally excluded properties can be specified, * it means that if such a property is found in {@link org.apache.ignite.configuration.IgniteConfiguration} * then it is removed before the bean is instantiated. * For example, {@code streamerConfiguration} can be excluded from the configs that Visor uses. * * @param cfgUrl Resource where config file is located. * @param excludedProps Properties to be excluded. * @return Spring application context./*from w w w . j av a2 s . c om*/ * @throws IgniteCheckedException If configuration could not be read. */ public static ApplicationContext applicationContext(URL cfgUrl, final String... excludedProps) throws IgniteCheckedException { try { GenericApplicationContext springCtx = prepareSpringContext(excludedProps); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(cfgUrl)); springCtx.refresh(); return springCtx; } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) " + "[springUrl=" + cfgUrl + ']', e); else throw new IgniteCheckedException("Failed to instantiate Spring XML application context [springUrl=" + cfgUrl + ", err=" + e.getMessage() + ']', e); } }
From source file:org.atricore.idbus.kernel.planning.jbpm.OsgiProcessFragmentRegistryApplicationContext.java
protected Resource[] getConfigResources() { List<Resource> resources = new ArrayList<Resource>(); try {// w w w. jav a2 s.co m PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( Thread.currentThread().getContextClassLoader()); Collections.addAll(resources, resolver.getResources(DEFAULT_JBPM_FRAGMENT_CFG_FILE)); Resource[] exts = resolver.getResources(DEFAULT_JBPM_EXT_FRAGMENT_CFG_FILE); for (Resource r : exts) { InputStream is = r.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = rd.readLine(); while (line != null) { if (!"".equals(line)) { resources.add(resolver.getResource(line)); } line = rd.readLine(); } is.close(); } } catch (IOException ex) { // ignore } if (null == cfgFiles) { cfgFiles = new String[] { DEFAULT_PROCESS_DESCRIPTOR_FILE }; } for (String cfgFile : cfgFiles) { boolean found = false; Resource cpr = new ClassPathResource(cfgFile); if (!cpr.exists()) { try { //see if it's a URL URL url = new URL(cfgFile); cpr = new UrlResource(url); if (cpr.exists()) { resources.add(cpr); found = true; } } catch (MalformedURLException e) { //ignore } if (!found) { //try loading it our way URL url = getResource(cfgFile, this.getClass()); if (url != null) { cpr = new UrlResource(url); if (cpr.exists()) { resources.add(cpr); found = true; } } } } else { resources.add(cpr); found = true; } if (!found) { logger.warn("No Process Descriptor found: " + cfgFile); } } if (null != cfgFileURLs) { for (URL cfgFileURL : cfgFileURLs) { UrlResource ur = new UrlResource(cfgFileURL); if (ur.exists()) { resources.add(ur); } else { logger.warn("No Process Descriptor found: " + cfgFileURL); } } } logger.info("Creating application context with resources: " + resources); if (0 == resources.size()) { return null; } Resource[] res = new Resource[resources.size()]; res = resources.toArray(res); return res; }