/** * Create a new InputSourceEditor, * using the default ResourceEditor underneath. */ public InputSourceEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new URLEditor, using a default ResourceEditor underneath. */ public URLEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new ReaderEditor, using the default ResourceEditor underneath. */ public ReaderEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new PathEditor, using the default ResourceEditor underneath. */ public PathEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new InputStreamEditor, using the default ResourceEditor underneath. */ public InputStreamEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new FileEditor, using a default ResourceEditor underneath. */ public FileEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new FileEditor, using a default ResourceEditor underneath. */ public FileEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new ReaderEditor, using the default ResourceEditor underneath. */ public ReaderEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new URLEditor, using a default ResourceEditor underneath. */ public URLEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new PathEditor, using the default ResourceEditor underneath. */ public PathEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new InputSourceEditor, * using the default ResourceEditor underneath. */ public InputSourceEditor() { this.resourceEditor = new ResourceEditor(); }
/** * Create a new InputStreamEditor, using the default ResourceEditor underneath. */ public InputStreamEditor() { this.resourceEditor = new ResourceEditor(); }
@Test(expected = IllegalArgumentException.class) public void ctorWithNullCtorArgs() throws Exception { new ResourceEditor(null, null); }
@Test public void testSystemPropertyReplacement() { PropertyEditor editor = new ResourceEditor(); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource resolved = (Resource) editor.getValue(); assertEquals("foo-${bar}", resolved.getFilename()); } finally { System.getProperties().remove("test.prop"); } }
@Test public void sunnyDay() throws Exception { PropertyEditor editor = new ResourceEditor(); editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class"); Resource resource = (Resource) editor.getValue(); assertNotNull(resource); assertTrue(resource.exists()); }
@Test public void setAndGetAsTextWithNull() throws Exception { PropertyEditor editor = new ResourceEditor(); editor.setAsText(null); assertEquals("", editor.getAsText()); }
@Test(expected = IllegalArgumentException.class) public void testStrictSystemPropertyReplacement() { PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource resolved = (Resource) editor.getValue(); assertEquals("foo-${bar}", resolved.getFilename()); } finally { System.getProperties().remove("test.prop"); } }
@Test public void setAndGetAsTextWithWhitespaceResource() throws Exception { PropertyEditor editor = new ResourceEditor(); editor.setAsText(" "); assertEquals("", editor.getAsText()); }
env = new StandardServletEnvironment(); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, env)); initBeanWrapper(bw); bw.setPropertyValues(pvs, true);
/** * Map config parameters onto bean properties of this servlet, and * invoke subclass initialization. * @throws ServletException if bean properties are invalid (or required * properties are missing), or if subclass initialization fails. */ @Override public final void init() throws ServletException { // Set bean properties from init parameters. PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); if (!pvs.isEmpty()) { try { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { if (logger.isErrorEnabled()) { logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex); } throw ex; } } // Let subclasses do whatever initialization they like. initServletBean(); }