int n = attributes.size();
StringBuffer buf = new StringBuffer();
buf.append("<");
String tagName = null;
for (int i = 0; i < n; ++i){
Attribute attribute = attributes.elementAt(i);
if (i == 0) {
tagName = attribute.getName();
} else if (isLocalizableAttribute(tagName, attribute)) {
attribute.getName(buf);
attribute.getAssignment(buf);
char quote = attribute.getQuote();
if (quote != 0) {
buf.append(quote);
}
if (buf.length() > 0) {
result.add(ctx.createNonlocalizableTextFragment(buf.toString()));
}
result.add(ctx.createTextFragment(attribute.getValue()));
buf = new StringBuffer();
if (quote != 0) {
buf.append(quote);
}
continue;
}
attribute.toString(buf);
}
buf.append(">");
result.add(ctx.createNonlocalizableTextFragment(buf.toString()));
}
/**
* Check if a particular attribute contains localizable content.
*
* @param tagName
* @param attribute
* @return true if the attribute's value is localizable, false otherwise
*/
private boolean isLocalizableAttribute(String tagName, Attribute attribute) {
if (!attribute.isValued()) {
return false;
}
String attrName = attribute.getName();
return LOCALIZABLE_ATTRIBUTES.contains(attrName)
|| LOCALIZABLE_ATTRIBUTES.contains(tagName + "/" + attrName);
}
});
ctx.replaceFragment(text, result);