You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Mailmur (JIRA)" <ji...@apache.org> on 2006/11/11 20:48:37 UTC

[jira] Commented: (VELOCITY-191) UnicodeFileResourceLoader for Win2k Notepad UTF-8 files

    [ http://issues.apache.org/jira/browse/VELOCITY-191?page=comments#action_12449017 ] 
            
Mailmur commented on VELOCITY-191:
----------------------------------

I have completely forgotten this issue, thx for reminding me. I really hope we can get this to the 1.5 version release.

I created a zipfile where all necessary changes can be found.
http://koti.mbnet.fi/akini/java/unicodereader/FileResourceLoader-UnicodeStream.zip

See "readme.txt" in a zip root.

I came up the the clever solution to avoid 99% copypaste from the FileResourceLoader file. I have introduced a "skipBOM" resourceloader property. See modified FileResourceLoader, it has only two minor changes.
* init() method reads skipBOM attribute from configuration
* findTemplate() has "if-then-else" according to skipBOM value

changes:
new file: src\java\org\apache\velocity\io\UnicodeInputStream.java
modified file: src\java\org\apache\velocity\runtime\resource\loader\FileResourceLoader.java

velocity.properties example:
-------------
   runtime.log = ./velocity.log
   runtime.log.invalid.references = false

   # Change loader.class and see what happens if you run
   # templates saved with Win2k UTF-8 format.

   resource.loader = file
   file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
   file.resource.loader.path = ./templates
   file.resource.loader.cache = true
   file.resource.loader.skipBOM = true
   file.resource.loader.modificationCheckInterval = 5

   input.encoding        = UTF-8
   output.encoding       = UTF-8
-------------

If we get this to Velocity base I can dump my proprietary class and use Velocity library out-of-the-box.


> UnicodeFileResourceLoader for Win2k Notepad UTF-8 files
> -------------------------------------------------------
>
>                 Key: VELOCITY-191
>                 URL: http://issues.apache.org/jira/browse/VELOCITY-191
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.3.1
>         Environment: Operating System: All
> Platform: All
>            Reporter: Mailmur
>            Priority: Minor
>             Fix For: 1.5
>
>
> [copypaste from velocity-user mailing list]
> Date: Mon, 14 Jul 2003 01:52:11 -0700 (PDT)
> From: mailmur <ma...@yahoo.com>
> Subject: UnicodeFileResourceLoader to support Win2k Notepad UTF-8 files
> Content-Type: text/plain; charset=us-ascii
> I discovered, that files saved with Win2k Notepad UTF-8 format always generated 
> an extra ? character at the start of ISO-8859-1 output text. 
> This was due to lack of UTF8 BOM mark support in 
> InputStreamReader/OutputStreamWriter classes.
> I then created a inputstream implementation to skip BOM mark to overcome this 
> bug.
> Please, find here a source + testprogram to see it for yourself. I created 
> UnicodeFileResourceLoader to make all this transparent.
> http://koti.mbnet.fi/akini/java/unicodereader/
> I dont know what is the proper procedure to add this to Velocity core (if you 
> find this useful), but here it is. Feel free to change class package. Or is 
> this even the right list to announce such addition....
> Here is a link to Sun bugparade about the UTF-8 BOM problem: 
> http://developer.java.sun.com/developer/bugParade/bugs/4508058.html

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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