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;
39 import mir.entity.Entity;
40 import mir.entity.EntityList;
41 import mir.media.MediaHelper;
42 import mir.media.MirMedia;
43 import mir.storage.StorageObject;
44 import mir.storage.StorageObjectException;
45 import mir.misc.NumberUtils;
46 import mircoders.storage.DatabaseUploadedMedia;
47 import mircoders.storage.DatabaseContentToMedia;
49 import java.sql.SQLException;
50 import java.util.HashMap;
53 * Diese Klasse enthält die Daten eines MetaObjekts
55 * @author mh, mir-coders group
56 * @version $Id: EntityUploadedMedia.java,v 1.9.2.7 2002/12/05 08:47:06 mh Exp $
60 public class EntityUploadedMedia extends Entity {
63 public EntityUploadedMedia() {
67 public EntityUploadedMedia(StorageObject theStorage) {
69 setStorage(theStorage);
72 public void update() throws StorageObjectException {
74 EntityList contentList = DatabaseContentToMedia.getInstance().getContent(this);
75 if (contentList!=null && contentList.size()>0) {
76 for(int i=0;i<contentList.size();i++) {
77 EntityContent contentEnt = (EntityContent)contentList.elementAt(i);
78 contentEnt.setProduced(false);
83 public void setValues(HashMap theStringValues) {
84 if (theStringValues != null) {
85 if (!theStringValues.containsKey("is_published"))
86 theStringValues.put("is_published", "0");
88 super.setValues(theStringValues);
93 * fetches the MediaType entry assiciated w/ this media
95 * @return mir.entity.Entity
97 public Entity getMediaType() throws StorageObjectException {
100 ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
102 catch (StorageObjectException e) {
103 throwStorageObjectException(e, "get MediaType failed -- ");
108 public String getValue(String key) {
109 String returnValue = null;
112 if (key.equals("big_icon"))
113 returnValue = getBigIconName();
114 else if (key.equals("descr") || key.equals("media_descr"))
115 returnValue = getDescr();
116 else if (key.equals("mediatype"))
117 returnValue = getMediaTypeString();
118 else if (key.equals("mimetype"))
119 returnValue = getMimeType();
120 else if (key.equals("human_readable_size")) {
121 String size = super.getValue("size");
123 returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
126 returnValue = super.getValue(key);
131 public TemplateModel get(java.lang.String key) throws TemplateModelException {
132 if (key.equals("url"))
134 return new SimpleScalar(getValue(key));
137 // @todo all these methods should be merged into 1
138 // and the MediaHandler should be cached somehow.
139 private String getMediaTypeString() {
140 MirMedia mediaHandler = null;
141 Entity mediaType = null;
144 mediaType = getMediaType();
145 mediaHandler = MediaHelper.getHandler(mediaType);
147 if (mediaHandler.isAudio())
149 else if (mediaHandler.isImage())
151 else if (mediaHandler.isVideo())
156 catch (Exception ex) {
157 theLog.printWarning("-- getMediaTypeString: could not fetch data "
158 + this.getClass().toString() + " " + ex.toString());
163 private String getBigIconName() {
164 MirMedia mediaHandler = null;
165 Entity mediaType = null;
168 mediaType = getMediaType();
169 mediaHandler = MediaHelper.getHandler(mediaType);
170 return mediaHandler.getBigIconName();
172 catch (Exception ex) {
173 theLog.printWarning("-- getBigIconName: could not fetch data "
174 + this.getClass().toString() + " " + ex.toString());
179 private SimpleList getUrl() {
180 MirMedia mediaHandler = null;
181 Entity mediaType = null;
184 mediaType = getMediaType();
185 mediaHandler = MediaHelper.getHandler(mediaType);
186 return mediaHandler.getURL(this, mediaType);
188 catch (Exception ex) {
189 theLog.printWarning("-- getUrl: could not fetch data "
190 + this.getClass().toString() + " " + ex.toString());
195 private String getDescr() {
196 MirMedia mediaHandler = null;
197 Entity mediaType = null;
200 mediaType = getMediaType();
201 mediaHandler = MediaHelper.getHandler(mediaType);
202 return mediaHandler.getDescr(mediaType);
204 catch (Exception ex) {
205 theLog.printWarning("-- getDescr: could not fetch data "
206 + this.getClass().toString() + " " + ex.toString());
210 private String getMimeType() {
211 Entity mediaType = null;
214 mediaType = getMediaType();
215 return mediaType.getValue("mime_type");
217 catch (Exception ex) {
218 theLog.printWarning("-- getBigIconName: could not fetch data "
219 + this.getClass().toString() + " " + ex.toString());