044a37fdf77c1e24f7a59b795e76f7c8cca6a2ae
[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("url"))
69         returnValue=getUrl();
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     return new SimpleScalar(getValue(key));
81   }
82
83   private String getUrl()
84   {
85     MirMedia            mediaHandler=null;
86     Entity              mediaType=null;
87
88     try {
89       mediaType = getMediaType();
90       mediaHandler = MediaHelper.getHandler( mediaType );
91       return mediaHandler.getURL(this, mediaType);
92     } catch (Exception ex) {
93       theLog.printWarning("-- getUrl: could not fetch data "
94                          + this.getClass().toString()+" "+ ex.toString());
95     }
96     return null;
97   }
98
99   private String getListView()
100   {
101     MirMedia            mediaHandler=null;
102     Entity              mediaType=null;
103
104     try {
105       mediaType = getMediaType();
106       mediaHandler = MediaHelper.getHandler( mediaType );
107       return mediaHandler.getListView(this, mediaType);
108     } catch (Exception ex) {
109       theLog.printWarning("-- getUrl: could not fetch data "
110                          + this.getClass().toString()+" "+ ex.toString());
111     }
112     return null;
113   }
114
115
116 }