| 1 | |
package org.paneris.bibliomania; |
| 2 | |
|
| 3 | |
import java.util.Enumeration; |
| 4 | |
|
| 5 | |
import org.melati.poem.AccessToken; |
| 6 | |
import org.melati.poem.PoemTask; |
| 7 | |
import org.melati.util.UnexpectedExceptionException; |
| 8 | |
import org.paneris.bibliomania.generated.BookStockingBase; |
| 9 | |
|
| 10 | |
import org.apache.oro.text.regex.MalformedPatternException; |
| 11 | |
import org.apache.oro.text.regex.Perl5Compiler; |
| 12 | |
import org.apache.oro.text.regex.Perl5Matcher; |
| 13 | |
import org.apache.oro.text.regex.Perl5Pattern; |
| 14 | |
|
| 15 | |
public class BookStocking extends BookStockingBase { |
| 16 | |
public BibliomaniaDatabase getBibliomaniaDatabase () { |
| 17 | 0 | return (BibliomaniaDatabase)getDatabase(); |
| 18 | |
} |
| 19 | |
|
| 20 | 0 | public BookStocking() {} |
| 21 | |
|
| 22 | |
public String getNotifyOfferedLinkHTML() { |
| 23 | 0 | return getShop().backend.notifiedOfferedLinkHTML(this); |
| 24 | |
} |
| 25 | |
|
| 26 | |
public String getProductURL() { |
| 27 | 0 | return getShop().backend.productURL(this); |
| 28 | |
} |
| 29 | |
|
| 30 | |
private static Perl5Pattern numberPattern; |
| 31 | |
|
| 32 | |
static { |
| 33 | |
try { |
| 34 | 0 | numberPattern = (Perl5Pattern)(new Perl5Compiler()).compile( |
| 35 | |
"([0-9]*\\.)[0-9]+", |
| 36 | |
Perl5Compiler.DEFAULT_MASK); |
| 37 | |
} |
| 38 | 0 | catch (MalformedPatternException e) { |
| 39 | 0 | throw new UnexpectedExceptionException(e); |
| 40 | 0 | } |
| 41 | 0 | } |
| 42 | |
|
| 43 | |
public void setPrice_unsafe(String price) { |
| 44 | 0 | super.setPrice_unsafe(price); |
| 45 | 0 | if (price == null) |
| 46 | 0 | pricenumber = null; |
| 47 | |
else { |
| 48 | 0 | Perl5Matcher matcher = new Perl5Matcher(); |
| 49 | 0 | if (matcher.contains(price, numberPattern)) { |
| 50 | |
try { |
| 51 | 0 | float p = Float.parseFloat(matcher.getMatch().toString()); |
| 52 | 0 | pricenumber = new Integer((int)(p * 100)); |
| 53 | |
} |
| 54 | 0 | catch (Exception e) { |
| 55 | 0 | pricenumber = null; |
| 56 | 0 | } |
| 57 | |
} |
| 58 | |
} |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public void setFormat_unsafe(String format) { |
| 62 | 0 | super.setFormat_unsafe(format); |
| 63 | 0 | if (format == null) |
| 64 | 0 | setFormatcode_unsafe(null); |
| 65 | 0 | else if (troid() != null) { |
| 66 | 0 | BookFormat code = getBibliomaniaDatabase().getBookFormatTable(). |
| 67 | |
formatOfDescription(format); |
| 68 | 0 | setFormatcode_unsafe(code == null ? null : code.troid()); |
| 69 | |
} |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
public void dump(java.io.PrintStream o) { |
| 73 | 0 | o.println("id: `" + id + "'\n" + |
| 74 | |
"shop: `" + shop + "'\n" + |
| 75 | |
"book: `" + book + "'\n" + |
| 76 | |
"title: `" + title + "'\n" + |
| 77 | |
"author: `" + author + "'\n" + |
| 78 | |
"vendorproductid: `" + vendorproductid + "'\n" + |
| 79 | |
"isbn: `" + isbn + "'\n" + |
| 80 | |
"deliveryinfo: `" + deliveryinfo + "'\n" + |
| 81 | |
"price: `" + price + "'\n" + |
| 82 | |
"pricenumber: `" + pricenumber + "'\n" + |
| 83 | |
"format: `" + format + "'\n" + |
| 84 | |
"publisher: `" + publisher + "'\n" + |
| 85 | |
"publicationyear: `" + publicationyear + "'\n" + |
| 86 | |
"detailurl: `" + detailurl + "'\n" + |
| 87 | |
"thumbnailurl: `" + thumbnailurl + "'"); |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
public static void main(String args[]) { |
| 91 | 0 | final BibliomaniaDatabase bib = new BibliomaniaDatabase(); |
| 92 | 0 | bib.connect("bibliomania","org.melati.poem.dbms.Postgresql", |
| 93 | |
"jdbc:postgresql:bibliomania", "postgres", "*",8); |
| 94 | |
|
| 95 | 0 | bib.inSession( |
| 96 | |
AccessToken.root, |
| 97 | 0 | new PoemTask() { |
| 98 | |
public void run() { |
| 99 | 0 | for (Enumeration e = bib.getBookStockingTable().selection(); |
| 100 | 0 | e.hasMoreElements();) { |
| 101 | 0 | BookStocking s = (BookStocking)e.nextElement(); |
| 102 | 0 | s.setFormat(s.getFormat_unsafe()); |
| 103 | 0 | } |
| 104 | 0 | } |
| 105 | |
}); |
| 106 | 0 | } |
| 107 | |
} |