- if (mediaTypesList.size() > 0) {
- Entity mediaType = null;
-
- // find out if we an exact content-type match if so take it.
- // otherwise just use the first one.
- // @todo this should probably be moved to DatabaseMediaType -mh
- for(int j=0;j<mediaTypesList.size();j++) {
- if(contentType.equals(
- mediaTypesList.elementAt(j).getValue("mime_type")))
- mediaType = mediaTypesList.elementAt(j);
- }
-
- if( mediaType == null )
- mediaType = mediaTypesList.elementAt(0);
-
- //get the class names from the media_type table.
- mediaTypeId = mediaType.getId();
- try {
- // ############### @todo: merge these and the getURL call into one
- // getURL helper call that just takes the Entity as a parameter
- // along with media_type
- mediaHandler = MediaHelper.getHandler(mediaType);
- mediaStorage = MediaHelper.getStorage(mediaType,
- "mircoders.storage.Database");
- Class prodCls = Class.forName("mircoders.producer.Producer"
- +mediaType.getValue("tablename"));
- mediaProducer = (ProducerMedia)prodCls.newInstance();
- } catch (Exception e) {
- theLog.printError("getting media handler failed: "+e.toString());
- contentModule.deleteById(cid);
- throw new ServletModuleException("getting media handler failed: "
- +e.toString());
- }
-
- mediaValues.put("to_media_type",mediaTypeId);
-
- //load the classes via reflection
- String MediaId;
- Entity mediaEnt = null;
- try {
- mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
- mediaEnt.setStorage(mediaStorage);
- mediaEnt.setValues(mediaValues);
- mediaId = mediaEnt.insert();
-
- //save and store the media data/metadata
- mediaHandler.set(mpReq.getMedia(), mediaEnt,
- mediaType);
-
- //were done with mpReq at this point, dereference it.
- //as it contains mucho mem. -mh 01.10.2001
- mpReq=null;
-
- //we got this far, associate the media to the article
- mediaEnt.setValueForProperty("is_published","1");
- mediaEnt.update();
- //produce it
- mediaProducer.handle(null, null, false, false, mediaId);
- DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
- } catch (Exception e) {
- theLog.printError("setting media failed: "+e.toString());
- contentModule.deleteById(cid);
- throw new ServletModuleException("setting media failed: "+e.toString());
- }