[opencms-dev] Problems with labels in workplace_ru.properties
Christian Steinert
christian_steinert at web.de
Wed Sep 30 22:12:35 CEST 2009
Hi
I thought, I just send you the code that I am using to munge a property
file after loading it.
I had my own property file loader anyway which loads property files
directly from the VFS so for me it was no big deal to filter the
property file contents before invoking the Property class based on that
data.
/**
* Licensed under GNU GPL v.2 with linking exception - see
http://www.gnu.org/software/classpath/license.html
* Based on code from the GNU Classpath project
*
* convert a string containing unicode characters, so that it can
later be
* loaded by a property bundle class (property bundles cannot handle
unicode
* properly, unless it has been escaped for them by representing each
* character with a code value greater then 127 by a \\uxxxx sequence.)
*
* @param src
* the source data, containing a property bundle,
possibly with
* non-7bit-ascii characters
* @return the properly escaped resource bundle that can be loaded
*
* @throws CmsException
* in case of character encoding errors
*/
@SuppressWarnings(value = { "all" })
public static final byte[] native2ascii(byte[] src) throws
CmsException {
try {
String s = new String(src,
SiteContext.getDefaultSystemEncoding());
StringBuilder sb = new StringBuilder((int) (1.25 * s.length()));
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if ((int) c <= 127) {
sb.append(c);
} else {
sb.append("\\u");
if ((int) c <= 255)
sb.append("00");
else if ((int) c <= 4095)
sb.append("0");
sb.append(Integer.toHexString((int) c));
}
}
return sb.toString().getBytes(
SiteContext.getDefaultSystemEncoding());
} catch (UnsupportedEncodingException e) {
throw new BaCmsException("", e);
}
}
Regards
Christian
More information about the opencms-dev
mailing list