/** * Create a new InputSourceEditor, * using the default ResourceEditor underneath. */ public InputSourceEditor() { this.resourceEditor = new ResourceEditor(); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? resource.getURL() : null); } catch (IOException ex) { throw new IllegalArgumentException("Could not retrieve URL for " + resource + ": " + ex.getMessage()); } }
@Override public void setAsText(String text) { if (StringUtils.hasText(text)) { String locationToUse = resolvePath(text).trim(); setValue(this.resourceLoader.getResource(locationToUse)); } else { setValue(null); } }
public static String base64Image(String resourceAsText, String type) throws IOException { ResourceEditor editor = new ResourceEditor(); editor.setAsText(resourceAsText); Resource resource = (Resource) editor.getValue(); BufferedImage img = ImageIO.read(resource.getFile()); return encodeToString(img, type); }
@Override @Nullable public String getAsText() { Resource value = (Resource) getValue(); try { // Try to determine URL for resource. return (value != null ? value.getURL().toExternalForm() : ""); } catch (IOException ex) { // Couldn't determine resource URL - return null to indicate // that there is no appropriate text representation. return null; } }
public static String resource(String resourceAsText) throws Exception { ResourceEditor editor = new ResourceEditor(); editor.setAsText(resourceAsText); Resource resource = (Resource) editor.getValue(); String resourceString = IOUtils.toString(resource.getInputStream()); return replaceVars(resourceString); }
@Override @Nullable public String getAsText() { Resource value = (Resource) getValue(); try { // Try to determine URL for resource. return (value != null ? value.getURL().toExternalForm() : ""); } catch (IOException ex) { // Couldn't determine resource URL - return null to indicate // that there is no appropriate text representation. return null; } }
private static Properties getInProperties(String location) throws IOException { if (inCache.containsKey(location)) { return inCache.get(location); } 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; }
/** * Create a new ReaderEditor, using the default ResourceEditor underneath. */ public ReaderEditor() { this.resourceEditor = new ResourceEditor(); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? resource.getInputStream() : null); } catch (IOException ex) { throw new IllegalArgumentException("Failed to retrieve InputStream for " + resource, ex); } }
@Override public String getAsText() { Resource value = (Resource) getValue(); try { // Try to determine URL for resource. return (value != null ? value.getURL().toExternalForm() : ""); } catch (IOException ex) { // Couldn't determine resource URL - return null to indicate // that there is no appropriate text representation. return null; } }
@Override public void setAsText(String text) { if (StringUtils.hasText(text)) { String locationToUse = resolvePath(text).trim(); setValue(this.resourceLoader.getResource(locationToUse)); } else { setValue(null); } }
public String getKeywordDocumentation(String name) { if(name.equals("__intro__")) { ResourceEditor editor = new ResourceEditor(); editor.setAsText("libdoc.intro"); Resource r = (Resource) editor.getValue(); try { return IOUtils.toString(r.getInputStream()); } catch (IOException ignore) { return "No introduction provided."; } } return library.getKeywordDocumentation(name); } }
/** * Create a new PathEditor, using the default ResourceEditor underneath. */ public PathEditor() { this.resourceEditor = new ResourceEditor(); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? new InputSource(resource.getURL().toString()) : null); } catch (IOException ex) { throw new IllegalArgumentException( "Could not retrieve URL for " + resource + ": " + ex.getMessage()); } }
@Override @Nullable public String getAsText() { Resource value = (Resource) getValue(); try { // Try to determine URL for resource. return (value != null ? value.getURL().toExternalForm() : ""); } catch (IOException ex) { // Couldn't determine resource URL - return null to indicate // that there is no appropriate text representation. return null; } }
@Override public void setAsText(String text) { if (StringUtils.hasText(text)) { String locationToUse = resolvePath(text).trim(); setValue(this.resourceLoader.getResource(locationToUse)); } else { setValue(null); } }
private static File getResource(String path) throws Exception { if(!StringUtils.startsWith(path, "file:") && !StringUtils.startsWith(path, "classpath:")) { return file(path); } ResourceEditor editor = new ResourceEditor(); editor.setAsText(replaceVars(path)); return ((Resource) editor.getValue()).getFile(); }
/** * Create a new URLEditor, using a default ResourceEditor underneath. */ public URLEditor() { this.resourceEditor = new ResourceEditor(); }
@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); } }