public PropertiesBinding() {
super("properties");
}
public Object parse(Element element, Parse parse, Parser parser) {
PropertiesDescriptor descriptor = new PropertiesDescriptor();
if (element.hasAttribute("file")) {
descriptor.setFile(element.getAttribute("file"));
}
if (element.hasAttribute("resource")) {
descriptor.setResource(element.getAttribute("resource"));
}
if (element.hasAttribute("url")) {
descriptor.setUrl(element.getAttribute("url"));
}
Boolean isXml = XmlUtil.attributeBoolean(element, "is-xml", false, parse);
if (isXml!=null) {
descriptor.setXml(isXml.booleanValue());
}
List<Descriptor> keyDescriptors = new ArrayList<Descriptor>();
List<Descriptor> valueDescriptors = new ArrayList<Descriptor>();
List<Element> elements = XmlUtil.elements(element);
for (Element propertyElement: elements) {
if ("property".equals(XmlUtil.getTagLocalName(propertyElement))) {
// key
String name = XmlUtil.attribute(propertyElement, "name");
// value
String value = XmlUtil.attribute(propertyElement, "value");
if ( (name!=null)
&& (value!=null)
) {
keyDescriptors.add(new StringDescriptor(name));
valueDescriptors.add(new StringDescriptor(value));
} else {
parse.addProblem("property must have name and value attributes: "+XmlUtil.toString(propertyElement), element);
}
} else {
parse.addProblem("properties can only contain property elements: "+XmlUtil.toString(propertyElement), element);
}
}
descriptor.setKeyDescriptors(keyDescriptors);
descriptor.setValueDescriptors(valueDescriptors);
return descriptor;
}