}
public HtmlSchema(WhiteList tagList, WhiteList attribList) {
this.allowedAttributes = Sets.newHashSet();
for (String key : attribList.allowedItems()) {
AttribKey attribKey = attribKey(key);
allowedAttributes.add(attribKey);
}
Map<AttribKey, RegularCriterion> criteria = Maps.newHashMap();
for (WhiteList.TypeDefinition def : attribList.typeDefinitions().values()) {
final String values = (String) def.get("values", null);
RegularCriterion criterion = null;
if (values != null) {
criterion = RegularCriterion.Factory.fromValueSet(
Arrays.asList(values.split(",")));
} else {
String pattern = (String) def.get("pattern", null);
if (pattern != null) {
criterion = RegularCriterion.Factory.fromPattern(
"(?i:" + pattern + ")");
}
}
if (criterion != null) {
String key = Strings.lower((String) def.get("key", null));
criteria.put(attribKey(key), criterion);
}
}
this.attributeDetails = Maps.newHashMap();
Multimap<ElKey, HTML.Attribute> attributeDetailsByElement
= Multimaps.newListHashMultimap();
for (WhiteList.TypeDefinition def : attribList.typeDefinitions().values()) {
String key = Strings.lower((String) def.get("key", null));
AttribKey elAndAttrib = attribKey(key);
if (elAndAttrib == null) { throw new NullPointerException(key); }
ElKey element = elAndAttrib.el;
HTML.Attribute.Type type = HTML.Attribute.Type.NONE;
String typeName = (String) def.get("type", null);
if (typeName != null) {
// TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
type = HTML.Attribute.Type.valueOf(typeName);
}
String loaderTypeStr = (String) def.get("loaderType", null);
// TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
LoaderType loaderType = loaderTypeStr != null
? LoaderType.valueOf(loaderTypeStr) : null;
String uriEffectStr = (String) def.get("uriEffect", null);
// TODO(mikesamuel): divert IllegalArgumentExceptions to MessageQueue
UriEffect uriEffect = uriEffectStr != null
? UriEffect.valueOf(uriEffectStr) : null;
RegularCriterion elCriterion = criteria.get(elAndAttrib);
RegularCriterion wcCriterion = criteria.get(elAndAttrib.onAnyElement());
RegularCriterion criterion = conjunction(elCriterion, wcCriterion);
String defaultValue = (String) def.get("default", null);
boolean optional = Boolean.TRUE.equals(def.get("optional", true));
String safeValue = (String) def.get("safeValue", null);
if (safeValue == null) {