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 mir.misc.NumberUtils;
44 import mircoders.storage.DatabaseUploadedMedia;
46 import java.util.HashMap;
49 * Diese Klasse enthält die Daten eines MetaObjekts
51 * @author mh, mir-coders group
52 * @version $Id: EntityUploadedMedia.java,v 1.9.2.5 2002/11/28 19:55:25 mh Exp $
56 public class EntityUploadedMedia extends Entity {
59 public EntityUploadedMedia() {
63 public EntityUploadedMedia(StorageObject theStorage) {
65 setStorage(theStorage);
68 public void setValues(HashMap theStringValues) {
69 if (theStringValues != null) {
70 if (!theStringValues.containsKey("is_published"))
71 theStringValues.put("is_published", "0");
73 super.setValues(theStringValues);
78 * fetches the MediaType entry assiciated w/ this media
80 * @return mir.entity.Entity
82 public Entity getMediaType() throws StorageObjectException {
85 ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
87 catch (StorageObjectException e) {
88 throwStorageObjectException(e, "get MediaType failed -- ");
93 public String getValue(String key) {
94 String returnValue = null;
97 if (key.equals("big_icon"))
98 returnValue = getBigIconName();
99 else if (key.equals("descr") || key.equals("description"))
100 returnValue = getDescr();
101 else if (key.equals("mediatype"))
102 returnValue = getMediaTypeString();
103 else if (key.equals("mimetype"))
104 returnValue = getMimeType();
105 /*else if (key.equals("size")) {
106 String size = super.getValue(key);
108 returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
111 returnValue = super.getValue(key);
116 public TemplateModel get(java.lang.String key) throws TemplateModelException {
117 if (key.equals("url"))
119 return new SimpleScalar(getValue(key));
122 // @todo all these methods should be merged into 1
123 // and the MediaHandler should be cached somehow.
124 private String getMediaTypeString() {
125 MirMedia mediaHandler = null;
126 Entity mediaType = null;
129 mediaType = getMediaType();
130 mediaHandler = MediaHelper.getHandler(mediaType);
132 if (mediaHandler.isAudio())
134 else if (mediaHandler.isImage())
136 else if (mediaHandler.isVideo())
141 catch (Exception ex) {
142 theLog.printWarning("-- getMediaTypeString: could not fetch data "
143 + this.getClass().toString() + " " + ex.toString());
148 private String getBigIconName() {
149 MirMedia mediaHandler = null;
150 Entity mediaType = null;
153 mediaType = getMediaType();
154 mediaHandler = MediaHelper.getHandler(mediaType);
155 return mediaHandler.getBigIconName();
157 catch (Exception ex) {
158 theLog.printWarning("-- getBigIconName: could not fetch data "
159 + this.getClass().toString() + " " + ex.toString());
164 private SimpleList getUrl() {
165 MirMedia mediaHandler = null;
166 Entity mediaType = null;
169 mediaType = getMediaType();
170 mediaHandler = MediaHelper.getHandler(mediaType);
171 return mediaHandler.getURL(this, mediaType);
173 catch (Exception ex) {
174 theLog.printWarning("-- getUrl: could not fetch data "
175 + this.getClass().toString() + " " + ex.toString());
180 private String getDescr() {
181 MirMedia mediaHandler = null;
182 Entity mediaType = null;
185 mediaType = getMediaType();
186 mediaHandler = MediaHelper.getHandler(mediaType);
187 return mediaHandler.getDescr(mediaType);
189 catch (Exception ex) {
190 theLog.printWarning("-- getDescr: could not fetch data "
191 + this.getClass().toString() + " " + ex.toString());
195 private String getMimeType() {
196 Entity mediaType = null;
199 mediaType = getMediaType();
200 return mediaType.getValue("mime_type");
202 catch (Exception ex) {
203 theLog.printWarning("-- getBigIconName: could not fetch data "
204 + this.getClass().toString() + " " + ex.toString());