1 package org.paneris.melati.site.model;
2
3 import java.util.Enumeration;
4
5 import org.paneris.melati.site.model.generated.DivTableBase;
6 import org.melati.poem.DefinitionSource;
7 import org.melati.poem.Database;
8 import org.melati.poem.PoemException;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class DivTable extends DivTableBase {
38
39
40
41
42
43
44
45
46
47
48 public DivTable(
49 Database database, String name,
50 DefinitionSource definitionSource) throws PoemException {
51 super(database, name, definitionSource);
52 }
53
54
55
56
57
58
59
60
61
62 public Div ensure(Page page, String title, String content) {
63 Style s = ((SiteDatabaseTables)getDatabase()).getStyleTable().ensure("default");
64 return ensure(page, s, title, content);
65 }
66
67
68
69 public Div ensure(Page page, String styleName, String title, String content) {
70 Style s = ((SiteDatabaseTables)getDatabase()).getStyleTable().ensure(styleName);
71 return ensure(page, s, title, content);
72 }
73
74
75
76
77
78
79
80
81 public Div ensure(Page page, Style style, String title, String content) {
82 Div q = (Div)newPersistent();
83 q.setPage(page);
84 q.setTitle(title);
85 Div p = (Div)firstSelection(whereClause(q));
86 if (p == null) {
87 p = (Div)newPersistent();
88 if (page != null) {
89 p.setPage(page);
90 Enumeration e = getPageColumn().selectionWhereEq(page.troid());
91 int c = 0;
92 while (e.hasMoreElements()) {
93 e.nextElement();
94 c++;
95 }
96 p.setDisplayorder(c);
97 }
98 else
99 p.setDisplayorder(1);
100 p.setStyle(style);
101 p.setTitle(title);
102 p.setContent(content);
103 p.makePersistent();
104 }
105 return p;
106 }
107
108
109
110
111
112
113
114 public Div ensure(Page page) {
115 Style s = ((SiteDatabaseTables)getDatabase()).getStyleTable().ensure("ipsum");
116 return ensure(page,s);
117 }
118
119
120
121
122
123
124 public Div ensure(Page page, Style style) {
125 Div p = (Div)getPageColumn().firstWhereEq(page.troid());
126 if (p == null) {
127 p = ensure(page, style, "Lorem Ipsum",
128 "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>");
129 }
130 return p;
131 }
132
133 }