1 | |
package org.paneris.bibliomania.metasearch.bob; |
2 | |
|
3 | |
import java.io.File; |
4 | |
|
5 | |
import org.melati.util.IoUtils; |
6 | |
import org.paneris.bibliomania.BookStocking; |
7 | |
import org.paneris.bibliomania.metasearch.BookStockingFactory; |
8 | |
import org.paneris.bibliomania.metasearch.util.SearchResultsBase; |
9 | |
|
10 | |
public class SearchResults extends SearchResultsBase { |
11 | |
public SearchResults(byte[] text, |
12 | |
BookStockingFactory stockings) { |
13 | 0 | super(text, stockings); |
14 | 0 | } |
15 | |
|
16 | |
protected static final byte[] |
17 | 0 | form_oid = "form%25oid=".getBytes(), |
18 | 0 | italic = "<i>".getBytes(), |
19 | 0 | fontSize2 = "<font size=2>".getBytes(), |
20 | 0 | pound = "£".getBytes(), |
21 | 0 | pubstatus = "pubstatus.html".getBytes(), |
22 | 0 | width20 = "width=\"20%\">".getBytes(); |
23 | |
|
24 | |
protected Object more() { |
25 | |
try { |
26 | |
for (;;) { |
27 | 0 | skipTo(form_oid); |
28 | |
try { |
29 | 0 | BookStocking book = stockings.newStocking(); |
30 | |
int url; |
31 | 0 | for (url = here; text[url] != '"'; --url); |
32 | 0 | book.setVendorproductid_unsafe(digits()); |
33 | 0 | skipTo((byte)'"'); |
34 | 0 | book.setDetailurl_unsafe(new String(text, url + 1, here - url - 2)); |
35 | 0 | skipTo((byte)'>'); |
36 | 0 | book.setTitle_unsafe(plaintext()); |
37 | 0 | skipTo(italic); |
38 | 0 | book.setAuthor_unsafe(plaintext()); |
39 | 0 | skipTo(fontSize2); |
40 | 0 | book.setPublisher_unsafe(plaintext()); |
41 | 0 | skipTo(pound); |
42 | 0 | here -= pound.length; |
43 | 0 | book.setPrice_unsafe(plaintext()); |
44 | 0 | skipTo(width20); |
45 | 0 | skipTo((byte)'>'); |
46 | 0 | book.setFormat_unsafe(plaintext()); |
47 | 0 | skipTo(pubstatus); |
48 | 0 | skipTo((byte)'>'); |
49 | 0 | book.setDeliveryinfo_unsafe(plaintext()); |
50 | 0 | return book; |
51 | |
} |
52 | 0 | catch (ParseException e) { |
53 | |
|
54 | 0 | } |
55 | |
} |
56 | |
} |
57 | 0 | catch (ArrayIndexOutOfBoundsException e) { |
58 | |
} |
59 | 0 | catch (ParseException e) { |
60 | 0 | } |
61 | |
|
62 | 0 | return null; |
63 | |
} |
64 | |
|
65 | |
public static void main(String[] args) throws Exception { |
66 | 0 | BookStockingFactory dummy = |
67 | 0 | new BookStockingFactory() { |
68 | |
public BookStocking newStocking() { |
69 | 0 | return new BookStocking(); |
70 | |
} |
71 | |
}; |
72 | |
|
73 | 0 | SearchResults r = new SearchResults(IoUtils.slurp(new File(args[0]), 1000), |
74 | |
dummy); |
75 | |
|
76 | 0 | while (r.hasMoreElements()) { |
77 | 0 | ((BookStocking)r.nextElement()).dump(System.out); |
78 | 0 | System.out.println(); |
79 | |
} |
80 | 0 | } |
81 | |
} |