You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jeremy Jongsma <jj...@futuresource.com> on 2004/11/11 18:06:36 UTC

VelocityEngine.init(Properties p) not working

I'm unable to get the VelocityEngine.init(Properties p) method to work. 
  VelocityEngine seems to be completely ignoring the properties.  In my 
app, I'm using the following code (Velocity 1.4):

VelocityEngine ve = new VelocityEngine();
Properties p = new Properties();
p.load(stream);
ve.init(p);

Doing a p.list(new PrintStream(System.out)) gives the following:

resource.loader = class
class.resource.loader.class = org.apache.velocity.runtime.resource....
...

The problem is - ve.getProperty("resource.loader") now returns "[file]"! 
  It also ignores all my logging configuration, which leads me to 
believe it's not even reading the properties.

It returns the expected value ("[class]") if I use the following 
initialization code instead of a Properties object:

ve.setProperty("resource.loader", "class");
...
ve.init();

I couldn't find any bug reports on this.  Anyone see a no-brainer that 
I'm missing before I ask the devs?

-j

-- 
Jeremy Jongsma
Lead Architect
FutureSource, LLC
jjongsma@futuresource.com
http://www.futuresource.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Claude Brisson <cl...@renegat.net>.
> 
> > All the default properties are visible through the application
> > properties object using either the props.propertyNames() enumerator or a
> > props.getProperty() call.  How is it possible that VelocityEngine cannot
> > see these properties?  There is no way to distinguish between the two
> > types via the Properties API (as far as I can tell) - they should all
> > look the same to velocity.
>
> It looks like a possible bug in o.a.c.collections.ExtendedProperties. 
> Velocity uses this class instead of java.util.Properties.  It calls
> ExtendedProperties#convertProperties() to convert the properties, but
> this method uses Properties#keys() to transfer the values.  This is
> equivalent to HashTable#keys(), which has no reference to the default
> properties.
> 

That's right. You should check your version of jakarta-commons, and
maybe upgrade to the latest release.

Claude




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi everyone,

> > It looks like a possible bug in o.a.c.collections.ExtendedProperties.
> > Velocity uses this class instead of java.util.Properties.  It calls
> > ExtendedProperties#convertProperties() to convert the properties, but
> > this method uses Properties#keys() to transfer the values.  This is
> > equivalent to HashTable#keys(), which has no reference to the default
> > properties.
> I've filed an issue on this.
>  http://issues.apache.org/bugzilla/show_bug.cgi?id=32204

I also filed one for Velocity, so we won't forget.
  http://issues.apache.org/bugzilla/show_bug.cgi?id=33020

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi everyone,

> > It looks like a possible bug in o.a.c.collections.ExtendedProperties.
> > Velocity uses this class instead of java.util.Properties.  It calls
> > ExtendedProperties#convertProperties() to convert the properties, but
> > this method uses Properties#keys() to transfer the values.  This is
> > equivalent to HashTable#keys(), which has no reference to the default
> > properties.
> I've filed an issue on this.
>  http://issues.apache.org/bugzilla/show_bug.cgi?id=32204

I also filed one for Velocity, so we won't forget.
  http://issues.apache.org/bugzilla/show_bug.cgi?id=33020

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Shinobu Kawai <sh...@gmail.com>.
> It looks like a possible bug in o.a.c.collections.ExtendedProperties.
> Velocity uses this class instead of java.util.Properties.  It calls
> ExtendedProperties#convertProperties() to convert the properties, but
> this method uses Properties#keys() to transfer the values.  This is
> equivalent to HashTable#keys(), which has no reference to the default
> properties.
I've filed an issue on this.
  http://issues.apache.org/bugzilla/show_bug.cgi?id=32204

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Jeremy,

> When I initialized VelocityEngine directly with the default properties
> object, it worked.  So apparently, somehow the default properties are
> not accessible to VelocityEngine when I pass in the application
> properties object.
> 
> All the default properties are visible through the application
> properties object using either the props.propertyNames() enumerator or a
> props.getProperty() call.  How is it possible that VelocityEngine cannot
> see these properties?  There is no way to distinguish between the two
> types via the Properties API (as far as I can tell) - they should all
> look the same to velocity.
It looks like a possible bug in o.a.c.collections.ExtendedProperties. 
Velocity uses this class instead of java.util.Properties.  It calls
ExtendedProperties#convertProperties() to convert the properties, but
this method uses Properties#keys() to transfer the values.  This is
equivalent to HashTable#keys(), which has no reference to the default
properties.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Jeremy Jongsma <jj...@futuresource.com>.
p.getProperty("resource.loader") returns "class".

