2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.entity;
34 import freemarker.template.SimpleList;
35 import freemarker.template.SimpleScalar;
36 import freemarker.template.TemplateModel;
37 import freemarker.template.TemplateModelException;
38 import mir.entity.Entity;
39 import mir.media.MediaHelper;
40 import mir.media.MirMedia;
41 import mir.storage.StorageObject;
42 import mir.storage.StorageObjectException;
43 import mircoders.storage.DatabaseUploadedMedia;
45 import java.util.HashMap;
48 * Diese Klasse enthält die Daten eines MetaObjekts
55 public class EntityUploadedMedia extends Entity {
58 public EntityUploadedMedia() {
62 public EntityUploadedMedia(StorageObject theStorage) {
64 setStorage(theStorage);
67 public void setValues(HashMap theStringValues) {
68 if (theStringValues != null) {
69 if (!theStringValues.containsKey("is_published"))
70 theStringValues.put("is_published", "0");
72 super.setValues(theStringValues);
77 * fetches the MediaType entry assiciated w/ this media
79 * @return mir.entity.Entity
81 public Entity getMediaType() throws StorageObjectException {
84 ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
86 catch (StorageObjectException e) {
87 throwStorageObjectException(e, "get MediaType failed -- ");
92 public String getValue(String key) {
93 String returnValue = null;
96 if (key.equals("big_icon"))
97 returnValue = getBigIcon();
98 else if (key.equals("descr"))
99 returnValue = getDescr();
100 else if (key.equals("mediatype"))
101 returnValue = getMediaTypeString();
102 else if (key.equals("mimetype"))
103 returnValue = getMimeType();
105 returnValue = super.getValue(key);
110 public TemplateModel get(java.lang.String key) throws TemplateModelException {
111 if (key.equals("url"))
113 return new SimpleScalar(getValue(key));
116 // @todo all these methods should be merged into 1
117 // and the MediaHandler should be cached somehow.
118 private String getMediaTypeString() {
119 MirMedia mediaHandler = null;
120 Entity mediaType = null;
123 mediaType = getMediaType();
124 mediaHandler = MediaHelper.getHandler(mediaType);
126 if (mediaHandler.isAudio())
128 else if (mediaHandler.isImage())
130 else if (mediaHandler.isVideo())
135 catch (Exception ex) {
136 theLog.printWarning("-- getMediaTypeString: could not fetch data "
137 + this.getClass().toString() + " " + ex.toString());
142 private String getBigIcon() {
143 MirMedia mediaHandler = null;
144 Entity mediaType = null;
147 mediaType = getMediaType();
148 mediaHandler = MediaHelper.getHandler(mediaType);
149 return mediaHandler.getBigIcon();
151 catch (Exception ex) {
152 theLog.printWarning("-- getBigIcon: could not fetch data "
153 + this.getClass().toString() + " " + ex.toString());
158 private SimpleList getUrl() {
159 MirMedia mediaHandler = null;
160 Entity mediaType = null;
163 mediaType = getMediaType();
164 mediaHandler = MediaHelper.getHandler(mediaType);
165 return mediaHandler.getURL(this, mediaType);
167 catch (Exception ex) {
168 theLog.printWarning("-- getUrl: could not fetch data "
169 + this.getClass().toString() + " " + ex.toString());
174 private String getDescr() {
175 MirMedia mediaHandler = null;
176 Entity mediaType = null;
179 mediaType = getMediaType();
180 mediaHandler = MediaHelper.getHandler(mediaType);
181 return mediaHandler.getDescr(mediaType);
183 catch (Exception ex) {
184 theLog.printWarning("-- getDescr: could not fetch data "
185 + this.getClass().toString() + " " + ex.toString());
189 private String getMimeType() {
190 Entity mediaType = null;
193 mediaType = getMediaType();
194 return mediaType.getValue("mime_type");
196 catch (Exception ex) {
197 theLog.printWarning("-- getBigIcon: could not fetch data "
198 + this.getClass().toString() + " " + ex.toString());