made the getUrl() method of MirMedia return a SimpleList of TemplateModels
[mir.git] / source / mircoders / entity / EntityUploadedMedia.java
1 package mircoders.entity;
2
3 import java.lang.*;
4 import java.io.*;
5 import java.util.*;
6 import java.sql.*;
7
8 import freemarker.template.*;
9
10 import mir.entity.*;
11 import mir.misc.*;
12 import mir.storage.*;
13 import mir.media.*;
14
15 import mircoders.storage.*;
16 /**
17  * Diese Klasse enthält die Daten eines MetaObjekts
18  *
19  * @author RK
20  * @version 29.6.1999
21  */
22
23
24 public class EntityUploadedMedia extends Entity
25 {
26
27
28   public EntityUploadedMedia(){
29     super();
30   }
31
32   public EntityUploadedMedia(StorageObject theStorage)
33   {
34     this();
35     setStorage(theStorage);
36   }
37
38   public void setValues(HashMap theStringValues)
39         {
40                 if (theStringValues != null) {
41                         if (!theStringValues.containsKey("is_published"))
42                          theStringValues.put("is_published","0");
43                 }
44                 super.setValues(theStringValues);
45         }
46
47
48         /**
49          * fetches the MediaType entry assiciated w/ this media
50          *
51          * @return mir.entity.Entity
52          */
53         public Entity getMediaType() throws StorageObjectException {
54         Entity ent = null;
55         try {
56                     ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
57         } catch (StorageObjectException e) {
58             throwStorageObjectException(e, "get MediaType failed -- ");
59         }
60         return ent;
61         }
62
63   public String getValue(String key)
64   {
65     String returnValue=null;
66
67     if (key!=null) {
68       if (key.equals("big_icon"))
69         returnValue=getBigIcon();
70       else if (key.equals("list"))
71         returnValue=getListView();
72       else
73         returnValue=super.getValue(key);
74     }
75     return returnValue;
76   }
77
78   public TemplateModel get(java.lang.String key) throws TemplateModelException
79   {
80     if (key.equals("url"))
81       return getUrl();
82
83     return new SimpleScalar(getValue(key));
84   }
85
86   private String getBigIcon()
87   {
88     MirMedia            mediaHandler=null;
89     Entity              mediaType=null;
90
91     try {
92       mediaType = getMediaType();
93       mediaHandler = MediaHelper.getHandler( mediaType );
94       return mediaHandler.getBigIcon();
95     } catch (Exception ex) {
96       theLog.printWarning("-- getBigIcon: could not fetch data "
97                          + this.getClass().toString()+" "+ ex.toString());
98     }
99     return null;
100   }
101
102   private SimpleList getUrl()
103   {
104     MirMedia            mediaHandler=null;
105     Entity              mediaType=null;
106
107     try {
108       mediaType = getMediaType();
109       mediaHandler = MediaHelper.getHandler( mediaType );
110       return mediaHandler.getURL(this, mediaType);
111     } catch (Exception ex) {
112       theLog.printWarning("-- getUrl: could not fetch data "
113                          + this.getClass().toString()+" "+ ex.toString());
114     }
115     return null;
116   }
117
118   private String getListView()
119   {
120     MirMedia            mediaHandler=null;
121     Entity              mediaType=null;
122
123     try {
124       mediaType = getMediaType();
125       mediaHandler = MediaHelper.getHandler( mediaType );
126       return mediaHandler.getListView(this, mediaType);
127     } catch (Exception ex) {
128       theLog.printWarning("-- getUrl: could not fetch data "
129                          + this.getClass().toString()+" "+ ex.toString());
130     }
131     return null;
132   }
133
134
135 }