* @throws PropertyException For an invalid property value.
*/
private PropertyValue createPropertyValue(final FObj fobj,
final String propertyFullName, final String value)
throws PropertyException {
final PropertyCollection collection = new PropertyCollection();
final PropertyValue pv = checkKeywords(this.getValidKeywords(), value);
if (pv != null) {
collection.addItem(new PdBackgroundColor(pv));
collection.addItem(new PdBackgroundImage(pv));
collection.addItem(new PdBackgroundRepeat(pv));
collection.addItem(new PdBackgroundAttachment(pv));
collection.addItem(new PdBackgroundPosition(pv));
return collection;
}
// There are 5 properties supported, one of which can have 2 tokens
final byte maxTokens = 6;
// Tokenize the input & put the tokens into an ArrayList
final StringTokenizer st = new StringTokenizer(value);
if (st.countTokens() < 1 || st.countTokens() > maxTokens) {
throw unexpectedValue(value, fobj);
}
final List<String> tokenList = new ArrayList<String>(st.countTokens());
while (st.hasMoreTokens()) {
tokenList.add(st.nextToken());
}
// Create an array indicating which property is in each position
final FoProperty[] positionArray = new FoProperty[tokenList.size()];
for (int i = 0; i < tokenList.size(); i++) {
final FoProperty contentType = getContentType(tokenList.get(i));
if (contentType == null) {
throw unexpectedValue(value, fobj);
}
positionArray[i] = contentType;
}
boolean colorFound = false;
boolean imageFound = false;
boolean repeatFound = false;
boolean attachmentFound = false;
boolean positionFound = false;
for (int i = 0; i < positionArray.length; i++) {
switch (positionArray[i]) {
case BACKGROUND_COLOR: {
if (colorFound) {
throw unexpectedValue(value, fobj);
}
collection.addItem(new PdBackgroundColor(fobj,
propertyFullName, tokenList.get(i)));
colorFound = true;
break;
}
case BACKGROUND_IMAGE: {
if (imageFound) {
throw unexpectedValue(value, fobj);
}
collection.addItem(new PdBackgroundImage(fobj,
propertyFullName, tokenList.get(i)));
imageFound = true;
break;
}
case BACKGROUND_REPEAT: {
if (repeatFound) {
throw unexpectedValue(value, fobj);
}
collection.addItem(new PdBackgroundRepeat(fobj,
propertyFullName, tokenList.get(i)));
repeatFound = true;
break;
}
case BACKGROUND_ATTACHMENT: {
if (attachmentFound) {
throw unexpectedValue(value, fobj);
}
collection.addItem(new PdBackgroundAttachment(fobj,
propertyFullName, tokenList.get(i)));
attachmentFound = true;
break;
}
case BACKGROUND_POSITION: {
if (positionFound) {
throw unexpectedValue(value, fobj);
}
final String propertyInput = tokenList.get(i);
if (i < positionArray.length && positionArray[i + 1]
== FoProperty.BACKGROUND_POSITION) {
propertyInput.concat(" " + tokenList.get(i + 1));
i++;
}
collection.addItem(new PdBackgroundPosition(fobj,
propertyFullName, tokenList.get(i)));
positionFound = true;
break;
}
}