Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit warnings for use of rel={copyright,previous} #485

Merged
merged 2 commits into from Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/nu/validator/datatype/ARel.java
Expand Up @@ -25,8 +25,11 @@
import nu.validator.datatype.tools.RegisteredRelValuesBuilder;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import org.relaxng.datatype.DatatypeException;
import org.xml.sax.SAXException;

public final class ARel extends AbstractRel {
Expand Down Expand Up @@ -68,8 +71,19 @@ private ARel() {
super();
}

private final static boolean WARN = System.getProperty(
"nu.validator.datatype.warn", "").equals("true");

@Override
protected boolean isRegistered(CharSequence literal, String token) {
protected boolean isRegistered(CharSequence literal, String token)
throws DatatypeException {
if (WARN) {
// Synonyms for current keywords
Map<String, String> map = new HashMap<>();
map.put("copyright", "license");
map.put("previous", "prev");
errSynonym(token, map);
}
return registeredValues.contains(token.toLowerCase());
}

Expand Down
17 changes: 17 additions & 0 deletions src/nu/validator/datatype/AbstractRel.java
Expand Up @@ -26,6 +26,9 @@
import java.util.Set;
import java.util.regex.Pattern;

import java.util.HashMap;
import java.util.Map;

import org.relaxng.datatype.DatatypeException;

abstract class AbstractRel extends AbstractDatatype {
Expand Down Expand Up @@ -74,6 +77,20 @@ private void checkToken(CharSequence literal, StringBuilder builder, int i,
}
}

protected void errSynonym(String token, Map<String, String> map)
throws DatatypeException {
// Synonyms for current keywords
for (Map.Entry m : map.entrySet()) {
if (token.toLowerCase().equals(m.getKey())) {
throw newDatatypeException("The keyword \u201c" + m.getKey()
+ "\u201d for the \u201crel\u201d"
+ " attribute should not be used."
+ " Consider using \u201c" + m.getValue()
+ "\u201d instead.", true);
}
}
}

private void errNotRegistered(int position, String token)
throws DatatypeException {
throw newDatatypeException(position, "The string ", token,
Expand Down
12 changes: 12 additions & 0 deletions src/nu/validator/datatype/LinkRel.java
Expand Up @@ -25,7 +25,9 @@
import nu.validator.datatype.tools.RegisteredRelValuesBuilder;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import org.relaxng.datatype.DatatypeException;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -71,6 +73,9 @@ private LinkRel() {
super();
}

private final static boolean WARN = System.getProperty(
"nu.validator.datatype.warn", "").equals("true");

@Override
protected boolean isRegistered(CharSequence literal, String token)
throws DatatypeException {
Expand All @@ -84,6 +89,13 @@ protected boolean isRegistered(CharSequence literal, String token)
+ " \u201cshortcut icon\u201d.");
}
} else {
if (WARN) {
// Synonyms for current keywords
Map<String, String> map = new HashMap<>();
map.put("copyright", "license");
map.put("previous", "prev");
errSynonym(token, map);
}
return registeredValues.contains(token.toLowerCase());
}
}
Expand Down