1 // Copyright 2009 The Android Open Source Project 2 3 package com.google.wireless.gdata2.contacts.parser.xml; 4 5 import com.google.wireless.gdata2.contacts.data.GroupEntry; 6 import com.google.wireless.gdata2.contacts.data.GroupsFeed; 7 import com.google.wireless.gdata2.data.Entry; 8 import com.google.wireless.gdata2.data.Feed; 9 import com.google.wireless.gdata2.data.StringUtils; 10 import com.google.wireless.gdata2.parser.ParseException; 11 import com.google.wireless.gdata2.parser.xml.XmlGDataParser; 12 13 import org.xmlpull.v1.XmlPullParser; 14 15 import java.io.InputStream; 16 17 /** 18 * GDataParser for a contact groups feed. 19 */ 20 public class XmlGroupEntryGDataParser extends XmlGDataParser { 21 /** 22 * Creates a new XmlGroupEntryGDataParser. 23 * @param is The InputStream that should be parsed. 24 * @param parser the XmlPullParser to use for the xml parsing 25 * @throws ParseException Thrown if a parser cannot be created. 26 */ XmlGroupEntryGDataParser(InputStream is, XmlPullParser parser)27 public XmlGroupEntryGDataParser(InputStream is, XmlPullParser parser) throws ParseException { 28 super(is, parser); 29 } 30 31 /* 32 * (non-Javadoc) 33 * @see com.google.wireless.gdata2.parser.xml.XmlGDataParser#createFeed() 34 */ createFeed()35 protected Feed createFeed() { 36 return new GroupsFeed(); 37 } 38 39 /* 40 * (non-Javadoc) 41 * @see com.google.wireless.gdata2.parser.xml.XmlGDataParser#createEntry() 42 */ createEntry()43 protected Entry createEntry() { 44 return new GroupEntry(); 45 } 46 handleExtraElementInEntry(Entry entry)47 protected void handleExtraElementInEntry(Entry entry) { 48 XmlPullParser parser = getParser(); 49 50 if (!(entry instanceof GroupEntry)) { 51 throw new IllegalArgumentException("Expected GroupEntry!"); 52 } 53 GroupEntry groupEntry = (GroupEntry) entry; 54 String name = parser.getName(); 55 if ("systemGroup".equals(name)) { 56 String systemGroup = parser.getAttributeValue(null /* ns */, "id"); 57 // if the systemGroup is the empty string, convert it to a null 58 if (StringUtils.isEmpty(systemGroup)) systemGroup = null; 59 groupEntry.setSystemGroup(systemGroup); 60 } 61 } 62 } 63