diff --git a/src/helma/scripting/rhino/HacHspConverter.java b/src/helma/scripting/rhino/HacHspConverter.java index 0139d0db..07265922 100644 --- a/src/helma/scripting/rhino/HacHspConverter.java +++ b/src/helma/scripting/rhino/HacHspConverter.java @@ -28,22 +28,25 @@ import java.util.StringTokenizer; */ public class HacHspConverter { - public static String convertHac(Resource action) throws IOException { + public static String convertHac(Resource action, String encoding) + throws IOException { String functionName = action.getBaseName().replace('.', '_') + "_action"; - return composeFunction(functionName, null, action.getContent()); + return composeFunction(functionName, null, action.getContent(encoding)); } - public static String convertHsp(Resource template) throws IOException { + public static String convertHsp(Resource template, String encoding) + throws IOException { String functionName = template.getBaseName().replace('.', '_'); - String body = processHspBody(template.getContent()); + String body = processHspBody(template.getContent(encoding)); return composeFunction(functionName, "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", body); } - public static String convertHspAsString(Resource template) throws IOException { + public static String convertHspAsString(Resource template, String encoding) + throws IOException { String functionName = template.getBaseName().replace('.', '_') + "_as_string"; - String body = processHspBody(template.getContent()); + String body = processHspBody(template.getContent(encoding)); return composeFunction(functionName, "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", "res.pushStringBuffer(); " + body + diff --git a/src/helma/scripting/rhino/RhinoCore.java b/src/helma/scripting/rhino/RhinoCore.java index da185ccd..aabbd0c4 100644 --- a/src/helma/scripting/rhino/RhinoCore.java +++ b/src/helma/scripting/rhino/RhinoCore.java @@ -769,19 +769,23 @@ public final class RhinoCore implements ScopeProvider { Resource previousCurrentResource = app.getCurrentCodeResource(); app.setCurrentCodeResource(code); + String encoding = app.getProperty("sourceCharset"); + try { Scriptable op = type.objProto; // do the update, evaluating the file if (sourceName.endsWith(".js")) { - reader = new InputStreamReader(code.getInputStream()); + reader = encoding == null ? + new InputStreamReader(code.getInputStream()) : + new InputStreamReader(code.getInputStream(), encoding); cx.evaluateReader(op, reader, sourceName, 1, null); } else if (sourceName.endsWith(".hac")) { - reader = new StringReader(HacHspConverter.convertHac(code)); + reader = new StringReader(HacHspConverter.convertHac(code, encoding)); cx.evaluateReader(op, reader, sourceName, 0, null); } else if (sourceName.endsWith(".hsp")) { - reader = new StringReader(HacHspConverter.convertHsp(code)); + reader = new StringReader(HacHspConverter.convertHsp(code, encoding)); cx.evaluateReader(op, reader, sourceName, 0, null); - reader = new StringReader(HacHspConverter.convertHspAsString(code)); + reader = new StringReader(HacHspConverter.convertHspAsString(code, encoding)); cx.evaluateReader(op, reader, sourceName, 0, null); }