01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TemplateException.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.template.exceptions;
09:
10: import com.uwyn.rife.datastructures.DocumentPosition;
11: import com.uwyn.rife.tools.StringUtils;
12:
13: public class TemplateException extends RuntimeException {
14: private static final long serialVersionUID = 8643896354837543058L;
15:
16: public TemplateException(String message) {
17: super (message);
18: }
19:
20: public TemplateException(String message, Throwable cause) {
21: super (message, cause);
22: }
23:
24: public static String formatError(String name,
25: DocumentPosition errorLocation, String message) {
26: String without_tabs = StringUtils.stripFromFront(errorLocation
27: .getLineContent(), "\t");
28: int removed_tab_count = errorLocation.getLineContent().length()
29: - without_tabs.length();
30:
31: return "\n"
32: + name
33: + ":"
34: + errorLocation.getLine()
35: + ":"
36: + errorLocation.getColumn()
37: + ": "
38: + message
39: + "\n"
40: + StringUtils.repeat(" ", removed_tab_count)
41: + without_tabs
42: + "\n"
43: + StringUtils.repeat(" ", removed_tab_count)
44: + StringUtils
45: .repeat(" ", errorLocation.getColumn() - 1)
46: + "^\n";
47: }
48: }
|