summaryrefslogtreecommitdiff
path: root/src/com/google/wireless/gdata2/contacts/parser/xml/XmlGroupEntryGDataParser.java
blob: 943eb41a52953e92486833f228ae36fe469ab4e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2009 The Android Open Source Project

package com.google.wireless.gdata2.contacts.parser.xml;

import com.google.wireless.gdata2.contacts.data.GroupEntry;
import com.google.wireless.gdata2.contacts.data.GroupsFeed;
import com.google.wireless.gdata2.data.Entry;
import com.google.wireless.gdata2.data.Feed;
import com.google.wireless.gdata2.data.StringUtils;
import com.google.wireless.gdata2.parser.ParseException;
import com.google.wireless.gdata2.parser.xml.XmlGDataParser;

import org.xmlpull.v1.XmlPullParser;

import java.io.InputStream;

/**
 * GDataParser for a contact groups feed.
 */
public class XmlGroupEntryGDataParser extends XmlGDataParser {
  /**
   * Creates a new XmlGroupEntryGDataParser.
   * @param is The InputStream that should be parsed.
   * @param parser the XmlPullParser to use for the xml parsing
   * @throws ParseException Thrown if a parser cannot be created.
   */
  public XmlGroupEntryGDataParser(InputStream is, XmlPullParser parser) throws ParseException {
    super(is, parser);
  }

  /*
  * (non-Javadoc)
  * @see com.google.wireless.gdata2.parser.xml.XmlGDataParser#createFeed()
  */
  protected Feed createFeed() {
    return new GroupsFeed();
  }

  /*
  * (non-Javadoc)
  * @see com.google.wireless.gdata2.parser.xml.XmlGDataParser#createEntry()
  */
  protected Entry createEntry() {
    return new GroupEntry();
  }

  protected void handleExtraElementInEntry(Entry entry) {
    XmlPullParser parser = getParser();

    if (!(entry instanceof GroupEntry)) {
      throw new IllegalArgumentException("Expected GroupEntry!");
    }
    GroupEntry groupEntry = (GroupEntry) entry;
    String name = parser.getName();
    if ("systemGroup".equals(name)) {
      String systemGroup = parser.getAttributeValue(null /* ns */, "id");
      // if the systemGroup is the empty string, convert it to a null
      if (StringUtils.isEmpty(systemGroup)) systemGroup = null;
      groupEntry.setSystemGroup(systemGroup);
    }
  }
}