src/org/gege/caldavsyncadapter/caldav/xml/ServerInfoHandler.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.

     1 /**
     2  * Copyright (c) 2012-2013, David Wiesner
     3  * 
     4  * This file is part of Andoid Caldav Sync Adapter Free.
     5  *
     6  * Andoid Caldav Sync Adapter Free is free software: you can redistribute 
     7  * it and/or modify it under the terms of the GNU General Public License 
     8  * as published by the Free Software Foundation, either version 3 of the 
     9  * License, or at your option any later version.
    10  *
    11  * Andoid Caldav Sync Adapter Free is distributed in the hope that 
    12  * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
    13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License
    17  * along with Andoid Caldav Sync Adapter Free.  
    18  * If not, see <http://www.gnu.org/licenses/>.
    19  * 
    20  */
    22 package org.gege.caldavsyncadapter.caldav.xml;
    24 import java.util.Arrays;
    25 import java.util.List;
    27 import org.xml.sax.Attributes;
    28 import org.xml.sax.SAXException;
    29 import org.xml.sax.helpers.DefaultHandler;
    31 public class ServerInfoHandler extends DefaultHandler {
    33 	private static final String HREF = "href";
    34 	private static final String PRINCIPAL_URL = "principal-URL";
    35 	private static final String CURRENT_USER_PRINCIPAL = "current-user-principal";
    36 	private final static List<String> TAGS = Arrays.asList(
    37 			CURRENT_USER_PRINCIPAL, PRINCIPAL_URL);
    38 	private StringBuilder stringBuilder = new StringBuilder();
    39 	private String inParentElement;
    40 	private String currentElement;
    42 	public String currentUserPrincipal = null;
    43 	public String principalUrl = null;
    45 	@Override
    46 	public void startElement(String uri, String localName, String qName,
    47 			Attributes attributes) throws SAXException {
    48 		if (TAGS.contains(localName)) {
    49 			inParentElement = localName;
    50 		}
    51 		currentElement = localName;
    52 		stringBuilder.setLength(0);
    53 	}
    55 	@Override
    56 	public void characters(char[] ch, int start, int length)
    57 			throws SAXException {
    58 		if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) {
    59 			stringBuilder.append(ch, start, length);
    60 		}
    61 	}
    63 	@Override
    64 	public void endElement(String uri, String localName, String qName)
    65 			throws SAXException {
    66 		//if (TAGS.contains(inParentElement)) {
    67 		if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) {
    68 			if (CURRENT_USER_PRINCIPAL.equals(inParentElement)) {
    69 				currentUserPrincipal = stringBuilder.toString();
    70 			} else {
    71 				principalUrl = stringBuilder.toString();
    72 			}
    73 		}
    74 		 if(TAGS.contains(localName)){
    75 			inParentElement = null;
    76 			//stringBuilder.setLength(0);
    77 		}
    78 		 currentElement=null;
    80 	}
    81 }

mercurial