View Javadoc

1   package org.paneris.melati.site.model;
2   
3   import java.util.Enumeration;
4   import java.util.Vector;
5   
6   import org.melati.Melati;
7   import org.melati.admin.AdminSpecialised;
8   import org.melati.poem.CachedSelection;
9   import org.melati.poem.util.ArrayUtils;
10  import org.melati.poem.util.EmptyEnumeration;
11  import org.melati.template.MarkupLanguage;
12  import org.melati.util.StringUtils;
13  import org.melati.poem.Treeable;
14  import org.paneris.melati.site.model.generated.PageBase;
15  
16  /**
17   * Melati POEM generated, programmer modifiable stub for a
18   * <code>Persistent</code> <code>Page</code> object.
19   * 
20   * 
21   * <table>
22   * <tr>
23   * <th colspan='3'> Field summary for SQL table <code>Page</code> </th>
24   * </tr>
25   * <tr>
26   * <th>Name</th>
27   * <th>Type</th>
28   * <th>Description</th>
29   * </tr>
30   * <tr>
31   * <td> fsname </td>
32   * <td> String </td>
33   * <td> A file system name, no spaces or special characters </td>
34   * </tr>
35   * <tr>
36   * <td> deleted </td>
37   * <td> Boolean </td>
38   * <td> Whether or not to include this Unit </td>
39   * </tr>
40   * <tr>
41   * <td> lastencached </td>
42   * <td> Timestamp </td>
43   * <td> When the unit was encached; cleared when the unit is updated </td>
44   * </tr>
45   * <tr>
46   * <td> layout </td>
47   * <td> Layout </td>
48   * <td> The name of the layout for this Unit </td>
49   * </tr>
50   * <tr>
51   * <td> messageboard </td>
52   * <td> Board </td>
53   * <td> A messageboard on which this unit can be discussed </td>
54   * </tr>
55   * </table>
56   * 
57   * @generator org.melati.poem.prepro.TableDef#generateMainJava
58   */
59  public class Page extends PageBase implements AdminSpecialised, Treeable,
60      Templated {
61  
62    /**
63     * Constructor for a <code>Persistent</code> <code>Page</code> object.
64     * 
65     * @generator org.melati.poem.prepro.TableDef#generateMainJava
66     */
67    public Page() {
68    }
69  
70    // programmer's domain-specific code here
71  
72    /**
73     * @return the database
74     */
75    public SiteDatabaseTables getSiteDatabase() {
76      return (SiteDatabaseTables) getDatabase();
77    }
78  
79    /**
80     * @return a string with non breaking space for spaces
81     */
82    /*
83     * public String getDisplayName() { return super.getDisplayname().replace("
84     * ","&nbsp;"); }
85     */
86    /**
87     * @return an Enumeration of ancestors
88     */
89    public Enumeration getAncestors() {
90      Vector v = new Vector();
91      Page p = getParent();
92      while (p != null) {
93        v.addElement(p);
94        p = p.getParent();
95      }
96      Vector reversed = new Vector();
97      for (Enumeration e = v.elements(); e.hasMoreElements();) {
98        reversed.insertElementAt(e.nextElement(), 0);
99      }
100     return reversed.elements();
101   }
102 
103   /**
104    * @return the numeric url
105    */
106   public String getRelativeDisplayUrlById() {
107     return "Display/page/" + troid() + ".html";
108   }
109 
110   /**
111    * @return the name with underscores for spaces and a file extension added.
112    */
113   public String getRelativeDisplayUrlByContent() {
114     return getUrlName() + ".html";
115   }
116   /**
117    * @return the name with underscores for spaces and a file extension added.
118    */
119   public String getUrlName() {
120     return StringUtils.tr(getDisplayname(), ' ', '_');
121   }
122   /**
123    * @return the name with underscores for spaces and a file extension added.
124    */
125   public String getJavaName() {
126     return StringUtils.tr(getUrlName(), '-', '_');
127   }
128 
129   /**
130    * XML does not allow forward slashes in Ids, so we use periods.
131    * 
132    * @return The table name, a period followed by the troid.
133    */
134   public String getXmlId() {
135     return StringUtils.tr(toString(), '/', '.');
136   }
137 
138   private CachedSelection divs = null;
139 
140   /**
141    * @return the divs
142    */
143   public Enumeration getDivs() {
144     if (getTroid() == null)
145       return EmptyEnumeration.it;
146     else {
147       if (divs == null)
148         divs = getSiteDatabase().getDivTable().getPageColumn()
149             .cachedSelectionWhereEq(getTroid());
150       return divs.objects();
151     }
152   }
153 
154   /*
155    * @see org.melati.util.Treeable#getChildren()
156    */
157 
158   public Treeable[] getChildren() {
159     Treeable[] children = null;
160     Object[] kids = ArrayUtils.arrayOf(getPageTable().getParentColumn()
161         .referencesTo(this));
162     int j = 0;
163     for (int i = 0; i < kids.length; i++) {
164       if (((Page) kids[i]).getDisplay().booleanValue()) {
165         j++;
166       }
167     }
168     children = new Treeable[j];
169     int k = 0;
170     for (int i = 0; i < kids.length; i++) {
171       if (((Page) kids[i]).getDisplay().booleanValue()) {
172         children[k] = (Treeable) kids[i];
173         k++;
174       }
175     }
176     return children;
177   }
178 
179   public String adminHandle(Melati melati, MarkupLanguage markupLanguage)
180       throws Exception {
181     return null;
182   }
183 
184   public String adminSpecialFacilities(Melati melati,
185       MarkupLanguage markupLanguage) throws Exception {
186     return "org/paneris/melati/site/model/Page.adminSpecial.wm";
187   }
188 
189 
190 }