1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.peaseplate.internal;
21
22 import org.peaseplate.TemplateException;
23 import org.peaseplate.locator.TemplateLocator;
24
25
26
27
28
29
30
31
32 public abstract class AbstractLocatedTemplateException extends TemplateException {
33
34 private static final long serialVersionUID = 1L;
35 private static final String LINE_SEPARATOR = System.getProperty("line.separator");
36
37 private final TemplateLocator locator;
38 private final int line;
39 private final int column;
40
41
42
43
44
45
46
47
48 public AbstractLocatedTemplateException(TemplateLocator locator, int line, int column, String message) {
49 this(locator, line, column, message, null);
50 }
51
52
53
54
55
56
57
58
59
60
61 public AbstractLocatedTemplateException(TemplateLocator locator, int line, int column, String message, Throwable cause) {
62 super(addHighlight(locator, message, line, column), cause);
63
64 this.locator = locator;
65 this.line = line;
66 this.column = column;
67 }
68
69
70
71
72
73 public TemplateLocator getLocator() {
74 return locator;
75 }
76
77
78
79
80
81 public int getLine() {
82 return line;
83 }
84
85
86
87
88
89 public int getColumn() {
90 return column;
91 }
92
93 private static String addHighlight(TemplateLocator locator, String message, int line, int column) {
94 StringBuilder builder = new StringBuilder(message);
95
96 if (locator != null) {
97 String highlight = locator.highlight(message, line, column);
98
99 if (highlight != null) {
100 builder.append(LINE_SEPARATOR).append(LINE_SEPARATOR);
101 builder.append(locator).append(" [").append(line).append(", ").append(column).append("]:").append(LINE_SEPARATOR);
102 builder.append(highlight);
103 }
104 else {
105 builder.append(" (").append(locator).append(" [").append(line).append(", ").append(column).append("])");
106 }
107 }
108
109 return builder.toString();
110 }
111
112 }