View Javadoc

1   package org.paneris.melati.site.model;
2   
3   import org.paneris.melati.site.model.generated.UploadedImageTableBase;
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>UploadedImageTable</code> object.
11   * <p>
12   * Description: 
13   *   An image uploaded by a user. 
14   * </p>
15   *
16   * 
17   * <table> 
18   * <tr><th colspan='3'>
19   * Field summary for SQL table <code>UploadedImage</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> url </td><td> String </td><td> The name of the file, as uploaded 
24   * </td></tr> 
25   * <tr><td> height </td><td> Integer </td><td> The height of this file if it 
26   * is an image </td></tr> 
27   * <tr><td> width </td><td> Integer </td><td> The width of this file if it is 
28   * an image </td></tr> 
29   * </table> 
30   * 
31   * @generator  org.melati.poem.prepro.TableDef#generateTableMainJava 
32   */
33  public class UploadedImageTable extends UploadedImageTableBase {
34  
35   /**
36    * Constructor.
37    * 
38    * @generator org.melati.poem.prepro.TableDef#generateTableMainJava 
39    * @param database          the POEM database we are using
40    * @param name              the name of this <code>Table</code>
41    * @param definitionSource  which definition is being us  String displayname 
42        (size = unlimited)
43        (displayname = "Display name")
44        (description = "The layout's name")
45        (displaylevel = primary)
46        (searchability = primary);
47  ed
48    * @throws PoemException    if anything goes wrong
49    */
50    public UploadedImageTable(
51        Database database, String name,
52        DefinitionSource definitionSource) throws PoemException {
53      super(database, name, definitionSource);
54    }
55  
56    // programmer's domain-specific code here
57    /**
58     * Find or create an object with these properties.
59     * Note that height and width are defaulted.
60     * @param displayName
61     * @param description
62     * @param url
63     * @param type
64     * @return existing or newly created one
65     */
66    public UploadedImage ensure(String displayName, String description, 
67                                String url, UploadedFileType type, 
68                                Integer width, Integer height){
69      UploadedImage p = (UploadedImage)getDisplaynameColumn().firstWhereEq(displayName);
70      if (p == null) {
71        p = (UploadedImage)newPersistent();
72        p.setDisplayname(displayName);
73        p.setDescription(description);
74        p.setUrl(url);
75        p.setWidth(width);
76        p.setHeight(height);
77        p.setType(type);
78        p.setDeleted(false);
79        p.makePersistent();
80      }
81      return p;
82    }
83    /**
84     * @return the relative url 
85     */
86    public String getRelativeUrl() {
87      return "/images";
88    }
89  
90  }
91