Ok, I found the problem.  I don't understand it though.

I'm creating my application properties object with a set of default 
properties.  i.e.:

Properties defaults = new Properties();
default.load(stream);
Properties props = new Properties(defaults);
props.load(stream2);

The property "resource.loader" only exists in the default properties. 
But calling props.getProperty("resource.loader") returns the correct 
value, as mentioned above.

When I initialized VelocityEngine directly with the default properties 
object, it worked.  So apparently, somehow the default properties are 
not accessible to VelocityEngine when I pass in the application 
properties object.

All the default properties are visible through the application 
properties object using either the props.propertyNames() enumerator or a 
props.getProperty() call.  How is it possible that VelocityEngine cannot 
see these properties?  There is no way to distinguish between the two 
types via the Properties API (as far as I can tell) - they should all 
look the same to velocity.

-j

Shinobu Kawai wrote:
> Hi Jeremy,
> 
> 
>>I'm unable to get the VelocityEngine.init(Properties p) method to work.
>> VelocityEngine seems to be completely ignoring the properties.  In my
>>app, I'm using the following code (Velocity 1.4):
>>
>>VelocityEngine ve = new VelocityEngine();
>>Properties p = new Properties();
>>p.load(stream);
>>ve.init(p);
>>
>>Doing a p.list(new PrintStream(System.out)) gives the following:
>>
>>resource.loader = class
> 
> What does p.getProperty("resource.loader") return?
> 
> 
>>The problem is - ve.getProperty("resource.loader") now returns "[file]"!
>> It also ignores all my logging configuration, which leads me to
>>believe it's not even reading the properties.
> 
> 
> ## snip
> 
> 
>>I couldn't find any bug reports on this.  Anyone see a no-brainer that
>>I'm missing before I ask the devs?
> 
> Works at my place.  B)
>   http://sylow.no-ip.com/maven/site/ShinobuDemo/xref-test/org/ieee/shinobu/demo/velocity/InitVelocityEngineTest.html
> 
> Try this:
> VelocityEngine ve = new VelocityEngine();
> Properties p = new Properties();
> p.setProperty("resource.loader", "class");
> p.setProperty("class.resource.loader.class",
> "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
> ve.init(p);
> System.out.println(ve.getProperty("resource.loader"));
> 
> If it works (which it should), the problem is in your stream.
> 
> Best regards,
> -- Shinobu Kawai
> 

-- 
Jeremy Jongsma
Lead Architect
FutureSource, LLC
jjongsma@futuresource.com
http://www.futuresource.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityEngine.init(Properties p) not working

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Jeremy,

> I'm unable to get the VelocityEngine.init(Properties p) method to work.
>  VelocityEngine seems to be completely ignoring the properties.  In my
> app, I'm using the following code (Velocity 1.4):
> 
> VelocityEngine ve = new VelocityEngine();
> Properties p = new Properties();
> p.load(stream);
> ve.init(p);
> 
> Doing a p.list(new PrintStream(System.out)) gives the following:
> 
> resource.loader = class
What does p.getProperty("resource.loader") return?

> The problem is - ve.getProperty("resource.loader") now returns "[file]"!
>  It also ignores all my logging configuration, which leads me to
> believe it's not even reading the properties.

## snip

> I couldn't find any bug reports on this.  Anyone see a no-brainer that
> I'm missing before I ask the devs?
Works at my place.  B)
  http://sylow.no-ip.com/maven/site/ShinobuDemo/xref-test/org/ieee/shinobu/demo/velocity/InitVelocityEngineTest.html

Try this:
VelocityEngine ve = new VelocityEngine();
Properties p = new Properties();
p.setProperty("resource.loader", "class");
p.setProperty("class.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
ve.init(p);
System.out.println(ve.getProperty("resource.loader"));

If it works (which it should), the problem is in your stream.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org