[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] alph/org/nongnu/alph/xml SpanReader.java serial...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] alph/org/nongnu/alph/xml SpanReader.java serial... |
Date: |
Fri, 25 Apr 2003 11:33:56 -0400 |
CVSROOT: /cvsroot/alph
Module name: alph
Changes by: Benja Fallenstein <address@hidden> 03/04/25 11:33:56
Modified files:
org/nongnu/alph/xml: SpanReader.java serialization.test
Log message:
test & fix
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/xml/SpanReader.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/xml/serialization.test.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: alph/org/nongnu/alph/xml/SpanReader.java
diff -u alph/org/nongnu/alph/xml/SpanReader.java:1.7
alph/org/nongnu/alph/xml/SpanReader.java:1.8
--- alph/org/nongnu/alph/xml/SpanReader.java:1.7 Fri Apr 25 10:29:19 2003
+++ alph/org/nongnu/alph/xml/SpanReader.java Fri Apr 25 11:33:56 2003
@@ -15,11 +15,11 @@
public static boolean dbg = false;
private static void pa(String s) { System.out.println(s); }
- public interface ScrollBlockFactory {
- ScrollBlock getScrollBlock(String id);
- }
+ public Alph alph;
- public ScrollBlockFactory scrollBlockFactory;
+ public SpanReader(Alph alph) {
+ this.alph = alph;
+ }
private ArrayList spans = new ArrayList();
@@ -38,7 +38,7 @@
String b = attributes.getValue("b");
int s = Integer.parseInt(attributes.getValue("s"));
int e = Integer.parseInt(attributes.getValue("e"));
- spans.add(((TextScrollBlock)(scrollBlockFactory.getScrollBlock(b)))
+ spans.add(((TextScrollBlock)(alph.getScrollBlock(b)))
. getSpan(s, e));
} else if(qName.equals("uts")) {
String b = attributes.getValue("b");
@@ -52,17 +52,22 @@
String b = attributes.getValue("b");
int s = Integer.parseInt(attributes.getValue("s"));
int e = Integer.parseInt(attributes.getValue("e"));
- spans.add(((PageScrollBlock)(scrollBlockFactory.getScrollBlock(b)))
+ spans.add(((PageScrollBlock)(alph.getScrollBlock(b)))
.getSpan(s, e));
} else if(qName.equals("pis")) {
- String b = attributes.getValue("b");
- int p = Integer.parseInt(attributes.getValue("p"));
- int x = Integer.parseInt(attributes.getValue("x"));
- int y = Integer.parseInt(attributes.getValue("y"));
- int w = Integer.parseInt(attributes.getValue("w"));
- int h = Integer.parseInt(attributes.getValue("h"));
- spans.add(((PageScrollBlock)(scrollBlockFactory.getScrollBlock(b)))
- .getPage(p).subArea(x,y,w,h));
+ try {
+ String b = attributes.getValue("b");
+ int p = Integer.parseInt(attributes.getValue("p"));
+ int x = Integer.parseInt(attributes.getValue("x"));
+ int y = Integer.parseInt(attributes.getValue("y"));
+ int w = Integer.parseInt(attributes.getValue("w"));
+ int h = Integer.parseInt(attributes.getValue("h"));
+ spans.add(((PageScrollBlock)(alph.getScrollBlock(b)))
+ .getPage(p).subArea(x,y,w,h));
+ } catch(Throwable t) {
+ System.out.println("------------ PageImageSpan -------------");
+ t.printStackTrace();
+ }
} else {
throw new Error("Unknown element '"+localName+"'");
}
Index: alph/org/nongnu/alph/xml/serialization.test
diff -u alph/org/nongnu/alph/xml/serialization.test:1.6
alph/org/nongnu/alph/xml/serialization.test:1.7
--- alph/org/nongnu/alph/xml/serialization.test:1.6 Tue Apr 15 23:44:23 2003
+++ alph/org/nongnu/alph/xml/serialization.test Fri Apr 25 11:33:56 2003
@@ -1,4 +1,4 @@
-from org.nongnu import alph
+from org.nongnu import alph, storm
from org.nongnu.alph.xml import *
import java
@@ -30,7 +30,10 @@
def getID(self):
return self.id
-class Fact(SpanReader.ScrollBlockFactory):
+class TestAlph(alph.Alph):
+ """
+ Partial implementation of Alph, for tests.
+ """
def getScrollBlock(self, id):
return Sb(id)
@@ -48,8 +51,7 @@
# Actual tests
def testParseSpan():
- r = SpanReader()
- r.scrollBlockFactory = Fact()
+ r = SpanReader(TestAlph())
str = """<ts b="X" s="5" e="10"/>"""
parseString(str, r)
sp = r.getSpans()[0]
@@ -62,8 +64,7 @@
def testMultiple():
"""See that multiple span readings work right.
"""
- r = SpanReader()
- r.scrollBlockFactory = Fact()
+ r = SpanReader(TestAlph())
str = """<alph><ts b="X" s="5" e="10"/><ts b="Y" s="7" e="8"/></alph>"""
parseString(str, r)
list = r.getSpans()
@@ -89,7 +90,7 @@
def testURN5():
"""See that reading and writing URN-5 spans works
"""
- r = SpanReader()
+ r = SpanReader(TestAlph())
str = """<uts b="Q" o="5" t="foo&bar"/>"""
parseString(str, r)
sp = r.getSpans()[0]
@@ -102,7 +103,7 @@
def testFake():
"""See that reading/writing fake spans works.
"""
- r = SpanReader()
+ r = SpanReader(TestAlph())
str = """<fts t="foo&bar"/>"""
parseString(str, r)
@@ -113,3 +114,23 @@
failUnlessEqual(SpanSerializer().span2xml(sp), str)
+def testPageImageSpan():
+ pool = storm.impl.TransientPool(java.util.HashSet())
+ salph = alph.impl.StormAlph(pool)
+ sb = salph.addFile(java.io.File('testdata/test1.pdf'),
+ 'application/pdf')
+ span = sb.getPage(1).subArea(70, 30, 40, 45)
+ s = SpanSerializer()
+ s.addSpan(span)
+ str = s.get()
+
+ assert str == '<alph><pis
b="urn:x-storm:1.0:application/pdf,6qrwyxinrkbr6znvopuo2rnqc7jjfpqg.ettfngwwbh4ore2hljm4soyipujr42gc7becvgq"
p="1" x="70" y="30" w="40" h="45"/></alph>'
+
+ r = SpanReader(salph)
+
+ parseString(str, r)
+ sp = r.getSpans()[0]
+ assert sp.getPageIndex() == 1
+ assert sp.getLocation() == span.getLocation()
+ assert sp.getSize() == span.getSize()
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] alph/org/nongnu/alph/xml SpanReader.java serial...,
Benja Fallenstein <=