src/org/gege/caldavsyncadapter/caldav/xml/CalendarHomeHandler.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

michael@0 1 /**
michael@0 2 * Copyright (c) 2012-2013, David Wiesner
michael@0 3 *
michael@0 4 * This file is part of Andoid Caldav Sync Adapter Free.
michael@0 5 *
michael@0 6 * Andoid Caldav Sync Adapter Free is free software: you can redistribute
michael@0 7 * it and/or modify it under the terms of the GNU General Public License
michael@0 8 * as published by the Free Software Foundation, either version 3 of the
michael@0 9 * License, or at your option any later version.
michael@0 10 *
michael@0 11 * Andoid Caldav Sync Adapter Free is distributed in the hope that
michael@0 12 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
michael@0 13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
michael@0 14 * GNU General Public License for more details.
michael@0 15 *
michael@0 16 * You should have received a copy of the GNU General Public License
michael@0 17 * along with Andoid Caldav Sync Adapter Free.
michael@0 18 * If not, see <http://www.gnu.org/licenses/>.
michael@0 19 *
michael@0 20 */
michael@0 21
michael@0 22 package org.gege.caldavsyncadapter.caldav.xml;
michael@0 23
michael@0 24 import java.net.URI;
michael@0 25 import java.net.URISyntaxException;
michael@0 26 import java.util.ArrayList;
michael@0 27 import java.util.List;
michael@0 28
michael@0 29 import org.gege.caldavsyncadapter.BuildConfig;
michael@0 30 import org.xml.sax.Attributes;
michael@0 31 import org.xml.sax.SAXException;
michael@0 32 import org.xml.sax.helpers.DefaultHandler;
michael@0 33
michael@0 34 import android.util.Log;
michael@0 35
michael@0 36 public class CalendarHomeHandler extends DefaultHandler {
michael@0 37
michael@0 38 private static final String HREF = "href";
michael@0 39 private static final String CALENDAR_HOME_SET = "calendar-home-set";
michael@0 40 private boolean isInCalendarHomeSet = false;
michael@0 41 private StringBuilder stringBuilder = new StringBuilder();
michael@0 42 private String currentElement;
michael@0 43 private URI principalURI;
michael@0 44
michael@0 45 public List<URI> calendarHomeSet = new ArrayList<URI>();
michael@0 46
michael@0 47 public CalendarHomeHandler(URI principalURI) {
michael@0 48 this.principalURI = principalURI;
michael@0 49 }
michael@0 50
michael@0 51 @Override
michael@0 52 public void startElement(String uri, String localName, String qName,
michael@0 53 Attributes attributes) throws SAXException {
michael@0 54 if (CALENDAR_HOME_SET.equals(localName)) {
michael@0 55 isInCalendarHomeSet = true;
michael@0 56 }
michael@0 57 currentElement = localName;
michael@0 58 stringBuilder.setLength(0);
michael@0 59 }
michael@0 60
michael@0 61 @Override
michael@0 62 public void characters(char[] ch, int start, int length)
michael@0 63 throws SAXException {
michael@0 64 if (HREF.equals(currentElement) && isInCalendarHomeSet) {
michael@0 65 stringBuilder.append(ch, start, length);
michael@0 66 }
michael@0 67 }
michael@0 68
michael@0 69 @Override
michael@0 70 public void endElement(String uri, String localName, String qName)
michael@0 71 throws SAXException {
michael@0 72 if (HREF.equals(localName) && isInCalendarHomeSet) {
michael@0 73 String calendarHomeSet = stringBuilder.toString();
michael@0 74 try {
michael@0 75 URI calendarHomeSetURI = new URI(calendarHomeSet);
michael@0 76 calendarHomeSetURI = principalURI.resolve(calendarHomeSetURI);
michael@0 77 this.calendarHomeSet.add(calendarHomeSetURI);
michael@0 78 } catch (URISyntaxException e) {
michael@0 79 if (BuildConfig.DEBUG) {
michael@0 80 Log.e(CalendarHomeHandler.class.getSimpleName(),
michael@0 81 "uri malformed: " + calendarHomeSet);
michael@0 82 } else {
michael@0 83 Log.e(CalendarHomeHandler.class.getSimpleName(),
michael@0 84 "uri malformed in calendar-home-set/href");
michael@0 85 }
michael@0 86 }
michael@0 87 //stringBuilder.setLength(0);
michael@0 88 }
michael@0 89 if (CALENDAR_HOME_SET.equals(localName)) {
michael@0 90 isInCalendarHomeSet = false;
michael@0 91 }
michael@0 92 currentElement=null;
michael@0 93 }
michael@0 94 }

mercurial