1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.jsieve.exception.CommandException;
24 import org.apache.jsieve.exception.SyntaxException;
25
26
27
28
29
30
31 public final class ScriptCoordinate {
32
33 private final int startLineNumber;
34
35 private final int startColumnNumber;
36
37 private final int endLineNumber;
38
39 private final int endColumnNumber;
40
41 private Log log;
42
43 public ScriptCoordinate(final int startLineNumber,
44 final int startColumnNumber, final int endLineNumber,
45 final int endColumnNumber) {
46 super();
47 this.startLineNumber = startLineNumber;
48 this.startColumnNumber = startColumnNumber;
49 this.endLineNumber = endLineNumber;
50 this.endColumnNumber = endColumnNumber;
51 }
52
53 public Log getLog() {
54 return log;
55 }
56
57 public void setLog(Log logger) {
58 this.log = logger;
59 }
60
61
62
63
64
65
66 public int getEndColumnNumber() {
67 return endColumnNumber;
68 }
69
70
71
72
73
74
75 public int getEndLineNumber() {
76 return endLineNumber;
77 }
78
79
80
81
82
83
84 public int getStartColumnNumber() {
85 return startColumnNumber;
86 }
87
88
89
90
91
92
93 public int getStartLineNumber() {
94 return startLineNumber;
95 }
96
97
98
99
100
101
102
103
104
105
106
107 public SyntaxException syntaxException(CharSequence message) {
108 if (log != null) {
109 if (log.isWarnEnabled()) {
110 log.warn(message);
111 }
112 logDiagnosticsInfo(log);
113 }
114 final String fullMessage = addStartLineAndColumn(message);
115 final SyntaxException result = new SyntaxException(fullMessage);
116 return result;
117 }
118
119
120
121
122
123
124
125
126
127
128
129 public CommandException commandException(CharSequence message) {
130 if (log != null) {
131 if (log.isWarnEnabled()) {
132 log.warn(message);
133 }
134 logDiagnosticsInfo(log);
135 }
136 final String fullMessage = addStartLineAndColumn(message);
137 final CommandException result = new CommandException(fullMessage);
138 return result;
139 }
140
141
142
143
144
145
146
147
148
149
150 public String addStartLineAndColumn(CharSequence message) {
151 final StringBuilder buffer;
152 if (message instanceof StringBuilder) {
153 buffer = (StringBuilder) message;
154 } else {
155 buffer = new StringBuilder(message.toString());
156 }
157 buffer.append(" Line ");
158 buffer.append(startLineNumber);
159 buffer.append(" column ");
160 buffer.append(startColumnNumber);
161 buffer.append(".");
162 return buffer.toString();
163 }
164
165
166
167
168
169
170
171 public void logDiagnosticsInfo(Log logger) {
172 if (logger.isInfoEnabled()) {
173 logger.info("Expression starts line " + startLineNumber
174 + " column " + startColumnNumber);
175 logger.info("Expression ends line " + endLineNumber + " column "
176 + endColumnNumber);
177 }
178 }
179
180
181
182
183
184
185
186 public void debugDiagnostics(Log logger) {
187 if (logger.isDebugEnabled()) {
188 logger.debug("Expression starts line " + startLineNumber
189 + " column " + startColumnNumber);
190 logger.debug("Expression ends line " + endLineNumber + " column "
191 + endColumnNumber);
192 }
193 }
194 }