org.apache.velocity.util.introspection.VelPropertySet Java Examples

The following examples show how to use org.apache.velocity.util.introspection.VelPropertySet. 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: WebappUberspector.java    From velocity-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Property setter
 * @param obj target object
 * @param identifier property key
 * @param arg value to set
 * @param i tool info
 * @return A Velocity Setter method.
 */
public VelPropertySet getPropertySet(Object obj, String identifier,
                                     Object arg, Info i)
{
    if (obj == null)
    {
        return null;
    }
    VelPropertySet ret = super.getPropertySet(obj,identifier,arg,i);

    if(ret == null) {
        Class claz = obj.getClass();
        if(obj instanceof HttpServletRequest
            || obj instanceof HttpSession
            || obj instanceof ServletContext)
        {
            SetExecutor executor = new SetAttributeExecutor(log, introspector, claz, arg, identifier);
            ret = executor.isAlive() ? new VelSetterImpl(executor) : null;
        }
    }
    return ret;
}
 
Example #2
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testNullPropertySetter()
    throws Exception
{
    Uberspect u = ri.getUberspect();
    GetPutObject gpo = new GetPutObject();
    Map map = new HashMap();

    // Don't screw up on null properties. That should map to put() on the GPO.
    VelPropertySet setter = u.getPropertySet(gpo, null, "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "put", setter.getMethodName());

    // And should be null on a Map which does not have a put()
    setter = u.getPropertySet(map, null, "", null);
    assertNull(setter);
}
 
Example #3
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testNullParameterType()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setRegular()
    setter = u.getPropertySet(uto, "Regular", null, null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setRegular", setter.getMethodName());

    // setAmbigous() - String and StringBuffer available
    setter = u.getPropertySet(uto, "Ambigous", null, null);
    assertNull(setter);

    // setAmbigous() - same with Object?
    setter = u.getPropertySet(uto, "Ambigous", new Object(), null);
    assertNull(setter);
}
 
Example #4
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testMultipleParameterTypes()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setAmbigous() - String
    setter = u.getPropertySet(uto, "Ambigous", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setAmbigous", setter.getMethodName());

    // setAmbigous() - StringBuffer
    setter = u.getPropertySet(uto, "Ambigous", new StringBuffer(), null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setAmbigous", setter.getMethodName());
}
 
Example #5
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testDisambiguation()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setUnambigous() - String
    setter = u.getPropertySet(uto, "unambiguous", "string", null);
    assertNotNull(setter);
    setter.invoke(uto, "string");

    // setUnambigous() - HashMap
    setter = u.getPropertySet(uto, "unambiguous", new HashMap(), null);
    assertNotNull(setter);
    setter.invoke(uto, new HashMap());
}
 
Example #6
Source File: AgnVelocityUberspector.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info info) throws Exception {
	
	if( isRuntimeCheckEnabled()) {
		checkRestrictedPackage( obj);

		if( this.packageChecker.includePackage( obj.getClass().getPackage())) {
			checkPropertyWriteAccess( obj, identifier, arg, info);
		}
	}
	
	return super.getPropertySet(obj, identifier, arg, info);
}
 
Example #7
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testNullObjects()
        throws Exception
{
    // How about some null objects... Gee, I'm mean. ;-)
    Uberspect u = ri.getUberspect();

    VelPropertyGet getter = u.getPropertyGet(null, "foo", null);
    assertNull(getter);

    VelPropertySet setter = u.getPropertySet(null, "foo", Object.class, null);
    assertNull(setter);
}
 
Example #8
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testEmptyPropertySetter()
        throws Exception
{
    Uberspect u = ri.getUberspect();
    Map map = new HashMap();

    VelPropertySet setter = u.getPropertySet(map, "", Object.class, null);

    // Don't screw up on empty properties. That should map to put("", Object)
    assertNotNull(setter);
    assertEquals("Found wrong method", "put", setter.getMethodName());
}
 
Example #9
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testRegularSetters()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setRegular()
    setter = u.getPropertySet(uto, "Regular", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setRegular", setter.getMethodName());

    // Lowercase regular
    setter = u.getPropertySet(uto, "regular", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setRegular", setter.getMethodName());

    // lowercase: setpremium()
    setter = u.getPropertySet(uto, "premium", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setpremium", setter.getMethodName());

    // test uppercase: getpremium()
    setter = u.getPropertySet(uto, "Premium", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setpremium", setter.getMethodName());
}
 
Example #10
Source File: UberspectDelegate.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info info) throws Exception {
	return uberspector.getPropertySet( obj, identifier, arg, info);
}
 
Example #11
Source File: ChainedUberspectorsTestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info info)
{
    identifier = identifier.replaceAll("foo","bar");
    return inner.getPropertySet(obj,identifier,arg,info);
}