public void createMarkers(IFile file, IDocument document) throws CoreException {
file.deleteMarkers(MARKER_ID, true, IResource.DEPTH_ZERO);
if (_provider != null && _provider instanceof FileDocumentProvider) {
String encoding = file.getCharset(true);
LineNumberReader read = null;
try {
read = new LineNumberReader(new InputStreamReader(new FileInputStream(file.getLocation().toFile()), encoding));
String line;
while ((line = read.readLine()) != null) {
boolean invalidCharsFound = false;
Map<String,Object> attributes = new HashMap<String, Object>();
List<Character> invalidCharsInLine = new ArrayList<Character>();
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
if (!Character.isLetterOrDigit(c) &&
!Character.isWhitespace(c) &&
!CURRENCY_SYMBOLS.contains(c) &&
ALLOWED_NONALPHANUMERIC.indexOf(c) == -1) {
invalidCharsFound = true;
invalidCharsInLine.add(c);
}
}
if (invalidCharsFound) {
// create marker
try {
IRegion lineInfo = document.getLineInformation(read.getLineNumber() - 1);
String lineContent = document.get(lineInfo.getOffset(), lineInfo.getLength());
int beginningSpaces = 0;
for (int i = 0; i < lineContent.length(); i++) {
char c = lineContent.charAt(i);
if (Character.isWhitespace(c)) {
beginningSpaces++;
} else {
break;
}
}
int trailingSpaces = 0;
for (int i = lineContent.length() - 1; i >= 0; i--) {
char c = lineContent.charAt(i);
if (Character.isWhitespace(c)) {
trailingSpaces++;
} else {
break;
}
}
int charStart = lineInfo.getOffset() + beginningSpaces;
int charEnd = charStart + lineInfo.getLength() - beginningSpaces - trailingSpaces;
Map<String,Object> map = new HashMap<String,Object>();
MarkerUtilities.setLineNumber(map, read.getLineNumber()-1);
MarkerUtilities.setCharStart(map, charStart);
MarkerUtilities.setCharEnd(map, charEnd);
MarkerUtilities.setMessage(map, "Invalid characters found '" + WGUtils.serializeCollection(invalidCharsInLine, ",") + "' .");
map.put(IMarker.LOCATION, file.getFullPath().toString());
map.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
if (attributes != null) {
map.putAll(attributes);
}
MarkerUtilities.createMarker(file, map, MARKER_ID);
} catch (BadLocationException e) {
}
}
}
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
} finally {
if (read != null) {
try {
read.close();
} catch (IOException e) {
}
}
}
}