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

changeset 0
fb9019fb1bf7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/org/gege/caldavsyncadapter/caldav/xml/ServerInfoHandler.java	Tue Feb 10 18:12:00 2015 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +/**
     1.5 + * Copyright (c) 2012-2013, David Wiesner
     1.6 + * 
     1.7 + * This file is part of Andoid Caldav Sync Adapter Free.
     1.8 + *
     1.9 + * Andoid Caldav Sync Adapter Free is free software: you can redistribute 
    1.10 + * it and/or modify it under the terms of the GNU General Public License 
    1.11 + * as published by the Free Software Foundation, either version 3 of the 
    1.12 + * License, or at your option any later version.
    1.13 + *
    1.14 + * Andoid Caldav Sync Adapter Free is distributed in the hope that 
    1.15 + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
    1.16 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 + * GNU General Public License for more details.
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License
    1.20 + * along with Andoid Caldav Sync Adapter Free.  
    1.21 + * If not, see <http://www.gnu.org/licenses/>.
    1.22 + * 
    1.23 + */
    1.24 +
    1.25 +package org.gege.caldavsyncadapter.caldav.xml;
    1.26 +
    1.27 +import java.util.Arrays;
    1.28 +import java.util.List;
    1.29 +
    1.30 +import org.xml.sax.Attributes;
    1.31 +import org.xml.sax.SAXException;
    1.32 +import org.xml.sax.helpers.DefaultHandler;
    1.33 +
    1.34 +public class ServerInfoHandler extends DefaultHandler {
    1.35 +
    1.36 +	private static final String HREF = "href";
    1.37 +	private static final String PRINCIPAL_URL = "principal-URL";
    1.38 +	private static final String CURRENT_USER_PRINCIPAL = "current-user-principal";
    1.39 +	private final static List<String> TAGS = Arrays.asList(
    1.40 +			CURRENT_USER_PRINCIPAL, PRINCIPAL_URL);
    1.41 +	private StringBuilder stringBuilder = new StringBuilder();
    1.42 +	private String inParentElement;
    1.43 +	private String currentElement;
    1.44 +
    1.45 +	public String currentUserPrincipal = null;
    1.46 +	public String principalUrl = null;
    1.47 +
    1.48 +	@Override
    1.49 +	public void startElement(String uri, String localName, String qName,
    1.50 +			Attributes attributes) throws SAXException {
    1.51 +		if (TAGS.contains(localName)) {
    1.52 +			inParentElement = localName;
    1.53 +		}
    1.54 +		currentElement = localName;
    1.55 +		stringBuilder.setLength(0);
    1.56 +	}
    1.57 +
    1.58 +	@Override
    1.59 +	public void characters(char[] ch, int start, int length)
    1.60 +			throws SAXException {
    1.61 +		if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) {
    1.62 +			stringBuilder.append(ch, start, length);
    1.63 +		}
    1.64 +	}
    1.65 +
    1.66 +	@Override
    1.67 +	public void endElement(String uri, String localName, String qName)
    1.68 +			throws SAXException {
    1.69 +		//if (TAGS.contains(inParentElement)) {
    1.70 +		if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) {
    1.71 +			if (CURRENT_USER_PRINCIPAL.equals(inParentElement)) {
    1.72 +				currentUserPrincipal = stringBuilder.toString();
    1.73 +			} else {
    1.74 +				principalUrl = stringBuilder.toString();
    1.75 +			}
    1.76 +		}
    1.77 +		 if(TAGS.contains(localName)){
    1.78 +			inParentElement = null;
    1.79 +			//stringBuilder.setLength(0);
    1.80 +		}
    1.81 +		 currentElement=null;
    1.82 +	
    1.83 +	}
    1.84 +}

mercurial