1 16 package org.apache.cocoon.components.flow.javascript; 17 18 import org.mozilla.javascript.ErrorReporter; 19 import org.mozilla.javascript.EvaluatorException; 20 import org.mozilla.javascript.tools.ToolErrorReporter; 21 import org.apache.avalon.framework.logger.Logger; 22 23 30 public class JSErrorReporter implements ErrorReporter 31 { 32 private Logger logger; 33 34 public JSErrorReporter(Logger logger) 35 { 36 this.logger = logger; 37 } 38 39 public void error(String message, 40 String sourceName, int line, 41 String lineSrc, int column) 42 { 43 String errMsg = getErrorMessage("msg.error", message, 44 sourceName, line, lineSrc, column); 45 System.err.println(errMsg); 46 logger.error(errMsg); 47 } 48 49 public void warning(String message, String sourceName, int line, 50 String lineSrc, int column) 51 { 52 String errMsg = getErrorMessage("msg.warning", message, 53 sourceName, line, lineSrc, column); 54 System.err.println(errMsg); 55 logger.warn(errMsg); 56 } 57 58 public EvaluatorException runtimeError(String message, String sourceName, 59 int line, String lineSrc, 60 int column) 61 { 62 String errMsg = getErrorMessage("msg.error", message, 63 sourceName, line, 64 lineSrc, column); 65 System.err.println(errMsg); 66 return new EvaluatorException(errMsg); 67 } 68 69 86 String getErrorMessage(String type, 87 String message, 88 String sourceName, int line, 89 String lineSource, int column) 90 { 91 if (line > 0) { 92 if (sourceName != null) { 93 Object [] errArgs = { sourceName, new Integer (line), message }; 94 return ToolErrorReporter.getMessage("msg.format3", errArgs); 95 } else { 96 Object [] errArgs = { new Integer (line), message }; 97 return ToolErrorReporter.getMessage("msg.format2", errArgs); 98 } 99 } else { 100 Object [] errArgs = { message }; 101 return ToolErrorReporter.getMessage("msg.format1", errArgs); 102 } 103 } 104 } 105 | Popular Tags |