View Javadoc

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