View Javadoc

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   * Melati POEM generated, programmer modifiable stub 
12   * for a <code>DivTable</code> object.
13   * <p>
14   * Description: 
15   *   An HTML fragment. 
16   * </p>
17   *
18   * 
19   * <table> 
20   * <tr><th colspan='3'>
21   * Field summary for SQL table <code>Div</code>
22   * </th></tr>
23   * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
24   * <tr><td> id </td><td> Integer </td><td> &nbsp; </td></tr> 
25   * <tr><td> page </td><td> Page </td><td> The Page to which this fragment 
26   * belongs </td></tr> 
27   * <tr><td> displayorder </td><td> Integer </td><td> A rank determining where 
28   * the div appears in a page </td></tr> 
29   * <tr><td> style </td><td> Style </td><td> The name of the CSS class for 
30   * this DIV </td></tr> 
31   * <tr><td> title </td><td> String </td><td> The HTML title </td></tr> 
32   * <tr><td> content </td><td> String </td><td> The HTML content </td></tr> 
33   * </table> 
34   * 
35   * @generator  org.melati.poem.prepro.TableDef#generateTableMainJava 
36   */
37  public class DivTable extends DivTableBase {
38  
39   /**
40    * Constructor.
41    * 
42    * @generator org.melati.poem.prepro.TableDef#generateTableMainJava 
43    * @param database          the POEM database we are using
44    * @param name              the name of this <code>Table</code>
45    * @param definitionSource  which definition is being used
46    * @throws PoemException    if anything goes wrong
47    */
48    public DivTable(
49        Database database, String name,
50        DefinitionSource definitionSource) throws PoemException {
51      super(database, name, definitionSource);
52    }
53  
54    // programmer's domain-specific code here
55  
56    /**
57     * Create or retrieve existing div by name.
58     * 
59     * @return the existing or newly created object
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     * @return existing or newly minted Div 
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     * Make sure that a Div exists, creating it if necessary.
77     * 
78     * @param page page that owns this Div, may be null
79     * @return the existing or newly created Div
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    * Create an ipsum record
110    * 
111    * @return the existing or newly created object
112    */
113 
114   public Div ensure(Page page) {
115     Style s = ((SiteDatabaseTables)getDatabase()).getStyleTable().ensure("ipsum");
116     return ensure(page,s);
117   }
118   /**
119    * Create or retrieve existing div by name.
120    * 
121    * @return the existing or newly created object
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 }