View Javadoc

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        return (BibliomaniaDatabase)getDatabase();
18    }
19  
20    public BookStocking() {}
21  
22    public String getNotifyOfferedLinkHTML() {
23      return getShop().backend.notifiedOfferedLinkHTML(this);
24    }
25  
26    public String getProductURL() {
27      return getShop().backend.productURL(this);
28    }
29  
30    private static Perl5Pattern numberPattern;
31  
32    static {
33      try {
34        numberPattern = (Perl5Pattern)(new Perl5Compiler()).compile(
35                                           "([0-9]*\\.)[0-9]+",
36                                           Perl5Compiler.DEFAULT_MASK);
37      }
38      catch (MalformedPatternException e) {
39        throw new UnexpectedExceptionException(e);
40      }
41    }
42  
43    public void setPrice_unsafe(String price) {
44      super.setPrice_unsafe(price);
45      if (price == null)
46        pricenumber = null;
47      else {
48        Perl5Matcher matcher = new Perl5Matcher();
49        if (matcher.contains(price, numberPattern)) {
50          try {
51            float p = Float.parseFloat(matcher.getMatch().toString());
52            pricenumber = new Integer((int)(p * 100));
53          }
54          catch (Exception e) {
55            pricenumber = null;
56          }
57        }
58      }
59    }
60  
61    public void setFormat_unsafe(String format) {
62      super.setFormat_unsafe(format);
63      if (format == null)
64        setFormatcode_unsafe(null);
65      else if (troid() != null) {
66        BookFormat code = getBibliomaniaDatabase().getBookFormatTable().
67                              formatOfDescription(format);
68        setFormatcode_unsafe(code == null ? null : code.troid());
69      }
70    }
71  
72    public void dump(java.io.PrintStream o) {
73      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    }
89  
90    public static void main(String args[]) {
91      final BibliomaniaDatabase bib = new BibliomaniaDatabase();
92      bib.connect("bibliomania","org.melati.poem.dbms.Postgresql",
93                  "jdbc:postgresql:bibliomania", "postgres", "*",8);
94  
95      bib.inSession(
96          AccessToken.root,
97          new PoemTask() {
98            public void run() {
99              for (Enumeration e = bib.getBookStockingTable().selection();
100                  e.hasMoreElements();) {
101               BookStocking s = (BookStocking)e.nextElement();
102               s.setFormat(s.getFormat_unsafe());
103             }            
104           }
105         });
106   }
107 }