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.util.Arrays;
michael@0: import java.util.List;
michael@0:
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: public class ServerInfoHandler extends DefaultHandler {
michael@0:
michael@0: private static final String HREF = "href";
michael@0: private static final String PRINCIPAL_URL = "principal-URL";
michael@0: private static final String CURRENT_USER_PRINCIPAL = "current-user-principal";
michael@0: private final static List TAGS = Arrays.asList(
michael@0: CURRENT_USER_PRINCIPAL, PRINCIPAL_URL);
michael@0: private StringBuilder stringBuilder = new StringBuilder();
michael@0: private String inParentElement;
michael@0: private String currentElement;
michael@0:
michael@0: public String currentUserPrincipal = null;
michael@0: public String principalUrl = null;
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 (TAGS.contains(localName)) {
michael@0: inParentElement = localName;
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) && TAGS.contains(inParentElement)) {
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 (TAGS.contains(inParentElement)) {
michael@0: if (HREF.equals(currentElement) && TAGS.contains(inParentElement)) {
michael@0: if (CURRENT_USER_PRINCIPAL.equals(inParentElement)) {
michael@0: currentUserPrincipal = stringBuilder.toString();
michael@0: } else {
michael@0: principalUrl = stringBuilder.toString();
michael@0: }
michael@0: }
michael@0: if(TAGS.contains(localName)){
michael@0: inParentElement = null;
michael@0: //stringBuilder.setLength(0);
michael@0: }
michael@0: currentElement=null;
michael@0:
michael@0: }
michael@0: }