Skip to main content
summaryrefslogtreecommitdiffstats
blob: 072b8ae85fe997add988ac70234d1b10c4355feb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.internal.tasks.core;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.mylar.internal.context.core.util.XmlStringConverter;
import org.eclipse.mylar.tasks.core.IRepositoryConstants;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Adapted from SaxContextContentHandler
 * 
 * @author Rob Elves
 */
public class SaxRepositoriesContentHandler extends DefaultHandler {


	static final String ATTRIBUTE_INTERACTION_EVENT = "InteractionEvent";

	private Set<TaskRepository> taskRepositories = new HashSet<TaskRepository>();

	@Override
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		try {
			if (localName.equals(TaskRepositoriesExternalizer.ELEMENT_TASK_REPOSITORY) && attributes != null) {
				String kind = XmlStringConverter.convertXmlToString(attributes
						.getValue(IRepositoryConstants.PROPERTY_KIND));
				String url = XmlStringConverter.convertXmlToString(attributes
						.getValue(IRepositoryConstants.PROPERTY_URL));
				if (kind != null && kind.length() > 0 && url != null && url.length() > 0) {
					TaskRepository repository = new TaskRepository(kind, url);
					for (int index = 0; index < attributes.getLength(); index++) {
						String key = XmlStringConverter.convertXmlToString(attributes.getLocalName(index));
						String value = XmlStringConverter.convertXmlToString(attributes.getValue(index));
						repository.setProperty(key, value);
					}
					taskRepositories.add(repository);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public Set<TaskRepository> getRepositories() {
		return taskRepositories;
	}
}

Back to the top