1 package org.paneris.bibliomania.metasearch.bol;
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
12 protected static final byte[]
13 seeAvailableTitles = "See available Titles".getBytes(),
14 bolprditmview = "&d=bolprditmview&PrdId=".getBytes(),
15 bolprice = "BOL price:".getBytes(),
16 bold = "<b>".getBytes(),
17 creatorid = "&CreatorId=".getBytes(),
18 size2 = "size=\"2\">".getBytes(),
19 cc0000 = "cc0000\">".getBytes();
20
21 public SearchResults(byte[] text,
22 BookStockingFactory stockings) {
23 super(text, stockings);
24 try {
25 skipTo(seeAvailableTitles);
26 }
27 catch (ArrayIndexOutOfBoundsException e) {}
28 }
29
30 protected Object more() {
31 try {
32 for (;;) {
33 skipTo(bolprditmview);
34 try {
35 BookStocking book = stockings.newStocking();
36
37
38 book.setDetailurl_unsafe("");
39
40 book.setVendorproductid_unsafe(digits());
41 skipTo(bold);
42 book.setTitle_unsafe(plaintext());
43 skipTo(cc0000);
44 book.setDeliveryinfo_unsafe(plaintext());
45
46
47 skipTo(creatorid);
48
49 skipTo((byte)'>');
50 book.setAuthor_unsafe(plaintext());
51 skipTo((byte)'|');
52
53
54
55
56
57
58 book.setFormat_unsafe(plaintext((byte)'|'));
59
60 book.setPublisher_unsafe(plaintext((byte)'|'));
61
62 book.setPublicationyear_unsafe(plaintext());
63
64 skipTo(bolprice);
65 skipTo(bold);
66 book.setPrice_unsafe(plaintext());
67 return book;
68 }
69 catch (ParseException e) {
70
71 }
72 }
73 }
74 catch (ArrayIndexOutOfBoundsException e) {
75 }
76 catch (ParseException e) {
77 }
78
79 return null;
80 }
81
82 public static void main(String[] args) throws Exception {
83 BookStockingFactory dummy =
84 new BookStockingFactory() {
85 public BookStocking newStocking() {
86 return new BookStocking();
87 }
88 };
89
90 SearchResults r = new SearchResults(IoUtils.slurp(new File(args[0]), 1000),
91 dummy);
92 while (r.hasMoreElements())
93 ((BookStocking)r.nextElement()).dump(System.out);
94 }
95 }