| 1 | |
package org.paneris.bibliomania.metasearch.bol; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.FileNotFoundException; |
| 5 | |
import java.io.IOException; |
| 6 | |
import java.net.URL; |
| 7 | |
import java.util.Enumeration; |
| 8 | |
|
| 9 | |
import org.melati.poem.transaction.ToTidyList; |
| 10 | |
import org.melati.util.IoUtils; |
| 11 | |
import org.melati.util.UTF8URLEncoder; |
| 12 | |
import org.paneris.bibliomania.BookStocking; |
| 13 | |
import org.paneris.bibliomania.metasearch.BOLAndBOBBackendBase; |
| 14 | |
import org.paneris.bibliomania.metasearch.BookPageBase; |
| 15 | |
import org.paneris.bibliomania.metasearch.BookStockingFactory; |
| 16 | |
|
| 17 | |
import com.sleepycat.db.DatabaseException; |
| 18 | |
|
| 19 | |
public class Backend extends BOLAndBOBBackendBase { |
| 20 | |
|
| 21 | |
public Backend(File dbHome, int isbnOfPrdidCacheSize) |
| 22 | |
throws FileNotFoundException, DatabaseException { |
| 23 | 0 | super( |
| 24 | |
dbHome, |
| 25 | |
"bol_isbnAndImageOfPrdid.db", |
| 26 | |
isbnOfPrdidCacheSize, |
| 27 | |
"http://www.uk.bol.com"); |
| 28 | 0 | } |
| 29 | |
|
| 30 | |
public String productURL_nonaffil(BookStocking stocking) { |
| 31 | 0 | return "http://www.uk.bol.com/cec/cstage?ecaction=boldlprdview&" |
| 32 | |
+ "PrdId=" |
| 33 | |
+ stocking.getVendorproductid_unsafe(); |
| 34 | |
} |
| 35 | |
|
| 36 | |
public byte[] productPage_nonaffil(BookStocking stocking) |
| 37 | |
throws IOException { |
| 38 | 0 | return IoUtils.slurp(new URL(productURL_nonaffil(stocking)), 32768, 100000); |
| 39 | |
} |
| 40 | |
|
| 41 | |
protected BookPageBase bookPage(byte[] text) { |
| 42 | 0 | return new BookPage(text); |
| 43 | |
} |
| 44 | |
|
| 45 | 0 | private int bfmid = 1389056; |
| 46 | 0 | private int siteid = 29472511; |
| 47 | |
|
| 48 | |
private String bfastURL(String op, String prdId) { |
| 49 | 0 | return "http://service.bfast.com/bfast/" |
| 50 | |
+ op |
| 51 | |
+ "?" |
| 52 | |
+ "bfmid=" |
| 53 | |
+ bfmid |
| 54 | |
+ "&siteid=" |
| 55 | |
+ siteid |
| 56 | |
+ "&" |
| 57 | |
+ "bfpid=0&" |
| 58 | |
+ |
| 59 | |
|
| 60 | |
"bfmtype=B&PrdId=" + prdId; |
| 61 | |
} |
| 62 | |
|
| 63 | |
public String notifyOfferedLinkHTML(String prdId) { |
| 64 | 0 | return "<IMG SRC=\"" |
| 65 | |
+ bfastURL("serve", prdId) |
| 66 | |
+ "\" " |
| 67 | |
+ "BORDER=0 WIDTH=1 HEIGHT=1 NOSAVE>"; |
| 68 | |
} |
| 69 | |
|
| 70 | |
public String productURL(String prdId) { |
| 71 | 0 | return bfastURL("click", prdId); |
| 72 | |
} |
| 73 | |
|
| 74 | |
public String productURL(BookStocking stocking) { |
| 75 | 0 | return productURL(stocking.getVendorproductid_unsafe()); |
| 76 | |
} |
| 77 | |
|
| 78 | |
public String notifiedOfferedLinkHTML(BookStocking stocking) { |
| 79 | 0 | return notifyOfferedLinkHTML(stocking.getVendorproductid_unsafe()); |
| 80 | |
} |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
public String thumbnailURL(String isbn) { |
| 87 | 0 | return "http://www.uk.bol.com/multimedia/image/bookcover/" |
| 88 | |
+ "thumb" |
| 89 | |
+ isbn |
| 90 | |
+ ".gif"; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public String searchURL( |
| 94 | |
String title, |
| 95 | |
String author, |
| 96 | |
String publisher, |
| 97 | |
String keyword) { |
| 98 | 0 | return "http://www.uk.bol.com/cec/cstage?ecaction=booksearch" |
| 99 | |
+ "&prdTmp=b_src_mainresults_top.uk.htm" |
| 100 | |
+ "&startnum=1&increment=20&count=0" |
| 101 | |
+ "&query_type=BS_SIMPLE" |
| 102 | |
+ "&title_ent=" |
| 103 | |
+ (title == null ? "" : UTF8URLEncoder.encode(title)) |
| 104 | |
+ "&author_ent=" |
| 105 | |
+ (author == null ? "" : UTF8URLEncoder.encode(author)) |
| 106 | |
+ "&publisher_ent=" |
| 107 | |
+ (publisher == null ? "" : UTF8URLEncoder.encode(publisher)) |
| 108 | |
+ "&keyword_ent=" |
| 109 | |
+ (keyword == null ? "" : UTF8URLEncoder.encode(keyword)) |
| 110 | |
+ "&keyword_option=ALL_KEYWORDS"; |
| 111 | |
} |
| 112 | |
|
| 113 | |
public Enumeration booksMatching( |
| 114 | |
BookStockingFactory stockings, |
| 115 | |
String title, |
| 116 | |
String author, |
| 117 | |
String publisher, |
| 118 | |
String keyword, |
| 119 | |
ToTidyList toTidy) |
| 120 | |
throws IOException { |
| 121 | |
|
| 122 | 0 | return new SearchResults( |
| 123 | |
IoUtils.slurp( |
| 124 | |
new URL(searchURL(title, author, publisher, keyword)), |
| 125 | |
65536), |
| 126 | |
stockings); |
| 127 | |
} |
| 128 | |
} |