Coverage Report - org.paneris.bibliomania.metasearch.amazon.SearchResults
 
Classes in this File Line Coverage Branch Coverage Complexity
SearchResults
0%
0/35
0%
0/2
2.5
SearchResults$1
0%
0/2
N/A
2.5
 
 1  
 package org.paneris.bibliomania.metasearch.amazon;
 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
       resultsSortedBy = "<div id=\"Results\" class=\"n2\">".getBytes(),
 14  0
       obidosASIN = "/dp/".getBytes(),
 15  0
       brBy = "</span></a>\n  \n  by ".getBytes(),
 16  0
       dotNL = ".\n".getBytes(),
 17  0
       spc3 = "   ".getBytes(),
 18  0
       spc2 = "  ".getBytes(),
 19  0
       slashTD = "</td>".getBytes(),
 20  0
       fontColor990000 = "<font color=#990000>".getBytes();
 21  
 
 22  
   public SearchResults(byte[] text,
 23  
                        BookStockingFactory stockings) {
 24  0
     super(text, stockings);
 25  0
     skipTo(resultsSortedBy);
 26  0
   }
 27  
 
 28  
   protected Object more() {
 29  
     try {
 30  
       for (;;) {
 31  0
         skipTo(obidosASIN);
 32  0
         skipTo(obidosASIN);
 33  
         try {
 34  0
           BookStocking bookStocking = stockings.newStocking();
 35  
 
 36  0
           bookStocking.setIsbn_unsafe(digits());
 37  0
           bookStocking.setVendorproductid_unsafe(bookStocking.getIsbn_unsafe());
 38  
 
 39  
           // we don't need this: it's computed from the ISBN = prod id
 40  0
           bookStocking.setDetailurl_unsafe("");
 41  
 
 42  0
           skipTo("\"srTitle\">".getBytes());
 43  0
           bookStocking.setTitle_unsafe(plaintext());
 44  
           /*
 45  
 
 46  
           skipTo(brBy);
 47  
 
 48  
           int author = here;
 49  
           skipTo(dotNL);
 50  
           bookStocking.setAuthor_unsafe(new String(text, author, here - author - 2));
 51  
 
 52  
           skipTo("\"binding\">".getBytes());
 53  
           int format = here;
 54  
           skipTo("</span>".getBytes());
 55  
           bookStocking.setFormat_unsafe(new String(text, format, here - format - 1));
 56  
           skipRealSpace();
 57  
           skipTo(")</span>".getBytes());
 58  
           int i = here - 7;
 59  
           while (text[i] == '\n' || text[i] == ' ') --i;
 60  
           bookStocking.setPublicationyear_unsafe(
 61  
               text[i] == ')' ? new String(text, i - 4, 4) : "");
 62  
 
 63  
           skipTo((byte)'$');
 64  
           --here;
 65  
           bookStocking.setPrice_unsafe(plaintext());
 66  
 
 67  
           skipTo(slashTD);
 68  
           skipTo(fontColor990000);
 69  
           bookStocking.setDeliveryinfo_unsafe(plaintext());
 70  
           */
 71  0
           System.err.println("Returning " + bookStocking);
 72  0
           return bookStocking;
 73  
         }
 74  0
         catch (ParseException e) {
 75  0
           System.err.println(e);
 76  
           // try again!
 77  0
         }
 78  
       }
 79  
     }
 80  0
     catch (ArrayIndexOutOfBoundsException e) {
 81  0
       System.err.println(e);
 82  
     }
 83  0
     catch (ParseException e) {
 84  0
       System.err.println(e);
 85  0
     }
 86  
 
 87  0
     return null;
 88  
   }
 89  
 
 90  
   public static void main(String[] args) throws Exception {
 91  0
       BookStockingFactory dummy =
 92  0
           new BookStockingFactory() {
 93  
             public BookStocking newStocking() {
 94  0
               return new BookStocking();
 95  
             }
 96  
           };
 97  
 
 98  0
     SearchResults r = new SearchResults(IoUtils.slurp(new File(args[0]), 1000),
 99  
                                         dummy);
 100  0
     while (r.hasMoreElements())
 101  0
       ((BookStocking)r.nextElement()).dump(System.out);
 102  0
   }
 103  
 }