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

changeset 0
fb9019fb1bf7
equal deleted inserted replaced
-1:000000000000 0:65cf8765ae02
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 */
21
22 package org.gege.caldavsyncadapter.caldav.xml;
23
24 import java.util.Arrays;
25 import java.util.List;
26
27 import org.xml.sax.Attributes;
28 import org.xml.sax.SAXException;
29 import org.xml.sax.helpers.DefaultHandler;
30
31 public class ServerInfoHandler extends DefaultHandler {
32
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;
41
42 public String currentUserPrincipal = null;
43 public String principalUrl = null;
44
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 }
54
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 }
62
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;
79
80 }
81 }

mercurial