[ http://issues.apache.org/jira/browse/VELOCITY-451?page=comments#action_12449020 ] Mailmur commented on VELOCITY-451: ----------------------------------
I think we should handle file encoding more transparently than what it is today. Issue 191, http://issues.apache.org/jira/browse/VELOCITY-191, is using a new UnicodeInputStream which is able to recognize _all_ unicode bom markers. BOM marker tell which bytesToString charset should be used. So this actually would make "input.encoding" velocity.properties entry obsolete. I have never really liked it, because we might have .vm files using several encodings (ISO-8859-1, UTF-8, UTF-16, ..). Problem is here and should be studied how to make charset transparent in case of UnicodeInputStream usecase: src\java\org\apache\velocity\runtime\resource\ContentResource.java public boolean process() throws ResourceNotFoundException { BufferedReader reader = null; try { StringWriter sw = new StringWriter(); reader = new BufferedReader( new InputStreamReader(resourceLoader.getResourceStream(name), encoding)); ...clip... We give here "encoding" value, but actually we _should_ oboye unicode BOM marker. I always say everybody should use unicode file formats, my choice is UTF-8 _with bom marker_ for all text files. Windows Notepad stores files with UTF-8 bom marker, but unfortunately not all text editors do so. One solution: Introduce new ResourceLoader interface which returns Reader instance. ResourceLoader could now use own velocity.properties attributes to control what to use in bytesToString translation. reader = new BufferedReader(resourceLoader.getResourceReader(name)); And velocity.properties could have "defaultCharset" if bom marker is not found. Give ISO-8859-1 or UTF-8 as you please in case of non-bom marked file. 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.defaultCharset=ISO-8859-1 file.resource.loader.modificationCheckInterval = 5 > Do some investigation into UTF-16 and InputStream / Reader interfaces > --------------------------------------------------------------------- > > Key: VELOCITY-451 > URL: http://issues.apache.org/jira/browse/VELOCITY-451 > Project: Velocity > Issue Type: Improvement > Components: Engine > Affects Versions: 2.0 > Reporter: Henning Schmiedehausen > Priority: Minor > > See http://koti.mbnet.fi/akini/java/unicodereader/ for a description of the > problem and some example code. -- 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
