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