if (checkComplex) {
Map<String, String> keys = p.getKeys();
for (CheckerData d : checkerData) {
if (d.match(p, keys)) {
errors.add( new TestError(this, d.getSeverity(), tr("Suspicious tag/value combinations"),
d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) );
withErrors.put(p, "TC");
}
}
}
for (Entry<String, String> prop : p.getKeys().entrySet()) {
String s = marktr("Key ''{0}'' invalid.");
String key = prop.getKey();
String value = prop.getValue();
if (checkValues && (containsLow(value)) && !withErrors.contains(p, "ICV")) {
errors.add( new TestError(this, Severity.WARNING, tr("Tag value contains character with code less than 0x20"),
tr(s, key), MessageFormat.format(s, key), LOW_CHAR_VALUE, p) );
withErrors.put(p, "ICV");
}
if (checkKeys && (containsLow(key)) && !withErrors.contains(p, "ICK")) {
errors.add( new TestError(this, Severity.WARNING, tr("Tag key contains character with code less than 0x20"),
tr(s, key), MessageFormat.format(s, key), LOW_CHAR_KEY, p) );
withErrors.put(p, "ICK");
}
if (checkValues && (value!=null && value.length() > 255) && !withErrors.contains(p, "LV")) {
errors.add( new TestError(this, Severity.ERROR, tr("Tag value longer than allowed"),
tr(s, key), MessageFormat.format(s, key), LONG_VALUE, p) );
withErrors.put(p, "LV");
}
if (checkKeys && (key!=null && key.length() > 255) && !withErrors.contains(p, "LK")) {
errors.add( new TestError(this, Severity.ERROR, tr("Tag key longer than allowed"),
tr(s, key), MessageFormat.format(s, key), LONG_KEY, p) );
withErrors.put(p, "LK");
}
if (checkValues && (value==null || value.trim().length() == 0) && !withErrors.contains(p, "EV")) {
errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"),
tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) );
withErrors.put(p, "EV");
}
if (checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) {
errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"),
tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) );
withErrors.put(p, "IPK");
}
if (checkKeys && key.indexOf(' ') >= 0 && !withErrors.contains(p, "IPK")) {
errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"),
tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) );
withErrors.put(p, "IPK");
}
if (checkValues && value != null && (value.startsWith(" ") || value.endsWith(" ")) && !withErrors.contains(p, "SPACE")) {
errors.add( new TestError(this, Severity.WARNING, tr("Property values start or end with white space"),
tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) );
withErrors.put(p, "SPACE");
}
if (checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"),
tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) );
withErrors.put(p, "HTML");
}
if (checkValues && value != null && value.length() > 0 && presetsValueData != null) {
final Set<String> values = presetsValueData.get(key);
final boolean keyInPresets = values != null;
final boolean tagInPresets = values != null && (values.isEmpty() || values.contains(prop.getValue()));
boolean ignore = false;
for (String a : ignoreDataStartsWith) {
if (key.startsWith(a)) {
ignore = true;
}
}
for (String a : ignoreDataEquals) {
if(key.equals(a)) {
ignore = true;
}
}
for (String a : ignoreDataEndsWith) {
if(key.endsWith(a)) {
ignore = true;
}
}
if (!tagInPresets) {
for (IgnoreKeyPair a : ignoreDataKeyPair) {
if (key.equals(a.key) && value.equals(a.value)) {
ignore = true;
}
}
}
if (!ignore) {
if (!keyInPresets) {
String i = marktr("Key ''{0}'' not in presets.");
errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property key"),
tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) );
withErrors.put(p, "UPK");
} else if (!tagInPresets) {
String i = marktr("Value ''{0}'' for key ''{1}'' not in presets.");
errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property value"),
tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) );
withErrors.put(p, "UPV");
}
}
}
if (checkFixmes && value != null && value.length() > 0) {
if ((value.toLowerCase().contains("fixme")
|| value.contains("check and delete")
|| key.contains("todo") || key.toLowerCase().contains("fixme"))
&& !withErrors.contains(p, "FIXME")) {
errors.add(new TestError(this, Severity.OTHER,
tr("FIXMES"), FIXME, p));
withErrors.put(p, "FIXME");
}
}
}