Tue, 10 Feb 2015 18:12:00 +0100
Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.
michael@0 | 1 | package org.gege.caldavsyncadapter.caldav.xml; |
michael@0 | 2 | |
michael@0 | 3 | import org.gege.caldavsyncadapter.caldav.xml.sax.MultiStatus; |
michael@0 | 4 | import org.gege.caldavsyncadapter.caldav.xml.sax.Prop; |
michael@0 | 5 | import org.gege.caldavsyncadapter.caldav.xml.sax.PropStat; |
michael@0 | 6 | import org.gege.caldavsyncadapter.caldav.xml.sax.Response; |
michael@0 | 7 | import org.xml.sax.Attributes; |
michael@0 | 8 | import org.xml.sax.SAXException; |
michael@0 | 9 | import org.xml.sax.helpers.DefaultHandler; |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | public class MultiStatusHandler extends DefaultHandler { |
michael@0 | 13 | public MultiStatus mMultiStatus; |
michael@0 | 14 | private Response mResponse; |
michael@0 | 15 | private PropStat mPropStat; |
michael@0 | 16 | private Prop mProp; |
michael@0 | 17 | private String mCurrentValue; |
michael@0 | 18 | |
michael@0 | 19 | private String RESPONSE = "response"; |
michael@0 | 20 | private String HREF = "href"; |
michael@0 | 21 | private String PROPSTAT = "propstat"; |
michael@0 | 22 | private String PROP = "prop"; |
michael@0 | 23 | private String STATUS = "status"; |
michael@0 | 24 | private String CALENDARDATA = "calendar-data"; |
michael@0 | 25 | private String GETETAG = "getetag"; |
michael@0 | 26 | |
michael@0 | 27 | public MultiStatusHandler() { |
michael@0 | 28 | mMultiStatus = new MultiStatus(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | @Override |
michael@0 | 32 | public void characters(char[] ch, int start, int length) throws SAXException { |
michael@0 | 33 | mCurrentValue += new String(ch, start, length); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | @Override |
michael@0 | 37 | public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { |
michael@0 | 38 | mCurrentValue = ""; |
michael@0 | 39 | if (localName.equals(RESPONSE)) { |
michael@0 | 40 | mResponse = new Response(); |
michael@0 | 41 | mMultiStatus.ResponseList.add(mResponse); |
michael@0 | 42 | } else if (localName.equals(PROPSTAT)) { |
michael@0 | 43 | mPropStat = new PropStat(); |
michael@0 | 44 | mResponse.propstat = mPropStat; |
michael@0 | 45 | } else if (localName.equals(PROP)) { |
michael@0 | 46 | mProp = new Prop(); |
michael@0 | 47 | mPropStat.prop = mProp; |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | @Override |
michael@0 | 52 | public void endElement(String uri, String localName, String qName) throws SAXException { |
michael@0 | 53 | if (localName.equals(HREF)) { |
michael@0 | 54 | mResponse.href = mCurrentValue; |
michael@0 | 55 | } else if (localName.equals(STATUS)) { |
michael@0 | 56 | if (mPropStat != null) |
michael@0 | 57 | mPropStat.status = mCurrentValue; |
michael@0 | 58 | } else if (localName.equals(CALENDARDATA)) { |
michael@0 | 59 | mProp.calendardata = mCurrentValue; |
michael@0 | 60 | } else if (localName.equals(GETETAG)) { |
michael@0 | 61 | mProp.getetag = mCurrentValue; |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | } |