2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with any library licensed under the Apache Software License,
\r
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
\r
23 * (or with modified versions of the above that use the same license as the above),
\r
24 * and distribute linked combinations including the two. You must obey the
\r
25 * GNU General Public License in all respects for all of the code used other than
\r
26 * the above mentioned libraries. If you modify this file, you may extend this
\r
27 * exception to your version of the file, but you are not obligated to do so.
\r
28 * If you do not wish to do so, delete this exception statement from your version.
\r
30 package mircoders.entity;
\r
32 import java.sql.SQLException;
\r
33 import java.util.List;
\r
34 import java.util.Map;
\r
36 import mir.entity.Entity;
\r
37 import mir.log.LoggerWrapper;
\r
38 import mir.media.MediaHelper;
\r
39 import mir.media.MirMedia;
\r
40 import mir.misc.NumberUtils;
\r
41 import mir.storage.StorageObject;
\r
42 import mir.storage.StorageObjectFailure;
\r
43 import mircoders.storage.DatabaseUploadedMedia;
\r
47 * @author mh, mir-coders group
\r
48 * @version $Id: EntityUploadedMedia.java,v 1.27 2003/09/03 18:29:04 zapata Exp $
\r
52 public class EntityUploadedMedia extends Entity {
\r
55 public EntityUploadedMedia() {
\r
58 logger = new LoggerWrapper("Entity.UploadedMedia");
\r
61 public EntityUploadedMedia(StorageObject theStorage) {
\r
63 setStorage(theStorage);
\r
66 public void update() throws StorageObjectFailure {
\r
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()+")");
\r
71 catch (SQLException e) {
\r
72 throwStorageObjectFailure(e, "EntityAudio :: update :: failed!! ");
\r
76 public void setValues(Map theStringValues) {
\r
77 if (theStringValues != null) {
\r
78 if (!theStringValues.containsKey("is_published"))
\r
79 theStringValues.put("is_published", "0");
\r
81 super.setValues(theStringValues);
\r
86 * fetches the MediaType entry assiciated w/ this media
\r
88 * @return mir.entity.Entity
\r
90 public Entity getMediaType() throws StorageObjectFailure {
\r
93 ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
\r
95 catch (StorageObjectFailure e) {
\r
96 throwStorageObjectFailure(e, "get MediaType failed -- ");
\r
101 public String getValue(String key) {
\r
102 String returnValue = null;
\r
105 if (key.equals("big_icon"))
\r
106 returnValue = getBigIconName();
\r
107 else if (key.equals("descr") || key.equals("media_descr"))
\r
108 returnValue = getDescr();
\r
109 else if (key.equals("mediatype"))
\r
110 returnValue = getMediaTypeString();
\r
111 else if (key.equals("mimetype"))
\r
112 returnValue = getMimeType();
\r
113 else if (key.equals("human_readable_size")) {
\r
114 String size = super.getValue("size");
\r
116 returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
\r
119 returnValue = super.getValue(key);
\r
121 return returnValue;
\r
124 // @todo all these methods should be merged into 1
\r
125 // and the MediaHandler should be cached somehow.
\r
126 private String getMediaTypeString() {
\r
127 MirMedia mediaHandler = null;
\r
128 Entity mediaType = null;
\r
131 mediaType = getMediaType();
\r
132 mediaHandler = MediaHelper.getHandler(mediaType);
\r
134 if (mediaHandler.isAudio())
\r
136 else if (mediaHandler.isImage())
\r
138 else if (mediaHandler.isVideo())
\r
143 catch (Exception ex) {
\r
144 logger.warn("EntityUploadedMedia.getMediaTypeString: could not fetch data: " + ex.toString());
\r
149 private String getBigIconName() {
\r
150 MirMedia mediaHandler = null;
\r
151 Entity mediaType = null;
\r
154 mediaType = getMediaType();
\r
155 mediaHandler = MediaHelper.getHandler(mediaType);
\r
156 return mediaHandler.getBigIconName();
\r
158 catch (Exception ex) {
\r
159 logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());
\r
164 private List getUrl() {
\r
165 MirMedia mediaHandler = null;
\r
166 Entity mediaType = null;
\r
169 mediaType = getMediaType();
\r
170 mediaHandler = MediaHelper.getHandler(mediaType);
\r
171 return mediaHandler.getURL(this, mediaType);
\r
173 catch (Throwable t) {
\r
174 logger.warn("EntityUploadedMedia.getUrl: could not fetch data: " + t.toString());
\r
179 private String getDescr() {
\r
180 MirMedia mediaHandler = null;
\r
181 Entity mediaType = null;
\r
184 mediaType = getMediaType();
\r
185 mediaHandler = MediaHelper.getHandler(mediaType);
\r
186 return mediaHandler.getDescr(mediaType);
\r
188 catch (Exception ex) {
\r
189 logger.warn("EntityUploadedMedia.getDescr: could not fetch data: " + ex.toString());
\r
193 private String getMimeType() {
\r
194 Entity mediaType = null;
\r
197 mediaType = getMediaType();
\r
198 return mediaType.getValue("mime_type");
\r
200 catch (Exception ex) {
\r
201 logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());
\r