coliver 2003/03/16 16:38:39
Modified: src/java/org/apache/cocoon/components/flow/javascript
JSCocoon.java JSErrorReporter.java
JavaScriptInterpreter.java
Log:
removed tabs
Revision Changes Path
1.6 +2 -2
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java
Index: JSCocoon.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JSCocoon.java 17 Mar 2003 00:32:35 -0000 1.5
+++ JSCocoon.java 17 Mar 2003 00:38:39 -0000 1.6
@@ -198,7 +198,7 @@
org.mozilla.javascript.Context cx =
org.mozilla.javascript.Context.getCurrentContext();
try {
- Scriptable scope = getParentScope();
+ Scriptable scope = getParentScope();
Script script = interpreter.compileScript(cx, scope, environment,
filename);
return script.exec(cx, scope);
} catch (JavaScriptException e) {
1.5 +16 -16
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
Index: JSErrorReporter.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JSErrorReporter.java 17 Mar 2003 00:32:35 -0000 1.4
+++ JSErrorReporter.java 17 Mar 2003 00:38:39 -0000 1.5
@@ -26,16 +26,16 @@
String lineSrc, int column)
{
String errMsg = getErrorMessage("msg.error", message,
- sourceName, line, lineSrc, column);
+ sourceName, line, lineSrc, column);
System.err.println(errMsg);
logger.error(errMsg);
}
public void warning(String message, String sourceName, int line,
- String lineSrc, int column)
+ String lineSrc, int column)
{
String errMsg = getErrorMessage("msg.warning", message,
- sourceName, line, lineSrc, column);
+ sourceName, line, lineSrc, column);
System.err.println(errMsg);
logger.warn(errMsg);
}
@@ -45,8 +45,8 @@
int column)
{
String errMsg = getErrorMessage("msg.error", message,
- sourceName, line,
- lineSrc, column);
+ sourceName, line,
+ lineSrc, column);
System.err.println(errMsg);
return new EvaluatorException(errMsg);
}
@@ -69,17 +69,17 @@
* real values
*/
String getErrorMessage(String type,
- String message,
- String sourceName, int line,
- String lineSource, int column)
+ String message,
+ String sourceName, int line,
+ String lineSource, int column)
{
- if (line > 0) {
- if (sourceName != null) {
- Object[] errArgs = { sourceName, new Integer(line), message };
- return ToolErrorReporter.getMessage("msg.format3", errArgs);
- } else {
- Object[] errArgs = { new Integer(line), message };
- return ToolErrorReporter.getMessage("msg.format2", errArgs);
+ if (line > 0) {
+ if (sourceName != null) {
+ Object[] errArgs = { sourceName, new Integer(line), message };
+ return ToolErrorReporter.getMessage("msg.format3", errArgs);
+ } else {
+ Object[] errArgs = { new Integer(line), message };
+ return ToolErrorReporter.getMessage("msg.format2", errArgs);
}
} else {
Object[] errArgs = { message };
1.5 +95 -95
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
Index: JavaScriptInterpreter.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JavaScriptInterpreter.java 17 Mar 2003 00:32:35 -0000 1.4
+++ JavaScriptInterpreter.java 17 Mar 2003 00:38:39 -0000 1.5
@@ -122,36 +122,36 @@
List topLevelScripts = new ArrayList();
class ScriptSourceEntry {
- final private Source source;
- private Script script;
- private long compileTime;
-
- public ScriptSourceEntry(Source source) {
- this.source = source;
- }
-
- public ScriptSourceEntry(Source source, Script script, long t) {
- this.source = source;
- this.script = script;
- this.compileTime = t;
- }
-
- public Source getSource() {
- return source;
- }
-
- public Script getScript(Context context, Scriptable scope,
- boolean refresh)
- throws Exception {
- if (refresh) {
- source.refresh();
- }
- if (script == null || compileTime < source.getLastModified()) {
- script = compileScript(context, scope, source);
- compileTime = source.getLastModified();
- }
- return script;
- }
+ final private Source source;
+ private Script script;
+ private long compileTime;
+
+ public ScriptSourceEntry(Source source) {
+ this.source = source;
+ }
+
+ public ScriptSourceEntry(Source source, Script script, long t) {
+ this.source = source;
+ this.script = script;
+ this.compileTime = t;
+ }
+
+ public Source getSource() {
+ return source;
+ }
+
+ public Script getScript(Context context, Scriptable scope,
+ boolean refresh)
+ throws Exception {
+ if (refresh) {
+ source.refresh();
+ }
+ if (script == null || compileTime < source.getLastModified()) {
+ script = compileScript(context, scope, source);
+ compileTime = source.getLastModified();
+ }
+ return script;
+ }
}
/**
* Mapping of String objects (source uri's) to ScriptSourceEntry's
@@ -364,11 +364,11 @@
// The Cocoon object exported to JavaScript needs to be setup here
JSCocoon cocoon;
- boolean newScope = false;
- long lastExecTime = 0;
+ boolean newScope = false;
+ long lastExecTime = 0;
if (thrScope == null) {
- newScope = true;
+ newScope = true;
thrScope = context.newObject(scope);
@@ -386,60 +386,60 @@
cocoon.setInterpreter(this);
cocoon.setParentScope(thrScope);
thrScope.put("cocoon", thrScope, cocoon);
- ((ScriptableObject)thrScope).defineProperty(LAST_EXEC_TIME,
- new Long(0),
- ScriptableObject.DONTENUM |
- ScriptableObject.PERMANENT);
+ ((ScriptableObject)thrScope).defineProperty(LAST_EXEC_TIME,
+ new Long(0),
+ ScriptableObject.DONTENUM |
+ ScriptableObject.PERMANENT);
} else {
cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
- lastExecTime = ((Long)thrScope.get(LAST_EXEC_TIME,
- thrScope)).longValue();
+ lastExecTime = ((Long)thrScope.get(LAST_EXEC_TIME,
+ thrScope)).longValue();
}
// We need to setup the JSCocoon object according to the current
// request. Everything else remains the same.
cocoon.setContext(manager, environment);
- // Check if we need to compile and/or execute scripts
- List execList = new ArrayList();
- boolean needsRefresh = false;
- synchronized (this) {
- if (reloadScripts) {
- long now = System.currentTimeMillis();
- if (now >= lastTimeCheck + checkTime) {
- needsRefresh = true;
- }
- lastTimeCheck = now;
- }
- if (needsRefresh || needResolve.size() > 0) {
- topLevelScripts.addAll(needResolve);
- if (!newScope && !needsRefresh) {
- execList.addAll(needResolve);
- } else {
- execList.addAll(topLevelScripts);
- }
- needResolve.clear();
- }
- }
- thrScope.put(LAST_EXEC_TIME, thrScope,
- new Long(System.currentTimeMillis()));
- for (int i = 0; i < execList.size(); i++) {
- String sourceURI = (String)execList.get(i);
- ScriptSourceEntry entry =
- (ScriptSourceEntry)compiledScripts.get(sourceURI);
- if (entry == null) {
- Source src = environment.resolveURI(sourceURI);
- entry = new ScriptSourceEntry(src);
- compiledScripts.put(sourceURI, entry);
- }
- // Compile the script if necessary
- Script script = entry.getScript(context, thrScope, needsRefresh);
- long lastMod = entry.getSource().getLastModified();
- // Execute the script if necessary
- if (lastExecTime == 0 || lastMod > lastExecTime) {
- script.exec(context, thrScope);
- }
+ // Check if we need to compile and/or execute scripts
+ List execList = new ArrayList();
+ boolean needsRefresh = false;
+ synchronized (this) {
+ if (reloadScripts) {
+ long now = System.currentTimeMillis();
+ if (now >= lastTimeCheck + checkTime) {
+ needsRefresh = true;
+ }
+ lastTimeCheck = now;
+ }
+ if (needsRefresh || needResolve.size() > 0) {
+ topLevelScripts.addAll(needResolve);
+ if (!newScope && !needsRefresh) {
+ execList.addAll(needResolve);
+ } else {
+ execList.addAll(topLevelScripts);
+ }
+ needResolve.clear();
+ }
+ }
+ thrScope.put(LAST_EXEC_TIME, thrScope,
+ new Long(System.currentTimeMillis()));
+ for (int i = 0; i < execList.size(); i++) {
+ String sourceURI = (String)execList.get(i);
+ ScriptSourceEntry entry =
+ (ScriptSourceEntry)compiledScripts.get(sourceURI);
+ if (entry == null) {
+ Source src = environment.resolveURI(sourceURI);
+ entry = new ScriptSourceEntry(src);
+ compiledScripts.put(sourceURI, entry);
+ }
+ // Compile the script if necessary
+ Script script = entry.getScript(context, thrScope, needsRefresh);
+ long lastMod = entry.getSource().getLastModified();
+ // Execute the script if necessary
+ if (lastExecTime == 0 || lastMod > lastExecTime) {
+ script.exec(context, thrScope);
+ }
}
return thrScope;
}
@@ -469,32 +469,32 @@
*/
public Script compileScript(Context cx,
- Scriptable scope,
+ Scriptable scope,
Environment environment,
String fileName) throws Exception {
Source src = environment.resolveURI(fileName);
if (src == null) {
throw new ResourceNotFoundException(fileName + ": not found");
}
- ScriptSourceEntry entry =
- (ScriptSourceEntry)compiledScripts.get(src.getURI());
- Script compiledScript = null;
- if (entry == null) {
- compiledScripts.put(src.getURI(),
- entry = new ScriptSourceEntry(src));
- }
- compiledScript = entry.getScript(cx, this.scope, false);
- return compiledScript;
+ ScriptSourceEntry entry =
+ (ScriptSourceEntry)compiledScripts.get(src.getURI());
+ Script compiledScript = null;
+ if (entry == null) {
+ compiledScripts.put(src.getURI(),
+ entry = new ScriptSourceEntry(src));
+ }
+ compiledScript = entry.getScript(cx, this.scope, false);
+ return compiledScript;
}
private Script compileScript(Context cx, Scriptable scope,
- Source src) throws Exception {
+ Source src) throws Exception {
InputStream is = src.getInputStream();
Reader reader = new BufferedReader(new InputStreamReader(is));
Script compiledScript = cx.compileReader(this.scope, reader,
src.getURI(),
1, null);
- return compiledScript;
+ return compiledScript;
}
/**
@@ -534,21 +534,21 @@
for (int i = 0; i < size; i++) {
Interpreter.Argument arg = (Interpreter.Argument)params.get(i);
funArgs[i] = arg.value;
- if (arg.name == null) arg.name = "";
+ if (arg.name == null) arg.name = "";
parameters.put(arg.name, parameters, arg.value);
}
}
cocoon.setParameters(parameters);
NativeArray funArgsArray = new NativeArray(funArgs);
- Object fun = ScriptableObject.getProperty(thrScope, funName);
+ Object fun = ScriptableObject.getProperty(thrScope, funName);
if (fun == Scriptable.NOT_FOUND) {
fun = "funName";
- }
+ }
Object callFunArgs[] = { fun, funArgsArray };
Object callFun = ScriptableObject.getProperty(thrScope, "callFunction");
if (callFun == Scriptable.NOT_FOUND) {
callFun = "callFunction";
- }
+ }
ScriptRuntime.call(context, callFun, thrScope, callFunArgs, thrScope);
}
catch (JavaScriptException ex) {