1 package org.paneris.bibliomania;
2
3 import java.io.File;
4 import java.util.Enumeration;
5
6 import org.melati.Melati;
7 import org.melati.admin.AdminSpecialised;
8 import org.melati.poem.CachedTailoredQuery;
9 import org.melati.poem.Column;
10 import org.melati.poem.Table;
11 import org.melati.template.MarkupLanguage;
12 import org.melati.poem.util.ArrayUtils;
13 import org.melati.poem.util.EmptyEnumeration;
14 import org.melati.poem.util.MappedEnumeration;
15 import org.melati.poem.Treeable;
16 import org.paneris.bibliomania.generated.SectionBase;
17
18 public class Section extends SectionBase implements AdminSpecialised {
19
20 public Enumeration getProductAssociations() {
21 return EmptyEnumeration.it;
22 }
23
24 public String getMetatag_description() {
25 return null;
26 }
27
28 public String getMetatag_keywords() {
29 return null;
30 }
31
32 public long ftiTextID_start() {
33 return Chapter.ftiTextID(troid().intValue(), 0, 0, 0);
34 }
35
36 public long ftiTextID_limit() {
37 return ftiTextID_start() | ((1L << Chapter.ftiTextID_section_shift) - 1);
38 }
39
40 public Unit getParentUnit() {
41 return getGroup();
42 }
43
44 public void appendCacheSubpath(StringBuffer buffer) {
45 buffer.append("/s/");
46 buffer.append(troid());
47 }
48
49 public void encache() throws Exception {
50 super.encache();
51
52 getBibliomaniaDatabase().templateExpandNamed(
53 "read/Section.wm",
54 new File(getCachePath(), "index.html"),
55 this);
56 }
57
58 private CachedTailoredQuery authorsWithBooks = null;
59
60 public Enumeration getAuthorsWithBooks() {
61 BibliomaniaDatabase b = getBibliomaniaDatabase();
62
63 if (authorsWithBooks == null) {
64 authorsWithBooks =
65 new CachedTailoredQuery(
66 "DISTINCT",
67 new Column[] { b.getAuthorTable().troidColumn()},
68 new Table[] { b.getBookTable()},
69 "book.author = author.id AND book.section = " + troid(),
70 null);
71 }
72
73 final Table authorTable = b.getAuthorTable();
74 return new MappedEnumeration(authorsWithBooks.selection_firstRaw()) {
75 public Object mapped(Object troid) {
76 return authorTable.getObject((Integer)troid);
77 }
78 };
79 }
80
81 public Enumeration getBooksSlowly() {
82 return getBibliomaniaDatabase()
83 .getBookTable()
84 .getSectionColumn()
85 .selectionWhereEq(troid());
86 }
87
88 public String getDisplayName() {
89 return getDisplayname();
90 }
91
92 public Enumeration getMembersSlowly() {
93 return getBooksSlowly();
94
95 }
96
97 public String adminHandle(Melati melati, MarkupLanguage markupLanguage)
98 throws Exception {
99 return null;
100 }
101
102 public String adminSpecialFacilities(
103 Melati melati,
104 MarkupLanguage markupLanguage)
105 throws Exception {
106 return getWMTemplet("Section-specials");
107 }
108
109 public SectionGroup getReadArea() {
110 return getGroup();
111 }
112 public Advert getAdvert() {
113 Advert a = null;
114 return a;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129 public Treeable[] children = null;
130
131 public Treeable[] getChildren() {
132 if (children == null) {
133 Object[] kids = ArrayUtils.arrayOf(getAuthorsWithBooks());
134 children = new Treeable[kids.length];
135 for (int i=0; i<kids.length; i++) {
136 children[i] = (Treeable)kids[i];
137 }
138 }
139 return children;
140 }
141
142
143
144 public String getName() {
145 return getDisplayName();
146 }
147
148
149 }