* @author Remy Maucherat
*/
public class TagFileMetaDataParser extends MetaDataElementParser {
public static TagFileMetaData parse(XMLStreamReader reader) throws XMLStreamException {
TagFileMetaData tagFile = new TagFileMetaData();
// Handle attributes
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i ++) {
final String value = reader.getAttributeValue(i);
if (reader.getAttributeNamespace(i) != null) {
continue;
}
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case ID: {
tagFile.setId(value);
break;
}
default: throw unexpectedAttribute(reader, i);
}
}
DescriptionGroupMetaData descriptionGroup = new DescriptionGroupMetaData();
// Handle elements
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
if (DescriptionGroupMetaDataParser.parse(reader, descriptionGroup)) {
if (tagFile.getDescriptionGroup() == null) {
tagFile.setDescriptionGroup(descriptionGroup);
}
continue;
}
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case NAME:
tagFile.setName(reader.getElementText());
break;
case PATH:
tagFile.setPath(reader.getElementText());
break;
case EXAMPLE:
List<String> examples = tagFile.getExamples();
if (examples == null) {
examples = new ArrayList<String>();
tagFile.setExamples(examples);
}
examples.add(reader.getElementText());
break;
case TAG_EXTENSION:
List<TldExtensionMetaData> extensions = tagFile.getTagExtensions();
if (extensions == null) {
extensions = new ArrayList<TldExtensionMetaData>();
tagFile.setTagExtensions(extensions);
}
extensions.add(TldExtensionMetaDataParser.parse(reader));
break;
default: throw unexpectedElement(reader);
}