View Javadoc

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 new EmptyEnumeration();
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().interpolateTemplateToFile(
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 db = getBibliomaniaDatabase();
62  
63      final Table authorTable = db.getAuthorTable();
64      final Table bookTable = db.getBookTable();
65      if (authorsWithBooks == null) {
66        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      return new MappedEnumeration(authorsWithBooks.selection_firstRaw()) {
78        public Object mapped(Object troid) {
79          return authorTable.getObject((Integer)troid);
80        }
81      };
82    }
83  
84    public Enumeration getBooksSlowly() {
85      return getBibliomaniaDatabase()
86        .getBookTable()
87        .getSectionColumn()
88        .selectionWhereEq(troid());
89    }
90  
91    public String getDisplayName() {
92      return getDisplayname();
93    }
94  
95    public Enumeration getMembersSlowly() {
96      return getBooksSlowly();
97      // return getAuthorsWithBooks();
98    }
99  
100   public String adminHandle(Melati melati, MarkupLanguage markupLanguage)
101     throws Exception {
102     return null;
103   }
104 
105   public String adminSpecialFacilities(
106     Melati melati,
107     MarkupLanguage markupLanguage)
108     throws Exception {
109     return getBibliomaniaDatabase().getWMTemplet("Section-specials");
110   }
111 
112   public SectionGroup getReadArea() {
113     return getGroup();
114   }
115   public Advert getAdvert() {
116     Advert a = null;
117     return a;
118   }
119   /*
120     We want layouts at the section level now
121   
122     public Layout getLayout() {
123         Layout l = null;
124       return l;
125     }
126   */
127 
128   
129   /* 
130    * @see org.melati.util.Treeable#getChildren()
131    */
132   public Treeable[] children = null;
133    
134   public Treeable[] getChildren() {
135     if (children == null) {
136       Object[] kids = ArrayUtils.arrayOf(getAuthorsWithBooks());
137       children = new Treeable[kids.length];
138       for (int i=0; i<kids.length; i++) {
139         children[i] = (Treeable)kids[i];
140       }
141     }
142     return children;
143   }
144   /* 
145    * @see org.melati.util.Treeable#getName()
146    */
147   public String getName() {
148     return getDisplayName();
149   }
150 
151 
152 }