1 |
|
from org.nongnu import alph |
2 |
from org.nongnu.alph.xml import * |
from org.nongnu.alph.xml import * |
3 |
|
|
4 |
def testFoo(): |
import java |
5 |
print "HEI" |
import javax |
6 |
|
|
7 |
|
class Ts(alph.TextSpan): |
8 |
|
def __init__(self, id, s, e): |
9 |
|
print "TS: ",id,s,e |
10 |
|
self.id = id |
11 |
|
self.s = s |
12 |
|
self.e = e |
13 |
|
|
14 |
|
class Sb(alph.TextScrollBlock): |
15 |
|
def __init__(self, id): |
16 |
|
self.id = id |
17 |
|
def getSpan(self, s, e): |
18 |
|
return Ts(self.id, s, e) |
19 |
|
|
20 |
|
class Fact(SpanReader.ScrollBlockFactory): |
21 |
|
def getScrollBlock(self, id): |
22 |
|
return Sb(id) |
23 |
|
|
24 |
|
def getParser(): |
25 |
|
return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser() |
26 |
|
|
27 |
|
def parseString(string, handler): |
28 |
|
p = getParser() |
29 |
|
p.parse(java.io.StringBufferInputStream(string), handler) |
30 |
|
|
31 |
|
|
32 |
|
def testParseSpan(): |
33 |
|
r = SpanReader() |
34 |
|
r.scrollBlockFactory = Fact() |
35 |
|
parseString("""<ts b="X" s="5" e="10"/>""", r) |
36 |
|
sp = r.getSpans()[0] |
37 |
|
failUnlessEqual(sp.id, "X") |
38 |
|
failUnlessEqual(sp.s, 5) |
39 |
|
failUnlessEqual(sp.e, 10) |