LexicalUnit parameters = unit.getParameters();
String functionName = unit.getFunctionName();
if (parameters == null)
{
// no-parameter function include the date() function...
return new CSSFunctionValue(functionName, EMPTY_PARAMETERS);
}
if ("attr".equalsIgnoreCase(functionName))
{
return parseComplexAttrFn(unit.getParameters());
}
if ("color".equalsIgnoreCase(functionName))
{
// for some strange reason, flute translates "rgb" functions into "color" functions which
// are not even mentioned in the CSS specs. We therefore translate it back into RGB.
functionName = "rgb";
}
final ArrayList contentList = new ArrayList();
while (parameters != null)
{
if (parameters.getLexicalUnitType() == LexicalUnit.SAC_IDENT)
{
contentList.add(new CSSConstant(parameters.getStringValue()));
}
else if (parameters.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE)
{
contentList.add(new CSSStringValue(CSSStringType.STRING,
parameters.getStringValue()));
}
else if (CSSValueFactory.isNumericValue(parameters))
{
final CSSNumericValue numericValue =
CSSValueFactory.createNumericValue(parameters);
if (numericValue == null)
{
return null;
}
contentList.add(numericValue);
}
else if (CSSValueFactory.isLengthValue(parameters))
{
final CSSNumericValue lengthValue =
CSSValueFactory.createLengthValue(parameters);
if (lengthValue == null)
{
return null;
}
contentList.add(lengthValue);
}
else if (parameters.getLexicalUnitType() == LexicalUnit.SAC_ATTR)
{
final CSSAttrFunction attrFn =
CSSValueFactory.parseAttrFunction(parameters);
if (attrFn == null)
{
return null;
}
contentList.add(attrFn);
}
else if (parameters.getLexicalUnitType() == LexicalUnit.SAC_URI)
{
final CSSStringValue uriValue = CSSValueFactory.createUriValue(
parameters);
if (uriValue == null)
{
return null;
}
contentList.add(uriValue);
}
else if (isFunctionValue(parameters))
{
final CSSFunctionValue functionValue = parseFunction(parameters);
if (functionValue == null)
{
return null;
}
contentList.add(functionValue);
}
else
{
// parse error: Something we do not understand ...
return null;
}
parameters = CSSValueFactory.parseComma(parameters);
}
final CSSValue[] paramVals = (CSSValue[])
contentList.toArray(new CSSValue[contentList.size()]);
return new CSSFunctionValue(functionName, paramVals);
}