| 1 | |
package org.paneris.bibliomania; |
| 2 | |
|
| 3 | |
import java.util.Locale; |
| 4 | |
|
| 5 | |
import javax.servlet.ServletConfig; |
| 6 | |
import javax.servlet.ServletException; |
| 7 | |
|
| 8 | |
import org.melati.Melati; |
| 9 | |
import org.melati.servlet.Form; |
| 10 | |
import org.melati.poem.BaseFieldAttributes; |
| 11 | |
import org.melati.poem.Field; |
| 12 | |
import org.melati.poem.FieldAttributes; |
| 13 | |
import org.melati.template.ServletTemplateContext; |
| 14 | |
import org.melati.util.MelatiException; |
| 15 | |
import org.paneris.bibliomania.shopping.BibliomaniaShoppingTrolley; |
| 16 | |
import org.paneris.melati.shopping.MelatiShoppingConfig; |
| 17 | |
import org.paneris.melati.shopping.ShoppingTrolley; |
| 18 | |
import org.webmacro.servlet.WebContext; |
| 19 | |
|
| 20 | 0 | public class Shop extends BibliomaniaServlet { |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
private static final long serialVersionUID = 1L; |
| 26 | |
MelatiShoppingConfig config; |
| 27 | |
BibliomaniaDatabase db; |
| 28 | |
|
| 29 | |
protected String bibliomaniaHandle(Melati melati, WebContext context) |
| 30 | |
throws Exception { |
| 31 | |
|
| 32 | 0 | ServletTemplateContext tc = melati.getServletTemplateContext(); |
| 33 | 0 | db = (BibliomaniaDatabase)melati.getDatabase(); |
| 34 | 0 | if (Form.getFieldNulled(tc, "login") != null) { |
| 35 | 0 | assertRegisteredUser(db); |
| 36 | |
} |
| 37 | 0 | BibliomaniaShoppingTrolley trolley = |
| 38 | |
(BibliomaniaShoppingTrolley)ShoppingTrolley.getInstance(melati, config); |
| 39 | 0 | BibContext bibcontext = (BibContext)melati.getPoemContext(); |
| 40 | 0 | User user = (User)melati.getUser(); |
| 41 | |
|
| 42 | 0 | Locale locale = null; |
| 43 | 0 | Currency currency = null; |
| 44 | 0 | if (context.getForm("changelocale") != null) { |
| 45 | 0 | currency = |
| 46 | |
(Currency)db.getCurrencyTable().getObject( |
| 47 | |
Form.getIntegerField(tc, "field_currency")); |
| 48 | 0 | locale = currency.toLocale(); |
| 49 | 0 | trolley.setLocale(locale); |
| 50 | |
} else { |
| 51 | 0 | locale = trolley.getLocale(); |
| 52 | |
} |
| 53 | 0 | currency = trolley.getCurrency(); |
| 54 | 0 | if (user.isRegisteredUser(db)) |
| 55 | 0 | user.setCurrency(currency); |
| 56 | 0 | context.put( |
| 57 | |
"currencies", |
| 58 | |
new Field( |
| 59 | |
currency.getTroid(), |
| 60 | |
new BaseFieldAttributes( |
| 61 | |
(FieldAttributes) ((UserTable)db.getUserTable()).getCurrencyColumn(), |
| 62 | |
false))); |
| 63 | 0 | context.put("currency", currency); |
| 64 | 0 | context.put( |
| 65 | |
"acceptlanguage", |
| 66 | |
melati.getRequest().getHeader("accept-language")); |
| 67 | 0 | context.put("trolley", trolley); |
| 68 | 0 | db.setupContext(melati, context, (Unit)melati.getObject()); |
| 69 | 0 | String template = "shopping/"; |
| 70 | 0 | template += bibcontext.getTable().substring(0, 1).toUpperCase() |
| 71 | |
+ bibcontext.getTable().substring(1, bibcontext.getTable().length()) |
| 72 | |
+ ".wm"; |
| 73 | 0 | return template; |
| 74 | |
} |
| 75 | |
|
| 76 | |
public void init(ServletConfig conf) throws ServletException { |
| 77 | 0 | super.init(conf); |
| 78 | |
try { |
| 79 | 0 | config = new MelatiShoppingConfig(); |
| 80 | 0 | } catch (MelatiException e) { |
| 81 | 0 | throw new ServletException(e.toString()); |
| 82 | 0 | } |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
} |