michael@0: /** michael@0: * Copyright (c) 2012-2013, David Wiesner michael@0: * michael@0: * This file is part of Andoid Caldav Sync Adapter Free. michael@0: * michael@0: * Andoid Caldav Sync Adapter Free is free software: you can redistribute michael@0: * it and/or modify it under the terms of the GNU General Public License michael@0: * as published by the Free Software Foundation, either version 3 of the michael@0: * License, or at your option any later version. michael@0: * michael@0: * Andoid Caldav Sync Adapter Free is distributed in the hope that michael@0: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied michael@0: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the michael@0: * GNU General Public License for more details. michael@0: * michael@0: * You should have received a copy of the GNU General Public License michael@0: * along with Andoid Caldav Sync Adapter Free. michael@0: * If not, see . michael@0: * michael@0: */ michael@0: michael@0: package org.gege.caldavsyncadapter.caldav.xml; michael@0: michael@0: import java.net.URI; michael@0: import java.net.URISyntaxException; michael@0: import java.util.ArrayList; michael@0: import java.util.List; michael@0: michael@0: import org.gege.caldavsyncadapter.BuildConfig; michael@0: import org.xml.sax.Attributes; michael@0: import org.xml.sax.SAXException; michael@0: import org.xml.sax.helpers.DefaultHandler; michael@0: michael@0: import android.util.Log; michael@0: michael@0: public class CalendarHomeHandler extends DefaultHandler { michael@0: michael@0: private static final String HREF = "href"; michael@0: private static final String CALENDAR_HOME_SET = "calendar-home-set"; michael@0: private boolean isInCalendarHomeSet = false; michael@0: private StringBuilder stringBuilder = new StringBuilder(); michael@0: private String currentElement; michael@0: private URI principalURI; michael@0: michael@0: public List calendarHomeSet = new ArrayList(); michael@0: michael@0: public CalendarHomeHandler(URI principalURI) { michael@0: this.principalURI = principalURI; michael@0: } michael@0: michael@0: @Override michael@0: public void startElement(String uri, String localName, String qName, michael@0: Attributes attributes) throws SAXException { michael@0: if (CALENDAR_HOME_SET.equals(localName)) { michael@0: isInCalendarHomeSet = true; michael@0: } michael@0: currentElement = localName; michael@0: stringBuilder.setLength(0); michael@0: } michael@0: michael@0: @Override michael@0: public void characters(char[] ch, int start, int length) michael@0: throws SAXException { michael@0: if (HREF.equals(currentElement) && isInCalendarHomeSet) { michael@0: stringBuilder.append(ch, start, length); michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public void endElement(String uri, String localName, String qName) michael@0: throws SAXException { michael@0: if (HREF.equals(localName) && isInCalendarHomeSet) { michael@0: String calendarHomeSet = stringBuilder.toString(); michael@0: try { michael@0: URI calendarHomeSetURI = new URI(calendarHomeSet); michael@0: calendarHomeSetURI = principalURI.resolve(calendarHomeSetURI); michael@0: this.calendarHomeSet.add(calendarHomeSetURI); michael@0: } catch (URISyntaxException e) { michael@0: if (BuildConfig.DEBUG) { michael@0: Log.e(CalendarHomeHandler.class.getSimpleName(), michael@0: "uri malformed: " + calendarHomeSet); michael@0: } else { michael@0: Log.e(CalendarHomeHandler.class.getSimpleName(), michael@0: "uri malformed in calendar-home-set/href"); michael@0: } michael@0: } michael@0: //stringBuilder.setLength(0); michael@0: } michael@0: if (CALENDAR_HOME_SET.equals(localName)) { michael@0: isInCalendarHomeSet = false; michael@0: } michael@0: currentElement=null; michael@0: } michael@0: }