You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jason Tesser <ja...@gmail.com> on 2009/06/29 15:49:23 UTC

Serialize Template Object

I have a need for cache purposes to serialize the Velocity Resource object.
I was hoping to cache the velocity code within the template and then
reconstruct the template on the other end.

Is there a good way to do this.  I am look at the code and api and it isn't
obvious how.

Thanks,
Jason Tesser
dotCMS Lead Development Manager
1-305-858-1422

Re: Serialize Template Object

Posted by bluejoe <bl...@gmail.com>.
No, I didn't continue to do that. However, I chose another method, which let VelocityEngine loads all templates once the application starts.
Velocity's ResourceLoader uses a cache and will load resources while they are modified. You can configure velocity.properties such as:

#file.resource.loader.cache = true
#file.resource.loader.modificationCheckInterval = 2

webapp.resource.loader.cache = true
webapp.resource.loader.modificationCheckInterval = 2


--bluejoe

----- Original Message ----- 
From: "Jason Tesser" <ja...@gmail.com>
To: "Velocity Users List" <us...@velocity.apache.org>
Sent: Wednesday, July 08, 2009 6:32 PM
Subject: Re: Serialize Template Object


> Ohh I started to go there and turned back as I wasn't sure that was the best
> direction moving forward.  Were you successful?  Is the code open?
> 
> I ended up with implementing another cache layer.  We cache at the
> ResourceLoader just our velocity code which gets returned to velocity as an
> inputstream.  That object is serializable. We also implement a velocity
> cache which caches a wrapper of thr Velocity Resource but as a transient
> object.
> 
> So Basically if the Velocity cache returns null and the object has been
> loaded before and not modified at least the loader will return the the
> Inputstream without hitting db etc...
> 
> Thanks,
> Jason Tesser
> dotCMS Lead Development Manager
> 1-305-858-1422
> 
> 
> On Wed, Jul 8, 2009 at 4:58 AM, bluejoe <bl...@gmail.com> wrote:
> 
>> I had the same idea some months ago, and asked if there is any exsiting
>> method to follow.
>> It seems that we have to write extra codes to serialize the ASTNodes:(
>>
>> -bluejoe
>> ----- Original Message -----
>> From: "Jason Tesser" <ja...@gmail.com>
>> To: <us...@velocity.apache.org>
>> Sent: Monday, June 29, 2009 9:49 PM
>> Subject: Serialize Template Object
>>
>>
>> >I have a need for cache purposes to serialize the Velocity Resource
>> object.
>> > I was hoping to cache the velocity code within the template and then
>> > reconstruct the template on the other end.
>> >
>> > Is there a good way to do this.  I am look at the code and api and it
>> isn't
>> > obvious how.
>> >
>> > Thanks,
>> > Jason Tesser
>> > dotCMS Lead Development Manager
>> > 1-305-858-1422
>> >
>>
>

Re: AW: AW: getEncodingFromStream from UnicodeInputStream

Posted by mailmur <ma...@yahoo.com>.
Hmm..yes, I think I see it now. Users must use a same encoding for all template files and tell it in an input.encoding attribute. Failing to do so gives an incorrent bytesToChar conversion on some template files.
   [ Velocity.properties ]
   input.encoding        = UTF-8

This is Velocity loader limitation, it should use Reader* instead of InputStream* interface. All problems would go away if Velocity used UnicodeReader implementation.
http://koti.mbnet.fi/akini/java/unicodereader/
http://koti.mbnet.fi/akini/java/unicodereader/UnicodeReader.java.txt


--- On Wed, 7/22/09, mailmur <ma...@yahoo.com> wrote:

> From: mailmur <ma...@yahoo.com>
> Subject: Re: AW: AW: getEncodingFromStream from UnicodeInputStream
> To: "Velocity Users List" <us...@velocity.apache.org>
> Date: Wednesday, July 22, 2009, 12:44 AM
> 
> Here is an old v1.6 example but principal applies to a
> current release.
> http://koti.mbnet.fi/akini/java/unicodereader/
> http://koti.mbnet.fi/akini/java/unicodereader/UnicodeLoaderForVelocity.zip
> 
> resource.loader = file
> file.resource.loader.class =
> org.apache.velocity.runtime.resource.loader.FileResourceLoader
> file.resource.loader.unicode = true
> 
> Yes, FileResourceloader with "unicode=true" attribute can
> handle all utf* and ansi encoding transparently. Encoding is
> autorecognized by BOM marker or fallback to a legacy ansi.
> We don't need or should tell a read encoding, its an
> internal bytesToChars issue handled by unicodeinputstream.
>    ...
>    Template template =
> Velocity.getTemplate(srcFile);
>    template.merge(context, out);
>    ...
> 
> You should not use Velocity.getTemplate(name, encoding)
> method if used FileResourceLoader with unicode=true
> attribute. It voids all the wise purpose of
> FileResourceLoader unicode.
> 
> 
> --- On Tue, 7/21/09, Johann.Weber@eventim.de
> <Jo...@eventim.de>
> wrote:
> 
> > From: Johann.Weber@eventim.de
> <Jo...@eventim.de>
> > Subject: AW: AW: getEncodingFromStream from
> UnicodeInputStream
> > To: user@velocity.apache.org
> > Date: Tuesday, July 21, 2009, 10:14 AM
> > The UnicodeInputStream class is used
> > to load files with a BOM correctly. It knows the file
> > encoding but I can't use it.
> > If it is the case that I have to load files with a
> > different encoding (e.g. UTF-8 and UTF-16), I won't be
> able
> > to handle such a situation, because I must set the
> > input.encoding property or pass it to the getTemplate
> > method. Otherwise, the default encoding will be taken
> for
> > all files.
> > 
> > 
> > -----Ursprüngliche Nachricht-----
> > Von: mailmur [mailto:mailmur@yahoo.com]
> > 
> > Gesendet: Dienstag, 21. Juli 2009 08:22
> > An: Velocity Users List
> > Betreff: Re: AW: getEncodingFromStream from
> > UnicodeInputStream
> > 
> > 
> > I think you misunderstood a fundametal reason of the
> > UnicodeInputStream class. It is to use so that
> template
> > loaders don't need to tell an encoding so all is
> fully
> > transparent.
> > 
> > getTemplate(name, encoding) method is an old legacy
> method
> > where we as a user must know the encoding beforehand.
> This
> > is very very unfortunate issue, something we should
> not
> > worry about in the first place.
> > 
> > Its only FileResourceLoader class using the
> > UnicodeInputStream class. All other loaders don't use
> it,
> > this is a lack of Velocity loader implementation. If
> all
> > loaders was to use it then we just would use
> > getTemplate(name) and all is fine.
> > 
> > FileResourceLoader does not use it as a default use,
> you
> > must tell "unicode=true" in a velocity.properties
> > configuration. Then you can forget the file encoding,
> ansi
> > and utf* templates are loaded properly.
> > 
> > http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
> > 
> > 
> > --- On Tue, 7/14/09, Johann.Weber@eventim.de
> > <Jo...@eventim.de>
> > wrote:
> > 
> > > From: Johann.Weber@eventim.de
> > <Jo...@eventim.de>
> > > Subject: AW: getEncodingFromStream from
> > UnicodeInputStream
> > > To: user@velocity.apache.org
> > > Date: Tuesday, July 14, 2009, 9:36 AM
> > > It is in
> > >
> >
> org.apache.velocity.app.VelocityEngine.getTemplate(String
> > > name, String encoding)
> > > They sure do when you're using BOM in your
> templates.
> > I
> > > though it would be nice to use the encoding which
> was
> > > determined by UnicodeInputStream.
> > > 
> > > -----Ursprüngliche Nachricht-----
> > > Von: mailmur [mailto:mailmur@yahoo.com]
> > > 
> > > Gesendet: Montag, 13. Juli 2009 21:16
> > > An: Velocity Users List
> > > Betreff: Re: getEncodingFromStream from
> > UnicodeInputStream
> > > 
> > > 
> > > I think its not possible, its basicly an
> internal
> > > bytesToChars issue to know about encoding.
> Textual
> > templates
> > > know nothing about byte storage they run at
> character
> > level
> > > nor know nothing about template loader instance
> was
> > used.
> > > 
> > > What is it getTemplate() method you mean, can
> you
> > point me
> > > to the class?
> > > http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/
> > > 
> > > 
> > > 
> > > --- On Wed, 7/8/09, Johann.Weber@eventim.de
> > > <Jo...@eventim.de>
> > > wrote:
> > > > From: Johann.Weber@eventim.de
> > > <Jo...@eventim.de>
> > > > Subject: getEncodingFromStream from
> > > UnicodeInputStream
> > > > To: user@velocity.apache.org
> > > > Date: Wednesday, July 8, 2009, 2:48 PM
> > > > Hi all,
> > > > 
> > > > Is there a way to get the encoding
> information
> > from
> > > > UnicodeInputStream to use it in the
> > getTemplate()
> > > method?
> > > > How do I can use the encoding which was
> auto
> > detected
> > > in case of unicode file recognition?
> > 
> > 
> >       
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> > 
> > 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 


      

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


Re: AW: AW: getEncodingFromStream from UnicodeInputStream

Posted by mailmur <ma...@yahoo.com>.
Here is an old v1.6 example but principal applies to a current release.
http://koti.mbnet.fi/akini/java/unicodereader/
http://koti.mbnet.fi/akini/java/unicodereader/UnicodeLoaderForVelocity.zip

resource.loader = file
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.unicode = true

Yes, FileResourceloader with "unicode=true" attribute can handle all utf* and ansi encoding transparently. Encoding is autorecognized by BOM marker or fallback to a legacy ansi. We don't need or should tell a read encoding, its an internal bytesToChars issue handled by unicodeinputstream.
   ...
   Template template = Velocity.getTemplate(srcFile);
   template.merge(context, out);
   ...

You should not use Velocity.getTemplate(name, encoding) method if used FileResourceLoader with unicode=true attribute. It voids all the wise purpose of FileResourceLoader unicode.


--- On Tue, 7/21/09, Johann.Weber@eventim.de <Jo...@eventim.de> wrote:

> From: Johann.Weber@eventim.de <Jo...@eventim.de>
> Subject: AW: AW: getEncodingFromStream from UnicodeInputStream
> To: user@velocity.apache.org
> Date: Tuesday, July 21, 2009, 10:14 AM
> The UnicodeInputStream class is used
> to load files with a BOM correctly. It knows the file
> encoding but I can't use it.
> If it is the case that I have to load files with a
> different encoding (e.g. UTF-8 and UTF-16), I won't be able
> to handle such a situation, because I must set the
> input.encoding property or pass it to the getTemplate
> method. Otherwise, the default encoding will be taken for
> all files.
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: mailmur [mailto:mailmur@yahoo.com]
> 
> Gesendet: Dienstag, 21. Juli 2009 08:22
> An: Velocity Users List
> Betreff: Re: AW: getEncodingFromStream from
> UnicodeInputStream
> 
> 
> I think you misunderstood a fundametal reason of the
> UnicodeInputStream class. It is to use so that template
> loaders don't need to tell an encoding so all is fully
> transparent.
> 
> getTemplate(name, encoding) method is an old legacy method
> where we as a user must know the encoding beforehand. This
> is very very unfortunate issue, something we should not
> worry about in the first place.
> 
> Its only FileResourceLoader class using the
> UnicodeInputStream class. All other loaders don't use it,
> this is a lack of Velocity loader implementation. If all
> loaders was to use it then we just would use
> getTemplate(name) and all is fine.
> 
> FileResourceLoader does not use it as a default use, you
> must tell "unicode=true" in a velocity.properties
> configuration. Then you can forget the file encoding, ansi
> and utf* templates are loaded properly.
> 
> http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
> 
> 
> --- On Tue, 7/14/09, Johann.Weber@eventim.de
> <Jo...@eventim.de>
> wrote:
> 
> > From: Johann.Weber@eventim.de
> <Jo...@eventim.de>
> > Subject: AW: getEncodingFromStream from
> UnicodeInputStream
> > To: user@velocity.apache.org
> > Date: Tuesday, July 14, 2009, 9:36 AM
> > It is in
> >
> org.apache.velocity.app.VelocityEngine.getTemplate(String
> > name, String encoding)
> > They sure do when you're using BOM in your templates.
> I
> > though it would be nice to use the encoding which was
> > determined by UnicodeInputStream.
> > 
> > -----Ursprüngliche Nachricht-----
> > Von: mailmur [mailto:mailmur@yahoo.com]
> > 
> > Gesendet: Montag, 13. Juli 2009 21:16
> > An: Velocity Users List
> > Betreff: Re: getEncodingFromStream from
> UnicodeInputStream
> > 
> > 
> > I think its not possible, its basicly an internal
> > bytesToChars issue to know about encoding. Textual
> templates
> > know nothing about byte storage they run at character
> level
> > nor know nothing about template loader instance was
> used.
> > 
> > What is it getTemplate() method you mean, can you
> point me
> > to the class?
> > http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/
> > 
> > 
> > 
> > --- On Wed, 7/8/09, Johann.Weber@eventim.de
> > <Jo...@eventim.de>
> > wrote:
> > > From: Johann.Weber@eventim.de
> > <Jo...@eventim.de>
> > > Subject: getEncodingFromStream from
> > UnicodeInputStream
> > > To: user@velocity.apache.org
> > > Date: Wednesday, July 8, 2009, 2:48 PM
> > > Hi all,
> > > 
> > > Is there a way to get the encoding information
> from
> > > UnicodeInputStream to use it in the
> getTemplate()
> > method?
> > > How do I can use the encoding which was auto
> detected
> > in case of unicode file recognition?
> 
> 
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 


      

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


AW: AW: getEncodingFromStream from UnicodeInputStream

Posted by Jo...@eventim.de.
The UnicodeInputStream class is used to load files with a BOM correctly. It knows the file encoding but I can't use it.
If it is the case that I have to load files with a different encoding (e.g. UTF-8 and UTF-16), I won't be able to handle such a situation, because I must set the input.encoding property or pass it to the getTemplate method. Otherwise, the default encoding will be taken for all files.


-----Ursprüngliche Nachricht-----
Von: mailmur [mailto:mailmur@yahoo.com] 
Gesendet: Dienstag, 21. Juli 2009 08:22
An: Velocity Users List
Betreff: Re: AW: getEncodingFromStream from UnicodeInputStream


I think you misunderstood a fundametal reason of the UnicodeInputStream class. It is to use so that template loaders don't need to tell an encoding so all is fully transparent.

getTemplate(name, encoding) method is an old legacy method where we as a user must know the encoding beforehand. This is very very unfortunate issue, something we should not worry about in the first place.

Its only FileResourceLoader class using the UnicodeInputStream class. All other loaders don't use it, this is a lack of Velocity loader implementation. If all loaders was to use it then we just would use getTemplate(name) and all is fine.

FileResourceLoader does not use it as a default use, you must tell "unicode=true" in a velocity.properties configuration. Then you can forget the file encoding, ansi and utf* templates are loaded properly.

http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java


--- On Tue, 7/14/09, Johann.Weber@eventim.de <Jo...@eventim.de> wrote:

> From: Johann.Weber@eventim.de <Jo...@eventim.de>
> Subject: AW: getEncodingFromStream from UnicodeInputStream
> To: user@velocity.apache.org
> Date: Tuesday, July 14, 2009, 9:36 AM
> It is in
> org.apache.velocity.app.VelocityEngine.getTemplate(String
> name, String encoding)
> They sure do when you're using BOM in your templates. I
> though it would be nice to use the encoding which was
> determined by UnicodeInputStream.
> 
> -----Ursprüngliche Nachricht-----
> Von: mailmur [mailto:mailmur@yahoo.com]
> 
> Gesendet: Montag, 13. Juli 2009 21:16
> An: Velocity Users List
> Betreff: Re: getEncodingFromStream from UnicodeInputStream
> 
> 
> I think its not possible, its basicly an internal
> bytesToChars issue to know about encoding. Textual templates
> know nothing about byte storage they run at character level
> nor know nothing about template loader instance was used.
> 
> What is it getTemplate() method you mean, can you point me
> to the class?
> http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/
> 
> 
> 
> --- On Wed, 7/8/09, Johann.Weber@eventim.de
> <Jo...@eventim.de>
> wrote:
> > From: Johann.Weber@eventim.de
> <Jo...@eventim.de>
> > Subject: getEncodingFromStream from
> UnicodeInputStream
> > To: user@velocity.apache.org
> > Date: Wednesday, July 8, 2009, 2:48 PM
> > Hi all,
> > 
> > Is there a way to get the encoding information from
> > UnicodeInputStream to use it in the getTemplate()
> method?
> > How do I can use the encoding which was auto detected
> in case of unicode file recognition?


      

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


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


Re: AW: getEncodingFromStream from UnicodeInputStream

Posted by mailmur <ma...@yahoo.com>.
I think you misunderstood a fundametal reason of the UnicodeInputStream class. It is to use so that template loaders don't need to tell an encoding so all is fully transparent.

getTemplate(name, encoding) method is an old legacy method where we as a user must know the encoding beforehand. This is very very unfortunate issue, something we should not worry about in the first place.

Its only FileResourceLoader class using the UnicodeInputStream class. All other loaders don't use it, this is a lack of Velocity loader implementation. If all loaders was to use it then we just would use getTemplate(name) and all is fine.

FileResourceLoader does not use it as a default use, you must tell "unicode=true" in a velocity.properties configuration. Then you can forget the file encoding, ansi and utf* templates are loaded properly.

http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java


--- On Tue, 7/14/09, Johann.Weber@eventim.de <Jo...@eventim.de> wrote:

> From: Johann.Weber@eventim.de <Jo...@eventim.de>
> Subject: AW: getEncodingFromStream from UnicodeInputStream
> To: user@velocity.apache.org
> Date: Tuesday, July 14, 2009, 9:36 AM
> It is in
> org.apache.velocity.app.VelocityEngine.getTemplate(String
> name, String encoding)
> They sure do when you're using BOM in your templates. I
> though it would be nice to use the encoding which was
> determined by UnicodeInputStream.
> 
> -----Ursprüngliche Nachricht-----
> Von: mailmur [mailto:mailmur@yahoo.com]
> 
> Gesendet: Montag, 13. Juli 2009 21:16
> An: Velocity Users List
> Betreff: Re: getEncodingFromStream from UnicodeInputStream
> 
> 
> I think its not possible, its basicly an internal
> bytesToChars issue to know about encoding. Textual templates
> know nothing about byte storage they run at character level
> nor know nothing about template loader instance was used.
> 
> What is it getTemplate() method you mean, can you point me
> to the class?
> http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/
> 
> 
> 
> --- On Wed, 7/8/09, Johann.Weber@eventim.de
> <Jo...@eventim.de>
> wrote:
> > From: Johann.Weber@eventim.de
> <Jo...@eventim.de>
> > Subject: getEncodingFromStream from
> UnicodeInputStream
> > To: user@velocity.apache.org
> > Date: Wednesday, July 8, 2009, 2:48 PM
> > Hi all,
> > 
> > Is there a way to get the encoding information from
> > UnicodeInputStream to use it in the getTemplate()
> method?
> > How do I can use the encoding which was auto detected
> in case of unicode file recognition?


      

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


AW: getEncodingFromStream from UnicodeInputStream

Posted by Jo...@eventim.de.
It is in org.apache.velocity.app.VelocityEngine.getTemplate(String name, String encoding)
They sure do when you're using BOM in your templates. I though it would be nice to use the encoding which was determined by UnicodeInputStream.

-----Ursprüngliche Nachricht-----
Von: mailmur [mailto:mailmur@yahoo.com] 
Gesendet: Montag, 13. Juli 2009 21:16
An: Velocity Users List
Betreff: Re: getEncodingFromStream from UnicodeInputStream


I think its not possible, its basicly an internal bytesToChars issue to know about encoding. Textual templates know nothing about byte storage they run at character level nor know nothing about template loader instance was used.

What is it getTemplate() method you mean, can you point me to the class?
http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/



--- On Wed, 7/8/09, Johann.Weber@eventim.de <Jo...@eventim.de> wrote:
> From: Johann.Weber@eventim.de <Jo...@eventim.de>
> Subject: getEncodingFromStream from UnicodeInputStream
> To: user@velocity.apache.org
> Date: Wednesday, July 8, 2009, 2:48 PM
> Hi all,
> 
> Is there a way to get the encoding information from
> UnicodeInputStream to use it in the getTemplate() method?
> How do I can use the encoding which was auto detected in
> case of unicode file recognition?


      

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


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


Re: getEncodingFromStream from UnicodeInputStream

Posted by mailmur <ma...@yahoo.com>.
I think its not possible, its basicly an internal bytesToChars issue to know about encoding. Textual templates know nothing about byte storage they run at character level nor know nothing about template loader instance was used.

What is it getTemplate() method you mean, can you point me to the class?
http://svn.apache.org/repos/asf/velocity/engine/trunk/src/java/org/apache/velocity/



--- On Wed, 7/8/09, Johann.Weber@eventim.de <Jo...@eventim.de> wrote:
> From: Johann.Weber@eventim.de <Jo...@eventim.de>
> Subject: getEncodingFromStream from UnicodeInputStream
> To: user@velocity.apache.org
> Date: Wednesday, July 8, 2009, 2:48 PM
> Hi all,
> 
> Is there a way to get the encoding information from
> UnicodeInputStream to use it in the getTemplate() method?
> How do I can use the encoding which was auto detected in
> case of unicode file recognition?


      

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


getEncodingFromStream from UnicodeInputStream

Posted by Jo...@eventim.de.
Hi all,

Is there a way to get the encoding information from UnicodeInputStream
to use it in the getTemplate() method?
How do I can use the encoding which was auto detected in case of unicode
file recognition?

Regards,


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


Re: Serialize Template Object

Posted by Jason Tesser <ja...@gmail.com>.
Ohh I started to go there and turned back as I wasn't sure that was the best
direction moving forward.  Were you successful?  Is the code open?

I ended up with implementing another cache layer.  We cache at the
ResourceLoader just our velocity code which gets returned to velocity as an
inputstream.  That object is serializable. We also implement a velocity
cache which caches a wrapper of thr Velocity Resource but as a transient
object.

So Basically if the Velocity cache returns null and the object has been
loaded before and not modified at least the loader will return the the
Inputstream without hitting db etc...

Thanks,
Jason Tesser
dotCMS Lead Development Manager
1-305-858-1422


On Wed, Jul 8, 2009 at 4:58 AM, bluejoe <bl...@gmail.com> wrote:

> I had the same idea some months ago, and asked if there is any exsiting
> method to follow.
> It seems that we have to write extra codes to serialize the ASTNodes:(
>
> -bluejoe
> ----- Original Message -----
> From: "Jason Tesser" <ja...@gmail.com>
> To: <us...@velocity.apache.org>
> Sent: Monday, June 29, 2009 9:49 PM
> Subject: Serialize Template Object
>
>
> >I have a need for cache purposes to serialize the Velocity Resource
> object.
> > I was hoping to cache the velocity code within the template and then
> > reconstruct the template on the other end.
> >
> > Is there a good way to do this.  I am look at the code and api and it
> isn't
> > obvious how.
> >
> > Thanks,
> > Jason Tesser
> > dotCMS Lead Development Manager
> > 1-305-858-1422
> >
>

Re: Serialize Template Object

Posted by bluejoe <bl...@gmail.com>.
I had the same idea some months ago, and asked if there is any exsiting method to follow.
It seems that we have to write extra codes to serialize the ASTNodes:(

-bluejoe
----- Original Message ----- 
From: "Jason Tesser" <ja...@gmail.com>
To: <us...@velocity.apache.org>
Sent: Monday, June 29, 2009 9:49 PM
Subject: Serialize Template Object


>I have a need for cache purposes to serialize the Velocity Resource object.
> I was hoping to cache the velocity code within the template and then
> reconstruct the template on the other end.
> 
> Is there a good way to do this.  I am look at the code and api and it isn't
> obvious how.
> 
> Thanks,
> Jason Tesser
> dotCMS Lead Development Manager
> 1-305-858-1422
>