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 any library licensed under the Apache Software License,
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23 * (or with modified versions of the above that use the same license as the above),
24 * and distribute linked combinations including the two. You must obey the
25 * GNU General Public License in all respects for all of the code used other than
26 * the above mentioned libraries. If you modify this file, you may extend this
27 * exception to your version of the file, but you are not obligated to do so.
28 * If you do not wish to do so, delete this exception statement from your version.
30 package mircoders.entity;
32 import java.sql.SQLException;
33 import java.util.List;
36 import mir.entity.Entity;
37 import mir.log.LoggerWrapper;
38 import mir.media.MediaHelper;
39 import mir.media.MirMedia;
40 import mir.misc.NumberUtils;
41 import mir.storage.StorageObject;
42 import mir.storage.StorageObjectFailure;
43 import mircoders.storage.DatabaseUploadedMedia;
47 * @author mh, mir-coders group
48 * @version $Id: EntityUploadedMedia.java,v 1.26.2.3 2003/11/26 19:21:04 rk Exp $
52 public class EntityUploadedMedia extends Entity {
55 public EntityUploadedMedia() {
58 logger = new LoggerWrapper("Entity.UploadedMedia");
61 public EntityUploadedMedia(StorageObject theStorage) {
63 setStorage(theStorage);
66 public void update() throws StorageObjectFailure {
69 theStorageObject.executeUpdate( "update content set is_produced='0' where exists(select * from content_x_media where to_content=content.id and to_media=" + getId()+")");
71 catch (SQLException e) {
72 throwStorageObjectFailure(e, "EntityUploadedMedia :: update :: failed!! ");
76 public void setValues(Map theStringValues) {
77 if (theStringValues != null) {
78 if (!theStringValues.containsKey("is_published"))
79 theStringValues.put("is_published", "0");
81 super.setValues(theStringValues);
86 * fetches the MediaType entry assiciated w/ this media
88 * @return mir.entity.Entity
90 public Entity getMediaType() throws StorageObjectFailure {
93 ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
95 catch (StorageObjectFailure e) {
96 throwStorageObjectFailure(e, "get MediaType failed -- ");
101 public String getValue(String key) {
102 String returnValue = null;
105 if (key.equals("big_icon"))
106 returnValue = getBigIconName();
107 else if (key.equals("descr") || key.equals("media_descr"))
108 returnValue = getDescr();
109 else if (key.equals("mediatype"))
110 returnValue = getMediaTypeString();
111 else if (key.equals("mimetype"))
112 returnValue = getMimeType();
113 else if (key.equals("human_readable_size")) {
114 String size = super.getValue("size");
116 returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
119 returnValue = super.getValue(key);
124 // @todo all these methods should be merged into 1
125 // and the MediaHandler should be cached somehow.
126 private String getMediaTypeString() {
127 MirMedia mediaHandler = null;
128 Entity mediaType = null;
131 mediaType = getMediaType();
132 mediaHandler = MediaHelper.getHandler(mediaType);
134 if (mediaHandler.isAudio())
136 else if (mediaHandler.isImage())
138 else if (mediaHandler.isVideo())
143 catch (Exception ex) {
144 logger.warn("EntityUploadedMedia.getMediaTypeString: could not fetch data: " + ex.toString());
149 private String getBigIconName() {
150 MirMedia mediaHandler = null;
151 Entity mediaType = null;
154 mediaType = getMediaType();
155 mediaHandler = MediaHelper.getHandler(mediaType);
156 return mediaHandler.getBigIconName();
158 catch (Exception ex) {
159 logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());
164 private List 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 (Throwable t) {
174 logger.warn("EntityUploadedMedia.getUrl: could not fetch data: " + t.toString());
179 private String getDescr() {
180 MirMedia mediaHandler = null;
181 Entity mediaType = null;
184 mediaType = getMediaType();
185 mediaHandler = MediaHelper.getHandler(mediaType);
186 return mediaHandler.getDescr(mediaType);
188 catch (Exception ex) {
189 logger.warn("EntityUploadedMedia.getDescr: could not fetch data: " + ex.toString());
193 private String getMimeType() {
194 Entity mediaType = null;
197 mediaType = getMediaType();
198 return mediaType.getValue("mime_type");
200 catch (Exception ex) {
201 logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());