public class ContentPropertyBuilder extends AbstractPropertyBuilder {
public List buildDeclarations(
CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) {
if (values.size() == 1) {
PropertyValue value = (PropertyValue)values.get(0);
if (value.getCssValueType() == CSSValue.CSS_INHERIT) {
return Collections.EMPTY_LIST;
} else if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
IdentValue ident = checkIdent(CSSName.CONTENT, value);
if (ident == IdentValue.NONE || ident == IdentValue.NORMAL) {
return Collections.singletonList(
new PropertyDeclaration(CSSName.CONTENT, value, important, origin));
}
}
}
List resultValues = new ArrayList();
for (Iterator i = values.iterator(); i.hasNext(); ) {
PropertyValue value = (PropertyValue)i.next();
if (value.getOperator() != null) {
throw new CSSParseException(
"Found unexpected operator, " + value.getOperator().getExternalName(), -1);
}
short type = value.getPrimitiveType();
if (type == CSSPrimitiveValue.CSS_URI) {
continue;
} else if (type == CSSPrimitiveValue.CSS_STRING) {
resultValues.add(value);
} else if (value.getPropertyValueType() == PropertyValue.VALUE_TYPE_FUNCTION) {
if (! isFunctionAllowed(value.getFunction())) {
throw new CSSParseException(
"Function " + value.getFunction().getName() + " is not allowed here", -1);
}
resultValues.add(value);
} else if (type == CSSPrimitiveValue.CSS_IDENT) {
IdentValue ident = checkIdent(CSSName.CONTENT, value);
if (ident == IdentValue.OPEN_QUOTE || ident == IdentValue.CLOSE_QUOTE ||
ident == IdentValue.NO_CLOSE_QUOTE || ident == IdentValue.NO_OPEN_QUOTE) {
throw new CSSParseException("The quotes property is not implemented", -1);
} else {
throw new CSSParseException(
"Identifier " + ident + " is not a valid value for the content property", -1);
}
} else {
throw new CSSParseException(
value.getCssText() + " is not a value value for the content property", -1);
}
}
if (resultValues.size() > 0) {
return Collections.singletonList(
new PropertyDeclaration(CSSName.CONTENT, new PropertyValue(resultValues), important, origin));
} else {
return Collections.EMPTY_LIST;
}
}