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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*******************************************************************************
* 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.mylyn.internal.bugzilla.core;
import java.util.Locale;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.ITaskCollector;
import org.eclipse.mylyn.web.core.HtmlStreamTokenizer;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Parser for RDF bugzilla query results.
*
* @author Rob Elves
*/
public class SaxBugzillaQueryContentHandler extends DefaultHandler {
/** The bug id */
private String id;
/** The summary of the bug */
private String description = "";
/** The priority of the bug */
private String priority = AbstractTask.PriorityLevel.getDefault().toString();
private StringBuffer characters;
private ITaskCollector collector;
private String repositoryUrl;
public SaxBugzillaQueryContentHandler(String repositoryUrl, ITaskCollector collector) {
this.repositoryUrl = repositoryUrl;
this.collector = collector;
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
characters.append(ch, start, length);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
characters = new StringBuffer();
BugzillaReportElement tag = BugzillaReportElement.UNKNOWN;
try {
tag = BugzillaReportElement.valueOf(localName.trim().toUpperCase(Locale.ENGLISH));
switch (tag) {
case LI:
// hit = new BugzillaQueryHit();
// hit.setRepository(repositoryUrl);
// break;
}
} catch (RuntimeException e) {
if (e instanceof IllegalArgumentException) {
// ignore unrecognized tags
return;
}
throw e;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
String parsedText = HtmlStreamTokenizer.unescape(characters.toString());
BugzillaReportElement tag = BugzillaReportElement.UNKNOWN;
try {
tag = BugzillaReportElement.valueOf(localName.trim().toUpperCase(Locale.ENGLISH));
switch (tag) {
case ID:
id = parsedText;
break;
// case BUG_SEVERITY:
// severity = parsedText;
// break;
case PRIORITY:
priority = parsedText;
break;
// case REP_PLATFORM:
// platform = parsedText;
// break;
case ASSIGNED_TO:
//hit.setOwner(parsedText);
break;
case BUG_STATUS:
// state = parsedText;
break;
// case RESOLUTION:
// resolution = parsedText;
// break;
case SHORT_DESC:
description = parsedText;
break;
case SHORT_SHORT_DESC:
description = parsedText;
break;
case LI:
BugzillaTask task = new BugzillaTask(repositoryUrl, id, description);
task.setPriority(priority);
// TODO set state
collector.accept(task);
}
} catch (RuntimeException e) {
if (e instanceof IllegalArgumentException) {
// ignore unrecognized tags
return;
}
throw e;
}
}
}
|