3 |
package org.nongnu.alph.xml; |
package org.nongnu.alph.xml; |
4 |
import org.nongnu.alph.*; |
import org.nongnu.alph.*; |
5 |
|
|
6 |
|
import java.util.ArrayList; |
7 |
|
import java.util.List; |
8 |
|
|
9 |
/** A simple span serializer / deserializer. |
/** A simple span serializer / deserializer. |
10 |
* Just takes a sequence of spans and adds them to a list. |
* Just takes a sequence of spans and adds them to a list. |
11 |
*/ |
*/ |
12 |
|
|
13 |
public class SpanReader extends org.xml.sax.helpers.DefaultHandler { |
public class SpanReader extends org.xml.sax.helpers.DefaultHandler { |
14 |
|
public static boolean dbg = true; |
15 |
|
private static void pa(String s) { System.out.println(s); } |
16 |
|
|
17 |
public interface ScrollBlockFactory { |
public interface ScrollBlockFactory { |
18 |
ScrollBlock getScrollBlock(String id); |
ScrollBlock getScrollBlock(String id); |
26 |
|
|
27 |
public void startElement(String uri, String localName, String qName, |
public void startElement(String uri, String localName, String qName, |
28 |
org.xml.sax.Attributes attributes) { |
org.xml.sax.Attributes attributes) { |
29 |
if(localName.equals("ts")) { |
if(dbg) pa("Se: '"+uri+"' '"+localName+"' '"+qName+"'"); |
30 |
String b = attributes.getValue("s"); |
if(qName.equals("ts")) { |
31 |
|
String b = attributes.getValue("b"); |
32 |
int s = Integer.parseInt(attributes.getValue("s")); |
int s = Integer.parseInt(attributes.getValue("s")); |
33 |
int e = Integer.parseInt(attributes.getValue("e")); |
int e = Integer.parseInt(attributes.getValue("e")); |
34 |
spans.add((TextScrollBlock)(scrollBlockFactory.getScrollBlock(b)) |
spans.add(((TextScrollBlock)(scrollBlockFactory.getScrollBlock(b))) |
35 |
. getSpan(s, e)); |
. getSpan(s, e)); |
36 |
} else { |
} else { |
37 |
throw new Error("Unknown element "+localName); |
throw new Error("Unknown element '"+localName+"'"); |
38 |
} |
} |
39 |
} |
} |
40 |
public void endElement(String uri, String localName, String qName) { |
public void endElement(String uri, String localName, String qName) { |