Tue, 10 Feb 2015 18:12:00 +0100
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.util.Arrays; |
michael@0 | 25 | import java.util.List; |
michael@0 | 26 | |
michael@0 | 27 | import org.xml.sax.Attributes; |
michael@0 | 28 | import org.xml.sax.SAXException; |
michael@0 | 29 | import org.xml.sax.helpers.DefaultHandler; |
michael@0 | 30 | |
michael@0 | 31 | public class ServerInfoHandler extends DefaultHandler { |
michael@0 | 32 | |
michael@0 | 33 | private static final String HREF = "href"; |
michael@0 | 34 | private static final String PRINCIPAL_URL = "principal-URL"; |
michael@0 | 35 | private static final String CURRENT_USER_PRINCIPAL = "current-user-principal"; |
michael@0 | 36 | private final static List<String> TAGS = Arrays.asList( |
michael@0 | 37 | CURRENT_USER_PRINCIPAL, PRINCIPAL_URL); |
michael@0 | 38 | private StringBuilder stringBuilder = new StringBuilder(); |
michael@0 | 39 | private String inParentElement; |
michael@0 | 40 | private String currentElement; |
michael@0 | 41 | |
michael@0 | 42 | public String currentUserPrincipal = null; |
michael@0 | 43 | public String principalUrl = null; |
michael@0 | 44 | |
michael@0 | 45 | @Override |
michael@0 | 46 | public void startElement(String uri, String localName, String qName, |
michael@0 | 47 | Attributes attributes) throws SAXException { |
michael@0 | 48 | if (TAGS.contains(localName)) { |
michael@0 | 49 | inParentElement = localName; |
michael@0 | 50 | } |
michael@0 | 51 | currentElement = localName; |
michael@0 | 52 | stringBuilder.setLength(0); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | @Override |
michael@0 | 56 | public void characters(char[] ch, int start, int length) |
michael@0 | 57 | throws SAXException { |
michael@0 | 58 | if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) { |
michael@0 | 59 | stringBuilder.append(ch, start, length); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | @Override |
michael@0 | 64 | public void endElement(String uri, String localName, String qName) |
michael@0 | 65 | throws SAXException { |
michael@0 | 66 | //if (TAGS.contains(inParentElement)) { |
michael@0 | 67 | if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) { |
michael@0 | 68 | if (CURRENT_USER_PRINCIPAL.equals(inParentElement)) { |
michael@0 | 69 | currentUserPrincipal = stringBuilder.toString(); |
michael@0 | 70 | } else { |
michael@0 | 71 | principalUrl = stringBuilder.toString(); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | if(TAGS.contains(localName)){ |
michael@0 | 75 | inParentElement = null; |
michael@0 | 76 | //stringBuilder.setLength(0); |
michael@0 | 77 | } |
michael@0 | 78 | currentElement=null; |
michael@0 | 79 | |
michael@0 | 80 | } |
michael@0 | 81 | } |