cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r292782 - /cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
Date Fri, 30 Sep 2005 15:47:52 GMT
Author: sylvain
Date: Fri Sep 30 08:47:50 2005
New Revision: 292782

URL: http://svn.apache.org/viewcvs?rev=292782&view=rev
Log:
Rhino 1.5 calls error reporter several times, so buffer all messages

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java?rev=292782&r1=292781&r2=292782&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/JSErrorReporter.java
Fri Sep 30 08:47:50 2005
@@ -19,22 +19,39 @@
 import org.mozilla.javascript.EvaluatorException;
 import org.mozilla.javascript.tools.ToolErrorReporter;
 import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.util.location.LocatedRuntimeException;
+import org.apache.cocoon.util.location.Location;
+import org.apache.cocoon.util.location.LocationImpl;
 
 /**
  * Implements a Rhino JavaScript {@link
  * org.mozilla.javascript.ErrorReporter}. 
  * Like ToolErrorReporter but logs to supplied logger instead of stdout
  *
- * @version CVS $Id: JSErrorReporter.java,v 1.6 2004/03/06 02:25:40 antonio Exp $
+ * @version CVS $Id$
  */
 public class JSErrorReporter implements ErrorReporter
 {
   private Logger logger;
+  private Location location;
+  private StringBuffer message;
 
   public JSErrorReporter(Logger logger)
   {
       this.logger = logger;
   }
+  
+  private void appendMessage(String text, String sourceName, int line, int column) {
+      if (location == null) {
+          location = new LocationImpl(null, sourceName, line, column);
+          message = new StringBuffer();
+      } else {
+          // Append a linefeed
+          message.append("\n");
+      }
+      
+      message.append(text);
+  }
 
   public void error(String message,
                     String sourceName, int line,
@@ -42,6 +59,7 @@
   {
       String errMsg = getErrorMessage("msg.error", message, 
                                       sourceName, line, lineSrc, column);
+      appendMessage(errMsg, sourceName, line, column);
       System.err.println(errMsg);
       logger.error(errMsg);
   }
@@ -51,6 +69,7 @@
   {
       String errMsg = getErrorMessage("msg.warning", message, 
                                     sourceName, line, lineSrc, column);
+      appendMessage(errMsg, sourceName, line, column);
       System.err.println(errMsg);
       logger.warn(errMsg);
   }
@@ -62,8 +81,10 @@
       String errMsg = getErrorMessage("msg.error", message,
                                       sourceName, line,
                                       lineSrc, column);
+      appendMessage(errMsg, sourceName, line, column);
       System.err.println(errMsg);
-      return new EvaluatorException(errMsg);
+      // FIXME(SW): need to build a locatable extension to EvaluatorException
+      return new EvaluatorException(this.message.toString());
   }
 
   /**



Mime
View raw message