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