/** * Create a new ResourceScriptSource for the given resource. * @param resource the Resource to load the script from (using UTF-8 encoding) */ public ResourceScriptSource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); this.resource = new EncodedResource(resource, "UTF-8"); }
/** * Return the {@link org.springframework.core.io.Resource} to load the * script from. */ public final Resource getResource() { return this.resource.getResource(); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? new EncodedResource(resource).getReader() : null); } catch (IOException ex) { throw new IllegalArgumentException("Failed to retrieve Reader for " + resource, ex); } }
/** * Set the encoding used for reading the script resource. * <p>The default value for regular Resources is "UTF-8". * A {@code null} value implies the platform default. */ public void setEncoding(@Nullable String encoding) { this.resource = new EncodedResource(this.resource.getResource(), encoding); }
Reader reader = null; try { String filename = resource.getResource().getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { stream = resource.getInputStream(); persister.loadFromXml(props, stream); else if (resource.requiresReader()) { reader = resource.getReader(); persister.load(props, reader); stream = resource.getInputStream(); persister.load(props, stream);
InputStream inputStream = encodedResource.getResource().getInputStream(); try { InputSource inputSource = new InputSource(inputStream); if (encodedResource.getEncoding() != null) { inputSource.setEncoding(encodedResource.getEncoding()); return doLoadBeanDefinitions(inputSource, encodedResource.getResource()); "IOException parsing XML document from " + encodedResource.getResource(), ex);
String filename = encodedResource.getResource().getFilename(); if (StringUtils.endsWithIgnoreCase(filename, ".xml")) { return this.standardXmlBeanDefinitionReader.loadBeanDefinitions(encodedResource); try { GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding); shell.evaluate(encodedResource.getReader(), "beans"); new Location(encodedResource.getResource()), null, ex));
@Test public void equalsWithNullOtherObject() { assertFalse(new EncodedResource(resource).equals(null)); }
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, @Nullable String commentPrefix, @Nullable String separator) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator); } finally { lnr.close(); } }
/** * Set the encoding used for reading the script resource. * <p>The default value for regular Resources is "UTF-8". * A {@code null} value implies the platform default. */ public void setEncoding(@Nullable String encoding) { this.resource = new EncodedResource(this.resource.getResource(), encoding); }
try (InputStream is = encodedResource.getResource().getInputStream()) { if (encodedResource.getEncoding() != null) { getPropertiesPersister().load(props, new InputStreamReader(is, encodedResource.getEncoding())); int count = registerBeanDefinitions(props, prefix, encodedResource.getResource().getDescription()); if (logger.isDebugEnabled()) { logger.debug("Loaded " + count + " bean definitions from " + encodedResource); throw new BeanDefinitionStoreException("Could not parse properties from " + encodedResource.getResource(), ex);
Reader reader = null; try { String filename = resource.getResource().getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { stream = resource.getInputStream(); persister.loadFromXml(props, stream); else if (resource.requiresReader()) { reader = resource.getReader(); persister.load(props, reader); stream = resource.getInputStream(); persister.load(props, stream);
String filename = encodedResource.getResource().getFilename(); if (StringUtils.endsWithIgnoreCase(filename, ".xml")) { return this.standardXmlBeanDefinitionReader.loadBeanDefinitions(encodedResource); try { GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding); shell.evaluate(encodedResource.getReader(), "beans"); new Location(encodedResource.getResource()), null, ex));
@Override public String getScriptAsString() throws IOException { synchronized (this.lastModifiedMonitor) { this.lastModified = retrieveLastModifiedTime(); } Reader reader = this.resource.getReader(); return FileCopyUtils.copyToString(reader); }
/** * Create a new ResourceScriptSource for the given resource. * @param resource the Resource to load the script from (using UTF-8 encoding) */ public ResourceScriptSource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); this.resource = new EncodedResource(resource, "UTF-8"); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? new EncodedResource(resource).getReader() : null); } catch (IOException ex) { throw new IllegalArgumentException("Failed to retrieve Reader for " + resource, ex); } }
/** * Return the {@link org.springframework.core.io.Resource} to load the * script from. */ public final Resource getResource() { return this.resource.getResource(); }
/** * Set the encoding used for reading the script resource. * <p>The default value for regular Resources is "UTF-8". * A {@code null} value implies the platform default. */ public void setEncoding(@Nullable String encoding) { this.resource = new EncodedResource(this.resource.getResource(), encoding); }
InputStream inputStream = encodedResource.getResource().getInputStream(); try { InputSource inputSource = new InputSource(inputStream); if (encodedResource.getEncoding() != null) { inputSource.setEncoding(encodedResource.getEncoding()); return doLoadBeanDefinitions(inputSource, encodedResource.getResource()); "IOException parsing XML document from " + encodedResource.getResource(), ex);
Reader reader = null; try { String filename = resource.getResource().getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { stream = resource.getInputStream(); persister.loadFromXml(props, stream); else if (resource.requiresReader()) { reader = resource.getReader(); persister.load(props, reader); stream = resource.getInputStream(); persister.load(props, stream);