1
2
3
4
5
6
7
8
9
10
11 package org.paneris.melati.site;
12
13 import org.melati.Melati;
14 import org.melati.poem.Persistent;
15 import org.melati.poem.Column;
16 import org.melati.PoemContext;
17 import org.melati.template.ServletTemplateContext;
18 import org.melati.util.StringUtils;
19 import org.paneris.melati.site.model.Template;
20 import org.paneris.melati.site.model.Templated;
21 import org.paneris.melati.site.model.HasGetTemplateUrl;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class Display extends SiteServlet {
53
54
55
56
57 private static final long serialVersionUID = 1L;
58
59 protected String reallyDoTemplateRequest(Melati melati,
60 ServletTemplateContext context)
61 throws Exception {
62
63 PoemContext pc = melati.getPoemContext();
64 String method = pc.getMethod();
65
66 Persistent object = melati.getObject();
67
68 if (object != null) {
69 object.assertCanRead();
70 context.put("object", object);
71 }
72 if (method != null && !method.equals("") &&
73 melati.getTable() != null) {
74 if (method.lastIndexOf(".htm") != -1) {
75 method = method.substring(0,method.lastIndexOf(".htm"));
76 }
77
78 if (melati.getObject() == null) {
79 Integer id = null;
80 try {
81 id = new Integer(method);
82 }
83 catch (NumberFormatException e) {
84 if (melati.getTable() != null) {
85 String value = StringUtils.tr(method,'.', ' ');
86 value = StringUtils.tr(method,'_', ' ');
87 Column search = melati.getTable().primaryCriterionColumn();
88 Persistent o = search.firstWhereEq(value);
89 if (o != null) id = o.troid();
90 }
91 }
92 if (id != null) {
93 melati.getPoemContext().setTroid(id);
94 melati.getPoemContext().setMethod(null);
95 }
96 melati.loadTableAndObject();
97 if (melati.getObject() != null) {
98 object = melati.getObject();
99 object.assertCanRead();
100 context.put("object", object);
101 if (object instanceof Templated) {
102 Template t = ((Templated)object).getTemplate();
103 String url = null;
104 if (t != null) url = t.getUrl();
105 if (url != null) {
106 System.err.println("returning url:" + url);
107 return url;
108 } else {
109 System.err.println("url null");
110 }
111 } else {
112 System.err.println("not templated:" +object.getClass().getName());
113 }
114 System.err.println("return 1 - really");
115 return StringUtils.capitalised(melati.getTable().getName());
116
117 } else {
118 System.err.println("return 2");
119 return method;
120 }
121 } else {
122 System.err.println("return 3");
123 return method;
124 }
125 }
126 if (context.getForm("template") != null) {
127 System.err.println("return 4");
128 return context.getForm("template");
129 }
130 if (object != null && object instanceof Templated) {
131 Template t = ((Templated)object).getTemplate();
132 String url = null;
133 if(t != null) url = t.getUrl();
134 if (url != null) return url;
135 return StringUtils.capitalised(melati.getTable().getName());
136 }
137 if (object != null && object instanceof HasGetTemplateUrl) {
138 String t = ((HasGetTemplateUrl)melati.getObject()).getTemplateUrl();
139 if (t != null) return t;
140 return StringUtils.capitalised(melati.getTable().getName());
141 }
142 return "Display";
143 }
144
145 }