Java Code Examples for java.beans.PropertyEditor#getValue()

The following examples show how to use java.beans.PropertyEditor#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JspRuntimeLibrary.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static Object getValueFromBeanInfoPropertyEditor(
                       Class<?> attrClass, String attrName, String attrValue,
                       Class<?> propertyEditorClass)
    throws JasperException
{
    try {
        PropertyEditor pe = (PropertyEditor)propertyEditorClass.getConstructor().newInstance();
        pe.setAsText(attrValue);
        return pe.getValue();
    } catch (Exception ex) {
        throw new JasperException(
            Localizer.getMessage("jsp.error.beans.property.conversion",
                                 attrValue, attrClass.getName(), attrName,
                                 ex.getMessage()));
    }
}
 
Example 2
Source File: FileEditorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnqualifiedFileNameFound() throws Exception {
	PropertyEditor fileEditor = new FileEditor();
	String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass())
			+ ".class";
	fileEditor.setAsText(fileName);
	Object value = fileEditor.getValue();
	assertTrue(value instanceof File);
	File file = (File) value;
	assertTrue(file.exists());
	String absolutePath = file.getAbsolutePath();
	if (File.separatorChar == '\\') {
		absolutePath = absolutePath.replace('\\', '/');
	}
	assertTrue(absolutePath.endsWith(fileName));
}
 
Example 3
Source File: PathEditorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testUnqualifiedPathNameNotFound() throws Exception {
	PropertyEditor pathEditor = new PathEditor();
	String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
			ClassUtils.getShortName(getClass()) + ".clazz";
	pathEditor.setAsText(fileName);
	Object value = pathEditor.getValue();
	assertTrue(value instanceof Path);
	Path path = (Path) value;
	File file = path.toFile();
	assertFalse(file.exists());
	String absolutePath = file.getAbsolutePath();
	if (File.separatorChar == '\\') {
		absolutePath = absolutePath.replace('\\', '/');
	}
	assertTrue(absolutePath.endsWith(fileName));
}
 
Example 4
Source File: JspRuntimeLibrary.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static Object getValueFromBeanInfoPropertyEditor(
                       Class<?> attrClass, String attrName, String attrValue,
                       Class<?> propertyEditorClass) 
    throws JasperException 
{
    try {
        PropertyEditor pe =
            (PropertyEditor)propertyEditorClass.newInstance();
        pe.setAsText(attrValue);
        return pe.getValue();
    } catch (Exception ex) {
        throw new JasperException(
            Localizer.getMessage("jsp.error.beans.property.conversion",
                                 attrValue, attrClass.getName(), attrName,
                                 ex.getMessage()));
    }
}
 
Example 5
Source File: CustomEditorDisplayer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public boolean isValueModified() {
    PropertyEditor editor = getPropertyEditor();
    boolean result = editor.getValue() != originalValue;

    if (!result && editor instanceof EnhancedCustomPropertyEditor) {
        Object entered = ((EnhancedCustomPropertyEditor) editor).getPropertyValue();

        if (entered != null) {
            result = entered.equals(originalValue);
        } else {
            result = originalValue == null;
        }
    }

    return result;
}
 
Example 6
Source File: URLEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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"));
}
 
Example 7
Source File: FileEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testAbsoluteFileName() throws Exception {
	PropertyEditor fileEditor = new FileEditor();
	fileEditor.setAsText("/no_way_this_file_is_found.doc");
	Object value = fileEditor.getValue();
	assertTrue(value instanceof File);
	File file = (File) value;
	assertTrue(!file.exists());
}
 
Example 8
Source File: ResourceEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example 9
Source File: ThreadSafePropertyEditor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object setAsText(String str) {
    PropertyEditor editor = fetchFromPool();
    try {
        editor.setAsText(str);
        return editor.getValue();
    } finally {
        pool.putInPool(editor);
    }
}
 
Example 10
Source File: URLEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 11
Source File: URLEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 12
Source File: URIEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void standardURLWithWhitespace() throws Exception {
	PropertyEditor uriEditor = new URIEditor();
	uriEditor.setAsText("  http://www.springframework.org  ");
	Object value = uriEditor.getValue();
	assertTrue(value instanceof URI);
	URI uri = (URI) value;
	assertEquals("http://www.springframework.org", uri.toString());
}
 
Example 13
Source File: URIEditorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void doTestURI(String uriSpec) {
	PropertyEditor uriEditor = new URIEditor();
	uriEditor.setAsText(uriSpec);
	Object value = uriEditor.getValue();
	assertTrue(value instanceof URI);
	URI uri = (URI) value;
	assertEquals(uriSpec, uri.toString());
}
 
Example 14
Source File: ResourceArrayPropertyEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testVanillaResource() throws Exception {
	PropertyEditor editor = new ResourceArrayPropertyEditor();
	editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
	Resource[] resources = (Resource[]) editor.getValue();
	assertNotNull(resources);
	assertTrue(resources[0].exists());
}
 
Example 15
Source File: FileEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithNonExistentFile() throws Exception {
	PropertyEditor fileEditor = new FileEditor();
	fileEditor.setAsText("file:no_way_this_file_is_found.doc");
	Object value = fileEditor.getValue();
	assertTrue(value instanceof File);
	File file = (File) value;
	assertTrue(!file.exists());
}
 
Example 16
Source File: ParseContextConfig.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Object getValueFromString(Class<?> targetType, String text) {
  final PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
  if (editor == null) {
    throw new IllegalArgumentException("Cannot set properties of type " + targetType.getName());
  }
  editor.setAsText(text);
  return editor.getValue();
}
 
Example 17
Source File: IntrospectionSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static Object convert(final Object value, final Class type)
    throws URISyntaxException {
    final PropertyEditor editor = PropertyEditorManager.findEditor(type);
    if (editor != null) {
        editor.setAsText(value.toString());
        return editor.getValue();
    }
    if (type == URI.class) {
        return URLs.uri(value.toString());
    }
    return null;
}
 
Example 18
Source File: TypeConverterDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the given text value using the given property editor.
 * @param oldValue the previous value, if available (may be {@code null})
 * @param newTextValue the proposed text value
 * @param editor the PropertyEditor to use
 * @return the converted value
 */
private Object doConvertTextValue(Object oldValue, String newTextValue, PropertyEditor editor) {
	try {
		editor.setValue(oldValue);
	}
	catch (Exception ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);
		}
		// Swallow and proceed.
	}
	editor.setAsText(newTextValue);
	return editor.getValue();
}
 
Example 19
Source File: URIEditorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void standardURLWithWhitespace() throws Exception {
	PropertyEditor uriEditor = new URIEditor();
	uriEditor.setAsText("  https://www.springframework.org  ");
	Object value = uriEditor.getValue();
	assertTrue(value instanceof URI);
	URI uri = (URI) value;
	assertEquals("https://www.springframework.org", uri.toString());
}
 
Example 20
Source File: ResourceArrayPropertyEditorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
	PropertyEditor editor = new ResourceArrayPropertyEditor(
			new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
			false);
	System.setProperty("test.prop", "foo");
	try {
		editor.setAsText("${test.prop}-${bar}");
		Resource[] resources = (Resource[]) editor.getValue();
		assertEquals("foo-${bar}", resources[0].getFilename());
	}
	finally {
		System.getProperties().remove("test.prop");
	}
}