1 package org.paneris.rimauresq;
2
3 import org.melati.Melati;
4 import org.melati.PoemContext;
5 import org.melati.poem.Column;
6 import org.melati.poem.Persistent;
7 import org.melati.poem.Table;
8 import org.melati.servlet.PathInfoException;
9 import org.melati.template.ServletTemplateContext;
10 import org.melati.util.StringUtils;
11 import org.paneris.melati.site.SiteServlet;
12
13 import org.paneris.rimauresq.model.RimauresqDatabase;
14
15
16
17
18
19 public abstract class RimauresqServlet extends SiteServlet {
20
21
22 private static final String STATIC_ROOT = "/dist/rimauresq/rimauresq-webapp/src/main/webapp/";
23
24 private static String DB_NAME = "rimauresq";
25
26
27
28
29 public String getSTATIC_ROOT() {
30 return STATIC_ROOT;
31 }
32
33
34
35
36 public String getDB_NAME() {
37 return DB_NAME;
38 }
39
40
41
42
43
44
45
46 protected String reallyDoTemplateRequest(Melati melati,
47 ServletTemplateContext templateContext)
48 throws Exception {
49 templateContext.put("homePage", ((RimauresqDatabase) melati.getDatabase())
50 .getHomePage());
51 String newsAdminName = getSetting(melati, "NewsAdminName");
52 String newsAdminEmail = getSetting(melati, "NewsAdminEmail");
53 templateContext.put("newsAdminName", newsAdminName);
54 templateContext.put("newsAdminEmail", newsAdminEmail);
55 return doRimauresqTemplateRequest(melati, templateContext);
56 }
57
58 protected PoemContext poemContext(Melati melati)
59 throws PathInfoException {
60
61 PoemContext it = new PoemContext();
62
63 String initParameterPathInfo = getInitParameter("pathinfo");
64 String[] parts;
65 if (initParameterPathInfo != null) {
66 parts = StringUtils.split(initParameterPathInfo, '/');
67 } else {
68 parts = melati.getPathInfoParts();
69 }
70
71 it.setLogicalDatabase("");
72 if (parts.length > 0) {
73 it.setLogicalDatabase(parts[0]);
74
75
76
77 if (parts.length == 2)
78 it.setMethod(parts[1]);
79
80
81
82 if (parts.length == 3) {
83 String r = parts[2];
84 if (r.lastIndexOf(".htm") != -1) {
85 r = r.substring(0, r.lastIndexOf(".htm"));
86
87 }
88 it.setTable(parts[1]);
89 try {
90 it.setTroid(new Integer(r));
91 } catch (NumberFormatException e) {
92 it.setMethod(parts[2]);
93 }
94
95
96 }
97
98
99
100
101
102 if (parts.length == 4) {
103 it.setTable(parts[1]);
104 try {
105 it.setTroid(new Integer(parts[2]));
106 } catch (NumberFormatException e) {
107 String r = parts[2];
108 if (r.lastIndexOf(".htm") != -1) {
109 r = r.substring(0, r.lastIndexOf(".htm"));
110 }
111 String value = StringUtils.tr(r, '.', ' ');
112 value = StringUtils.tr(r, '_', ' ');
113 Table t = melati.getTable();
114 if (t != null) {
115 Column c = t.primaryCriterionColumn();
116 if (c == null)
117 throw new NullPointerException("primaryCriterionColumn null");
118 Persistent o = c.firstWhereEq(value);
119 if (o != null)
120 it.setTroid(o.troid());
121 }
122 }
123 it.setMethod(parts[3]);
124 }
125
126
127
128
129
130
131
132
133
134
135 }
136 return it;
137 }
138
139
140
141
142
143
144 protected abstract String doRimauresqTemplateRequest(Melati melati,
145 ServletTemplateContext templateContext)
146 throws Exception;
147
148 }