View Javadoc

1   package org.paneris.melati.site.model;
2   
3   import org.paneris.melati.site.model.generated.TemplateTableBase;
4   import org.melati.poem.DefinitionSource;
5   import org.melati.poem.Database;
6   import org.melati.poem.PoemException;
7   
8   /**
9    * Melati POEM generated, programmer modifiable stub 
10   * for a <code>TemplateTable</code> object.
11   * <p>
12   * Description: 
13   *   A page template, used to control HTML fragment layout. 
14   * </p>
15   *
16   * 
17   * <table> 
18   * <tr><th colspan='3'>
19   * Field summary for SQL table <code>Template</code>
20   * </th></tr>
21   * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
22   * <tr><td> id </td><td> Integer </td><td> &nbsp; </td></tr> 
23   * <tr><td> displayname </td><td> String </td><td> The layout's name 
24   * </td></tr> 
25   * <tr><td> pathname </td><td> String </td><td> Path in the file system 
26   * relative to template root </td></tr> 
27   * </table> 
28   * 
29   * @generator  org.melati.poem.prepro.TableDef#generateTableMainJava 
30   */
31  public class TemplateTable extends TemplateTableBase {
32  
33   /**
34    * Constructor.
35    * 
36    * @generator org.melati.poem.prepro.TableDef#generateTableMainJava 
37    * @param database          the POEM database we are using
38    * @param name              the name of this <code>Table</code>
39    * @param definitionSource  which definition is being used
40    * @throws PoemException    if anything goes wrong
41    */
42    public TemplateTable(
43        Database database, String name,
44        DefinitionSource definitionSource) throws PoemException {
45      super(database, name, definitionSource);
46    }
47  
48    // programmer's domain-specific code here
49    /**
50     * Create or retrieve existing Template by name.
51     * 
52     * @return the existing or newly created object
53     */
54    public Template ensure(String displayName, String url) {
55      Template p = (Template)getDisplaynameColumn().firstWhereEq(displayName);
56      if (p == null) {
57        p = (Template)newPersistent();
58        p.setDisplayname(displayName);
59        p.setDescription(displayName);
60        p.setUrl(url);
61        p.setType(((SiteDatabaseTables)getDatabase()).getUploadedFileTypeTable().ensure("wm"));
62        p.makePersistent();
63      }
64      return p;
65    }
66    
67  }