1 | |
package org.paneris.jammyjoes.controller; |
2 | |
|
3 | |
import java.util.Enumeration; |
4 | |
|
5 | |
import org.melati.Melati; |
6 | |
import org.melati.poem.NoSuchRowPoemException; |
7 | |
import org.melati.template.ServletTemplateContext; |
8 | |
import org.melati.util.StringUtils; |
9 | |
import org.paneris.jammyjoes.model.JammyjoesDatabase; |
10 | |
import org.paneris.jammyjoes.model.Product; |
11 | |
import org.paneris.jammyjoes.servlet.JammyJoesMelatiServlet; |
12 | |
|
13 | 0 | public class Toy extends JammyJoesMelatiServlet { |
14 | |
|
15 | |
private static final long serialVersionUID = 1L; |
16 | |
|
17 | |
protected String jammyjoesRequest(Melati melati, ServletTemplateContext context) |
18 | |
throws Exception { |
19 | |
|
20 | 0 | JammyjoesDatabase db = (JammyjoesDatabase) melati.getDatabase(); |
21 | 0 | String template = "view/Product.wm"; |
22 | |
|
23 | 0 | String[] pathInfo = melati.getPathInfoParts(); |
24 | |
|
25 | 0 | String troidString = pathInfo[0]; |
26 | 0 | if (troidString.endsWith(".html")) troidString = troidString.substring(0,troidString.length()-5); |
27 | 0 | Integer i = new Integer(troidString); |
28 | |
|
29 | |
try { |
30 | 0 | Product p = (Product)db.getProductTable().getObject(i); |
31 | 0 | if (pathInfo.length > 1) { |
32 | 0 | String next = pathInfo[1]; |
33 | 0 | if (next.equals("Next.html")) { |
34 | 0 | String basics = "stocklevel > 0 AND retailpriceincvat IS NOT NULL AND status = 0"; |
35 | 0 | Enumeration r = db.getProductTable().selection(basics + " AND name > " + q(p.getName()), null, false); |
36 | 0 | if (r.hasMoreElements()) { |
37 | 0 | p = (Product)r.nextElement(); |
38 | |
} else { |
39 | 0 | Enumeration s = db.getProductTable().selection(basics, null, false); |
40 | 0 | if (s.hasMoreElements()) p = (Product)s.nextElement(); |
41 | |
} |
42 | |
} |
43 | |
} |
44 | 0 | context.put("product",p); |
45 | 0 | } catch (NoSuchRowPoemException e) { |
46 | 0 | template = "view/RedirectHome.wm"; |
47 | 0 | } |
48 | 0 | return template; |
49 | |
} |
50 | |
|
51 | |
public String q(String name) { |
52 | 0 | StringBuffer b = new StringBuffer(); |
53 | 0 | StringUtils.appendQuoted(b, name, '\''); |
54 | 0 | return b.toString(); |
55 | |
} |
56 | |
|
57 | |
} |