Map<AttribKey, HTML.Attribute.Type> atypes = attributeTypes(schema);
Map<ElKey, EnumSet<EFlag>> eflags = elementFlags(schema);
Map<AttribKey, UriEffect> uriEffects = uriEffects(schema);
Map<AttribKey, LoaderType> ltypes = loaderTypes(schema);
Block definitions = new Block();
definitions.appendChild(QuasiBuilder.substV("var html4 = {};"));
definitions.appendChild(mapFromEnum(
EnumSet.allOf(HTML.Attribute.Type.class),
"atype",
new Function<HTML.Attribute.Type, String>() {
public String apply(HTML.Attribute.Type f) {
return f.name();
}
},
new Function<HTML.Attribute.Type, Integer>() {
public Integer apply(HTML.Attribute.Type f) {
return A_TYPE_MAP.get(f);
}
})
);
{
List<StringLiteral> keys = new ArrayList<StringLiteral>();
List<IntegerLiteral> values = new ArrayList<IntegerLiteral>();
for (Map.Entry<AttribKey, HTML.Attribute.Type> e : atypes.entrySet()) {
AttribKey key = e.getKey();
if (ElKey.HTML_WILDCARD.equals(key.el)
|| schema.isElementAllowed(key.el)
// Whitelisted to allow dynamic script loading via proxy
|| SCRIPT_SRC.equals(key)) {
keys.add(StringLiteral.valueOf(unk, key.toString()));
values.add(new IntegerLiteral(unk, A_TYPE_MAP.get(e.getValue())));
}
}
definitions.appendChild(new ExpressionStmt(unk, (Expression)
QuasiBuilder.substV(
"html4.ATTRIBS = { @k*: @v* };",
"k", new ParseTreeNodeContainer(keys),
"v", new ParseTreeNodeContainer(values))));
}
definitions.appendChild(mapFromEnum(
EnumSet.allOf(EFlag.class),
"eflags",
new Function<EFlag, String>() {
public String apply(EFlag f) {
return f.name();
}
},
new Function<EFlag, Integer>() {
public Integer apply(EFlag f) {
return f.bitMask;
}
})
);
{
List<StringLiteral> keys = new ArrayList<StringLiteral>();
List<IntegerLiteral> values = new ArrayList<IntegerLiteral>();
for (Map.Entry<ElKey, EnumSet<EFlag>> e : eflags.entrySet()) {
ElKey key = e.getKey();
int value = 0;
for (EFlag f : e.getValue()) { value |= f.bitMask; }
keys.add(StringLiteral.valueOf(unk, key.toString()));
values.add(new IntegerLiteral(unk, value));
}
definitions.appendChild(new ExpressionStmt(unk, (Expression)
QuasiBuilder.substV(
"html4.ELEMENTS = { @k*: @v* };",
"k", new ParseTreeNodeContainer(keys),
"v", new ParseTreeNodeContainer(values))));
}
definitions.appendChild(mapFromEnum(
EnumSet.allOf(UriEffect.class),
"ueffects",
new Function<UriEffect, String>() {
public String apply(UriEffect f) {
return f.name();
}
},
new Function<UriEffect, Integer>() {
public Integer apply(UriEffect f) {
return A_UEFFECT_MAP.get(f);
}
})
);
definitions.appendChild(mapFromEnum(
uriEffects.entrySet(),
"URIEFFECTS",
new Function<Entry<AttribKey, UriEffect>, String>() {
public String apply(Entry<AttribKey, UriEffect> f) {
return f.getKey().toString();
}
},
new Function<Entry<AttribKey, UriEffect>, Integer>() {
public Integer apply(Entry<AttribKey, UriEffect> f) {
return A_UEFFECT_MAP.get(f.getValue());
}
})
);
definitions.appendChild(mapFromEnum(
EnumSet.allOf(LoaderType.class),
"ltypes",
new Function<LoaderType, String>() {
public String apply(LoaderType f) {
return f.name();
}
},
new Function<LoaderType, Integer>() {
public Integer apply(LoaderType f) {
return L_TYPE_MAP.get(f);
}
})
);
definitions.appendChild(mapFromEnum(
ltypes.entrySet(),
"LOADERTYPES",
new Function<Entry<AttribKey, LoaderType>, String>() {
public String apply(Entry<AttribKey, LoaderType> f) {
return f.getKey().toString();