List of usage examples for org.springframework.core.io ResourceEditor getValue
public Object getValue()
From source file:org.jspringbot.spring.KeywordUtils.java
/** * Retrieves the given keyword's description. * * @param keyword keyword name/* ww w . j ava 2 s . co m*/ * @param context Spring application context * @param beanMap keyword name to bean name mapping * @return the documentation string of the given keyword, or empty string if unavailable. */ public static String getDescription(String keyword, ApplicationContext context, Map<String, String> beanMap) { KeywordInfo keywordInfo = getKeywordInfo(keyword, context, beanMap); if (keywordInfo == null) { return ""; } String desc = keywordInfo.description(); if (desc.startsWith("classpath:")) { try { ResourceEditor editor = new ResourceEditor(); editor.setAsText(desc); Resource r = (Resource) editor.getValue(); return IOUtils.toString(r.getInputStream()); } catch (Exception ignored) { } } return desc; }
From source file:org.jspringbot.keyword.expression.ELUtils.java
public static String resource(String resourceAsText) throws Exception { ResourceEditor editor = new ResourceEditor(); editor.setAsText(resourceAsText);//from www.j av a 2 s . c o m Resource resource = (Resource) editor.getValue(); String resourceString = IOUtils.toString(resource.getInputStream()); return replaceVars(resourceString); }
From source file:org.jspringbot.keyword.expression.ELUtils.java
private static Properties getInProperties(String location) throws IOException { if (inCache.containsKey(location)) { return inCache.get(location); }//from w ww .j a v a2s .c om ResourceEditor editor = new ResourceEditor(); editor.setAsText(location); Resource resource = (Resource) editor.getValue(); File inFile = resource.getFile(); Properties properties = new Properties(); properties.load(new FileReader(inFile)); inCache.put(location, properties); return properties; }
From source file:com.brienwheeler.lib.spring.beans.PropertyPlaceholderConfigurer.java
/** * Programatically process a single property file location, using System * properties in preference to included definitions for placeholder * resolution, and setting any resolved properties as System properties, if * no property by that name already exists. * //from w w w .java 2 s .c o m * @param locationName String-encoded resource location for the properties file to process * @param placeholderPrefix the placeholder prefix String * @param placeholderSuffix the placeholder suffix String */ public static void processLocation(String locationName, String placeholderPrefix, String placeholderSuffix) { ResourceEditor resourceEditor = new ResourceEditor(); resourceEditor.setAsText(locationName); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocation((Resource) resourceEditor.getValue()); if (placeholderPrefix != null) configurer.setPlaceholderPrefix(placeholderPrefix); if (placeholderSuffix != null) configurer.setPlaceholderSuffix(placeholderSuffix); configurer.quiet = true; GenericApplicationContext context = new GenericApplicationContext(); context.getBeanFactory().registerSingleton("propertyPlaceholderConfigurer", configurer); context.refresh(); context.close(); }
From source file:com.asual.summer.core.resource.PropertyResource.java
private Resource locationStringToResource(String location, ResourceEditor editor) { editor.setAsText(location);/* ww w .j a v a 2s . co m*/ return (Resource) editor.getValue(); }
From source file:org.springmodules.cache.config.AbstractCacheManagerAndProviderFacadeParser.java
/** * Parses the given XML element to obtain the value of the property * <code>configLocation</code>. This property specifies the location of the * configuration file to use to configure the cache manager. * /*from w ww . j a va 2s.co m*/ * @param element * the XML element to parse * @return the value of the property <code>configLocation</code> */ private PropertyValue parseConfigLocationProperty(Element element) { Resource resource = null; String configLocation = element.getAttribute("configLocation"); if (StringUtils.hasText(configLocation)) { ResourceEditor resourceEditor = new ResourceEditor(); resourceEditor.setAsText(configLocation); resource = (Resource) resourceEditor.getValue(); } return new PropertyValue("configLocation", resource); }
From source file:com.joshlong.esb.springintegration.modules.nativefs.config.NativeFileSystemMonitoringEndpointFactoryBean.java
@Override protected NativeFileSystemMonitoringEndpoint createInstance() throws Exception { File f = new File(this.directory); if (this.isAutoCreateDirectory()) { if (!f.exists() && !f.mkdirs()) { throw new RuntimeException("couldn't create directory '" + this.directory + "'."); }//from w w w . java 2 s .com } ResourceEditor editor = new ResourceEditor(this.resourceLoader); editor.setAsText(this.directory); this.directoryResource = (Resource) editor.getValue(); NativeFileSystemMonitoringEndpoint nativeFileSystemMonitoringEndpoint = new NativeFileSystemMonitoringEndpoint(); nativeFileSystemMonitoringEndpoint.setDirectory(this.directoryResource); nativeFileSystemMonitoringEndpoint.setRequestChannel(this.requestChannel); nativeFileSystemMonitoringEndpoint.setAutoCreateDirectory(this.autoCreateDirectory); nativeFileSystemMonitoringEndpoint.setMaxQueuedValue(this.maxQueuedValue); nativeFileSystemMonitoringEndpoint.setAutoStartup(this.isAutoStartup()); nativeFileSystemMonitoringEndpoint.afterPropertiesSet(); // todo add support for a filter // todo add support for an 'auto-startup' boolean return nativeFileSystemMonitoringEndpoint; }
From source file:com.zaubersoftware.mule.module.jenkins.JenkinsCloudConnector.java
/** * Utility operation: Renders a template. Used in combination with the create operation * //from w w w . j av a2 s .com * {@code * <jenkins:render-template resourcePath="classpath:config.xml" > * <jenkins:models> * <jenkins:model key="groupId" value="foo-bar"/> * </jenkins:models> * </jenkins:render-template> * <jenkins:create projectName="foo" template="#[payload]"/> * } * * @param resourcePath template's resource path (Spring's {@link Resource}...Ex: classpath:com/.... http:..., etc.) * @param models model to replace in the template * @param charset template's charset * @param templateType template format * @return an string with the template rendered */ @Operation public String renderTemplate(final String resourcePath, final Map<String, String> models, @Parameter(optional = true, defaultValue = "utf-8") final String charset, @Parameter(optional = true, defaultValue = "VELOCITY") TemplateType templateType) { final ResourceEditor editor = new ResourceEditor(loader); editor.setAsText(resourcePath); final Resource resource = (Resource) editor.getValue(); final String ret; if (TemplateType.VELOCITY.equals(templateType)) { ret = new VelocityTemplate(resource, charset).render(models); } else { throw new IllegalArgumentException("Don't know how to render" + templateType); } return ret; }
From source file:com.brienwheeler.lib.db.LocationValidatingPersistenceUnitManager.java
/** * Accept a list of locations for persistence XML files. Before passing this list * to our superclass DefaultPersistenceUnitManager, check each location on the list * for actual existence.//from w w w . j ava2s. c om */ @Override public void setPersistenceXmlLocations(String... persistenceXmlLocations) { ValidationUtils.assertNotNull(persistenceXmlLocations, "persistenceXmlLocations cannot be null"); List<String> goodLocations = new ArrayList<String>(); ResourceEditor editor = new ResourceEditor(); for (String location : persistenceXmlLocations) { if (location == null || location.isEmpty()) continue; editor.setAsText(location); Resource resource = (Resource) editor.getValue(); if (resource != null && resource.exists()) { log.debug("using valid persistence XML location: " + location); goodLocations.add(location); } else { log.warn("ignoring invalid persistence XML location: " + location); } } String[] valid = goodLocations.toArray(new String[goodLocations.size()]); log.info("using validated persistence locations: [" + ArrayUtils.toString(valid) + "]"); super.setPersistenceXmlLocations(valid); }
From source file:org.springmodules.cache.config.CacheManagerAndProviderFacadeParserTests.java
/** * Verifies that the method//from w ww . j ava 2 s . c o m * <code>{@link AbstractCacheManagerAndProviderFacadeParser#doParse(String, Element, BeanDefinitionRegistry)}</code> * creates a <code>{@link Resource}</code> from the path specified in the * XML attribute "configLocation" and sets such resource as the value of the * property "configLocation" of the cache manager factory definition. * * @throws Exception * any exception thrown when reading the contents of the specified * configuration file */ public void testDoParseWithExistingConfigLocation() throws Exception { configElementBuilder.configLocation = ("classpath:" + PathUtils.getPackageNameAsPath(getClass()) + "/fakeConfigLocation.xml"); Element element = configElementBuilder.toXml(); expectGetCacheManagerClass(); parserControl.replay(); parser.doParse(BeanName.CACHE_PROVIDER_FACADE, element, registry); Resource configLocation = getConfigLocationFromCacheManager(); ResourceEditor editor = new ResourceEditor(); editor.setAsText(configElementBuilder.configLocation); String expectedContent = getResourceContent((Resource) editor.getValue()); String actualContent = getResourceContent(configLocation); assertEquals("<Config resource content>", expectedContent, actualContent); assertCacheProviderFacadeHasCacheManagerAsProperty(); }