@Test(expected = IllegalArgumentException.class) public void testWithNonExistentResource() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening"); }
@Override public String getAsText() { URL value = (URL) getValue(); return (value != null ? value.toExternalForm() : ""); }
@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()); } }
@Test(expected = IllegalArgumentException.class) public void testCtorWithNullResourceEditor() throws Exception { new URLEditor(null); }
@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 String getAsText() { URL value = (URL) getValue(); return (value != null ? value.toExternalForm() : ""); }
this.defaultEditors.put(TimeZone.class, new TimeZoneEditor()); this.defaultEditors.put(URI.class, new URIEditor()); this.defaultEditors.put(URL.class, new URLEditor()); this.defaultEditors.put(UUID.class, new UUIDEditor()); this.defaultEditors.put(ZoneId.class, new ZoneIdEditor());
@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 String getAsText() { URL value = (URL) getValue(); return (value != null ? value.toExternalForm() : ""); }
@Test public void testStandardURI() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("mailto:juergen.hoeller@interface21.com"); Object value = urlEditor.getValue(); assertTrue(value instanceof URL); URL url = (URL) value; assertEquals(url.toExternalForm(), urlEditor.getAsText()); }
@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 String getAsText() { URL value = (URL) getValue(); return (value != null ? value.toExternalForm() : ""); }
@Test public void testStandardURL() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("http://www.springframework.org"); Object value = urlEditor.getValue(); assertTrue(value instanceof URL); URL url = (URL) value; assertEquals(url.toExternalForm(), urlEditor.getAsText()); }
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()); } }
public String getAsText() { URL value = (URL) getValue(); return (value != null ? value.toExternalForm() : ""); }
@Test public void testClasspathURL() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); Object value = urlEditor.getValue(); assertTrue(value instanceof URL); URL url = (URL) value; assertEquals(url.toExternalForm(), urlEditor.getAsText()); assertTrue(!url.getProtocol().startsWith("classpath")); }
@Test public void testSetAsTextWithNull() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText(null); assertNull(urlEditor.getValue()); assertEquals("", urlEditor.getAsText()); }
@Test public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception { PropertyEditor urlEditor = new URLEditor(); assertEquals("", urlEditor.getAsText()); }
this.defaultEditors.put(TimeZone.class, new TimeZoneEditor()); this.defaultEditors.put(URI.class, new URIEditor()); this.defaultEditors.put(URL.class, new URLEditor()); this.defaultEditors.put(UUID.class, new UUIDEditor()); this.defaultEditors.put(ZoneId.class, new ZoneIdEditor());
doRegisterEditor(registry, Path.class, new PathEditor(baseEditor)); doRegisterEditor(registry, Reader.class, new ReaderEditor(baseEditor)); doRegisterEditor(registry, URL.class, new URLEditor(baseEditor));