+ withValues.put("creator","Anonym");
+
+ // inserting content into database
+ String cid = contentModule.add(withValues);
+
+ String[] to_topicsArr = mp.getParameterValues("to_topic");
+ if (to_topicsArr != null && to_topicsArr.length > 0) {
+ try{
+ DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr);
+ theLog.printError("setting content_x_topic success");
+ } catch (Exception e) {
+ theLog.printError("setting content_x_topic failed");
+ } //end try
+ } //end if
+
+ // if op contains uploaddata
+ String mediaId=null;
+ int i=1;
+ for(Iterator it = mp.requestList.iterator(); it.hasNext();){
+ MpRequest mpReq = (MpRequest)it.next();
+ String fileName = mpReq.getFilename();
+ String contentType = FileUtil.guessContentTypeFromName(fileName);
+ HashMap mediaValues = new HashMap();
+
+ theLog.printError("CONTENT TYPE IS: "+contentType);
+
+ if ((contentType==null) || (contentType=="application/octet-stream")) {
+ throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
+ }
+
+
+ String mediaTitle=(String)withValues.get("media_title"+i);
+ i++;
+
+ if (mediaTitle==null)
+ mediaTitle = (String)withValues.get("title");
+
+ mediaValues.put("title", mediaTitle);
+ mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
+ mediaValues.put("to_publisher", "1"); // op user
+ mediaValues.put("to_media_folder", "7"); // op media_folder
+ mediaValues.put("is_produced", "0");
+ mediaValues.put("is_published","1");
+
+ String wc = " mime_type='"+contentType+"'";
+
+ EntityList mediaTypesList = DatabaseMediaType.getInstance().selectByWhereClause(wc);
+
+ String mediaTypeId = null;
+ String mediaStorageName = null;
+ String mediaHandlerName = null;
+
+ if (mediaTypesList.size() > 0) {
+ mediaTypeId = mediaTypesList.elementAt(0).getId();
+ mediaStorageName = mediaTypesList.elementAt(0).getValue("tablename");
+ mediaHandlerName = mediaTypesList.elementAt(0).getValue("classname");
+ mediaValues.put("to_media_type",mediaTypeId);
+
+ String MediaId;
+ try {
+ Class mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
+ Method m = mediaStorageClass.getMethod("getInstance", null);
+ Database mediaStorage = (Database)m.invoke(null, null);
+ Entity mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
+ mediaEnt.setStorage(mediaStorage);
+ mediaEnt.setValues(mediaValues);
+ mediaId = mediaEnt.insert();
+
+ Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+ MirMedia mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
+ mediaHandler.set(mpReq.getMedia(), mediaEnt,mediaTypesList.elementAt(0));
+ if(mediaId!=null){
+ //new ProducerImages().handle(null, null, false, false, mediaId);
+ }
+ } catch (Exception e) {
+ theLog.printError("setting uploaded_media failed: "+e.toString());
+ }
+
+
+ try{
+ DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
+ theLog.printError("setting content_x_media success");
+ } catch (Exception e) {
+ theLog.printError("setting content_x_media failed");
+ }
+
+ } else {
+ theLog.printDebugInfo("Wrong file uploaded!: " + fileName);
+ throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
+ }
+
+
+
+
+
+
+ //MirUploadedMedia Media = MirUploadedMedia(mpReq, cid);
+ //mediaValues.put("title",mediaTitle);
+
+ //mediaId = Media.add();
+ /* // this is video !!
+ //theLog.printDebugInfo("--GOT VIDEO");
+ EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
+ //notice the discr here..... (imageModule).
+ entVideo.setValues(mediaValues);
+ mediaId = entVideo.insert();
+ entVideo.setVideoData(mediaData);
+ }
+ //try content type first then go by xtension?
+ else if (contentType.equals("image/jpeg") || contentType.equals("image/gif")) {
+ // this is image !!
+ mediaId = imageModule.add(mediaValues);
+ EntityImages entImage = (EntityImages)imageModule.getById(mediaId);
+
+ int fileType = -1;
+
+ //replace all this with DatabaseContentMedia.getInst().getEn(contentType).set(mediaData) ??? w/ a catch for error, then return form w/ and error
+ if (contentType.equals("image/jpeg")) fileType=0;
+ if (contentType.equals("image/gif")) fileType=1;
+ if (fileType>=0) {
+ entImage.setImage(mediaData, fileType);
+ // inserting content and media id in table content_x_media
+ try{
+ DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
+ theLog.printError("setting content_x_media success");
+ } catch (Exception e) {
+ theLog.printError("setting content_x_media failed");
+ }
+
+ // producing new page
+ if(mediaId!=null){
+ new ProducerImages().handle(null, null, false, false, mediaId);
+ }
+ } else {
+ theLog.printDebugInfo("Wrong file uploaded!" + fileName);
+ }
+ }
+ }*/
+ }
+
+ // producing openpostinglist
+ new ProducerOpenPosting().handle(null,null,false,false);
+ // producing new page
+ new ProducerContent().handle(null, null, false, false,cid);
+ //if direct op producing startpage
+ if (directOp.equals("yes")) new ProducerStartPage().handle(null,null);
+
+
+ // sync the server
+ //should be configureable
+ int exitValue = Helper.rsync();
+ theLog.printDebugInfo("rsync: "+exitValue);
+
+ }
+ catch (IOException e) { throw new ServletModuleException("IOException: "+ e.toString());}
+ catch (StorageObjectException e) { throw new ServletModuleException("StorageObjectException" + e.toString());}
+ catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.toString());}
+
+ deliver(req, res, mergeData, postingFormDoneTemplate);
+ }