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 java.util.HashMap;
36 import mir.entity.Entity;
37 import mir.entity.EntityList;
38 import mir.media.MediaHelper;
39 import mir.media.MirMedia;
40 import mir.misc.NumberUtils;
41 import mir.storage.StorageObject;
42 import mir.storage.StorageObjectExc;
43 import mir.storage.StorageObjectFailure;
44 import mircoders.storage.DatabaseContentToMedia;
45 import mircoders.storage.DatabaseUploadedMedia;
46 import freemarker.template.SimpleList;
47 import freemarker.template.SimpleScalar;
48 import freemarker.template.TemplateModel;
49 import freemarker.template.TemplateModelException;
52 * Diese Klasse enth?lt die Daten eines MetaObjekts
54 * @author mh, mir-coders group
55 * @version $Id: EntityUploadedMedia.java,v 1.18 2003/02/20 16:05:33 zapata Exp $
59 public class EntityUploadedMedia extends Entity {
62 public EntityUploadedMedia() {
66 public EntityUploadedMedia(StorageObject theStorage) {
68 setStorage(theStorage);
71 public void update() throws StorageObjectFailure {
73 EntityList contentList = DatabaseContentToMedia.getInstance().getContent(this);
74 if (contentList!=null && contentList.size()>0) {
75 for(int i=0;i<contentList.size();i++) {
76 EntityContent contentEnt = (EntityContent)contentList.elementAt(i);
77 contentEnt.setProduced(false);
82 public void setValues(HashMap theStringValues) {
83 if (theStringValues != null) {
84 if (!theStringValues.containsKey("is_published"))
85 theStringValues.put("is_published", "0");
87 super.setValues(theStringValues);
92 * fetches the MediaType entry assiciated w/ this media
94 * @return mir.entity.Entity
96 public Entity getMediaType() throws StorageObjectFailure {
99 ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
101 catch (StorageObjectFailure e) {
102 throwStorageObjectFailure(e, "get MediaType failed -- ");
107 public String getValue(String key) {
108 String returnValue = null;
111 if (key.equals("big_icon"))
112 returnValue = getBigIconName();
113 else if (key.equals("descr") || key.equals("media_descr"))
114 returnValue = getDescr();
115 else if (key.equals("mediatype"))
116 returnValue = getMediaTypeString();
117 else if (key.equals("mimetype"))
118 returnValue = getMimeType();
119 else if (key.equals("human_readable_size")) {
120 String size = super.getValue("size");
122 returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
125 returnValue = super.getValue(key);
130 public TemplateModel get(java.lang.String key) throws TemplateModelException {
131 if (key.equals("url"))
133 return new SimpleScalar(getValue(key));
136 // @todo all these methods should be merged into 1
137 // and the MediaHandler should be cached somehow.
138 private String getMediaTypeString() {
139 MirMedia mediaHandler = null;
140 Entity mediaType = null;
143 mediaType = getMediaType();
144 mediaHandler = MediaHelper.getHandler(mediaType);
146 if (mediaHandler.isAudio())
148 else if (mediaHandler.isImage())
150 else if (mediaHandler.isVideo())
155 catch (Exception ex) {
156 theLog.printWarning("-- getMediaTypeString: could not fetch data "
157 + this.getClass().toString() + " " + ex.toString());
162 private String getBigIconName() {
163 MirMedia mediaHandler = null;
164 Entity mediaType = null;
167 mediaType = getMediaType();
168 mediaHandler = MediaHelper.getHandler(mediaType);
169 return mediaHandler.getBigIconName();
171 catch (Exception ex) {
172 theLog.printWarning("-- getBigIconName: could not fetch data "
173 + this.getClass().toString() + " " + ex.toString());
178 private SimpleList getUrl() {
179 MirMedia mediaHandler = null;
180 Entity mediaType = null;
183 mediaType = getMediaType();
184 mediaHandler = MediaHelper.getHandler(mediaType);
185 return mediaHandler.getURL(this, mediaType);
187 catch (Exception ex) {
188 theLog.printWarning("-- getUrl: could not fetch data "
189 + this.getClass().toString() + " " + ex.toString());
194 private String getDescr() {
195 MirMedia mediaHandler = null;
196 Entity mediaType = null;
199 mediaType = getMediaType();
200 mediaHandler = MediaHelper.getHandler(mediaType);
201 return mediaHandler.getDescr(mediaType);
203 catch (Exception ex) {
204 theLog.printWarning("-- getDescr: could not fetch data "
205 + this.getClass().toString() + " " + ex.toString());
209 private String getMimeType() {
210 Entity mediaType = null;
213 mediaType = getMediaType();
214 return mediaType.getValue("mime_type");
216 catch (Exception ex) {
217 theLog.printWarning("-- getBigIconName: could not fetch data "
218 + this.getClass().toString() + " " + ex.toString());