From d285cdbb4b307fa5bc47e87b62ab269d5fb10e24 Mon Sep 17 00:00:00 2001 From: idfx Date: Sat, 1 Sep 2001 14:17:36 +0000 Subject: [PATCH] *** empty log message *** --- source/mir/misc/Configuration.java | 71 ++-- source/mir/misc/WebdbMultipartRequest.java | 90 +++--- source/mircoders/servlet/ServletModuleContent.java | 20 +- .../mircoders/servlet/ServletModuleOpenIndy.java | 357 +++++++++++---------- 4 files changed, 281 insertions(+), 257 deletions(-) diff --git a/source/mir/misc/Configuration.java b/source/mir/misc/Configuration.java index 1155bf06..f899e0fd 100755 --- a/source/mir/misc/Configuration.java +++ b/source/mir/misc/Configuration.java @@ -23,7 +23,6 @@ public class Configuration { private String confFilename; private static String defaultconfFilename; private static int instances=0; - //static ResourceBundle conf = ResourceBundle.getBundle("config"); static ResourceBundle conf; public static void initConfig(String confName) { @@ -65,40 +64,40 @@ public class Configuration { } - /** - * Fragt ab, ob das Betriebssystem Windows ist. - * @return true wenn ja, sonst false. - */ + /** + * Fragt ab, ob das Betriebssystem Windows ist. + * @return true wenn ja, sonst false. + */ public static boolean isWindows() { return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; } /** - * Liefert Wert einer Property zurueck - * @param propName - * @return Wert der Property - */ + * Liefert Wert einer Property zurueck + * @param propName + * @return Wert der Property + */ public static String getProperty(String propName) { // default return conf.getString(propName); } /** - * Liest eine Property eines Modules aus der Konfiguration - * @param filename - * @param theModule - * @param propName - * @return Wert der Property - */ + * Liest eine Property eines Modules aus der Konfiguration + * @param filename + * @param theModule + * @param propName + * @return Wert der Property + */ public String getProperty(String filename ,String theModule, String propName) { return getProperty(filename, theModule + "." + propName); } - /** - * Liest eine Property aus der Konfiguration - * @param filename - * @param propName - * @return Wert der Property - */ + /** + * Liest eine Property aus der Konfiguration + * @param filename + * @param propName + * @return Wert der Property + */ public static String getProperty(String filename, String propName) { if (filename != null) { String prop = null; @@ -123,11 +122,11 @@ public class Configuration { return null; } - /** - * Liefert DBConnectionBroker einer Configuration zurueck - * @param confFilename - * @return DBConnectionBroker - */ + /** + * Liefert DBConnectionBroker einer Configuration zurueck + * @param confFilename + * @return DBConnectionBroker + */ public static DbConnectionBroker getBroker() { DbConnectionBroker broker=null; broker=(DbConnectionBroker)c.get("Pool.broker"); @@ -137,10 +136,10 @@ public class Configuration { return broker; } - /** - * Liefert Hashtabel mit den Konfigurationen - * @return - */ + /** + * Liefert Hashtabel mit den Konfigurationen + * @return + */ public static HashMap getConfs(){ return confs; } @@ -150,9 +149,9 @@ public class Configuration { } - /** - * Finalize Methode - */ + /** + * Finalize Methode + */ public void finalize(){ instances --; try { @@ -161,9 +160,9 @@ public class Configuration { } /** - * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck - * @return - */ + * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck + * @return + */ public static int getBrokerInstances() { return instances; } diff --git a/source/mir/misc/WebdbMultipartRequest.java b/source/mir/misc/WebdbMultipartRequest.java index 0fd02161..c889c919 100755 --- a/source/mir/misc/WebdbMultipartRequest.java +++ b/source/mir/misc/WebdbMultipartRequest.java @@ -18,53 +18,59 @@ import com.oreilly.servlet.*; public class WebdbMultipartRequest { - HttpServletRequest req=null; - HashMap parameters = new HashMap(); - MultipartParser mp=null; - byte[] uploadData=null; - String fileName=null; + HttpServletRequest req=null; + HashMap parameters = new HashMap(); + MultipartParser mp=null; + byte[] uploadData=null; + String fileName=null; + String fileContentType=null; - public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException - { - req=theReq; - mp = new MultipartParser(req, 1024*8192); // maximum eight megabyte - _evaluateRequest(); - } + public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException + { + req=theReq; + mp = new MultipartParser(req, 1024*8192); // maximum eight megabyte + _evaluateRequest(); + } - public HashMap getParameters(){ - return parameters; - } + public HashMap getParameters(){ + return parameters; + } - public byte[] getMedia() { - return uploadData; - } + public byte[] getMedia() { + return uploadData; + } - public String getFilename() { - return fileName; - } + public String getFilename() { + return fileName; + } + + public String getContentType() { + return fileContentType; + } - private void _evaluateRequest() throws IOException{ + private void _evaluateRequest() throws IOException{ - Part part; - while ((part = mp.readNextPart()) != null) { - String name = part.getName(); - if (part.isParam()) { - // It's a parameter part, add it to the vector of values - ParamPart paramPart = (ParamPart) part; - String value = paramPart.getStringValue(); - parameters.put(name,value); - } - else if (part.isFile()) { - // nur das erste uploadfile beruecksichtigen - FilePart filePart = (FilePart) part; - fileName = filePart.getFileName(); - if (fileName != null) { - ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); - filePart.writeTo(byteStream); - uploadData=byteStream.toByteArray(); - } - } - } // while */ - } + Part part; + while ((part = mp.readNextPart()) != null) { + String name = part.getName(); + if (part.isParam()) { + // It's a parameter part, add it to the vector of values + ParamPart paramPart = (ParamPart) part; + String value = paramPart.getStringValue(); + parameters.put(name,value); + } + else if (part.isFile()) { + // nur das erste uploadfile beruecksichtigen + FilePart filePart = (FilePart) part; + fileName = filePart.getFileName(); + fileContentType = filePart.getContentType(); + if (fileName != null) { + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + filePart.writeTo(byteStream); + uploadData=byteStream.toByteArray(); + } + } + } // while */ + } } diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index 7b46a8fc..e01d76f5 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -152,8 +152,14 @@ public class ServletModuleContent extends ServletModule mergeData.put("gruppenPopupData", gruppenModule.getGruppenAsSimpleList()); try { mergeData.put("articletypePopupData", DatabaseArticleType.getInstance().getPopupData()); - } catch (Exception e) {theLog.printError("articletype could not be fetched.");} - //mergeData.put("gruppenHashData", gruppenModule.getHashData()); + } catch (Exception e) { + theLog.printError("articletype could not be fetched."); + } + try { + mergeData.put("languagePopupData", DatabaseLanguage.getInstance().getPopupData()); + } catch (Exception e) { + theLog.printError("language-popup could not be fetched."); + } mergeData.put("schwerpunktPopupData", schwerpunktModule.getSchwerpunktAsSimpleList()); mergeData.put("login_user", HTMLTemplateProcessor.makeSimpleHash(user)); deliver(req, res, mergeData, templateObjektString); @@ -357,8 +363,14 @@ public class ServletModuleContent extends ServletModule mergeData.put("gruppenPopupData", gruppenModule.getGruppenAsSimpleList()); try { mergeData.put("articletypePopupData", DatabaseArticleType.getInstance().getPopupData()); - } catch (Exception e) {theLog.printError("articletype could not be fetched.");} - + } catch (Exception e) { + theLog.printError("articletype could not be fetched."); + } + try { + mergeData.put("languagePopupData", DatabaseLanguage.getInstance().getPopupData()); + } catch (Exception e) { + theLog.printError("language-popup could not be fetched."); + } // get the images String currentMediaId = entContent.getValue("to_media"); SimpleHash imageHash = new SimpleHash(); diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 5d14c4af..eaedd494 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -33,189 +33,196 @@ import mircoders.producer.*; public class ServletModuleOpenIndy extends ServletModule { - private String commentFormTemplate, commentFormDoneTemplate; - private String postingFormTemplate, postingFormDoneTemplate; - private ModuleContent contentModule; - private ModuleImages imageModule; - - // Singelton / Kontruktor - private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy(); - public static ServletModule getInstance() { return instance; } - - private ServletModuleOpenIndy() { - try { - theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.OpenIndy.Logfile")); - commentFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentTemplate"); - commentFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentDoneTemplate"); - postingFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingTemplate"); - postingFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingDoneTemplate"); - - mainModule = new ModuleComment(DatabaseComment.getInstance()); - contentModule = new ModuleContent(DatabaseContent.getInstance()); - imageModule = new ModuleImages(DatabaseImages.getInstance()); + private String commentFormTemplate, commentFormDoneTemplate; + private String postingFormTemplate, postingFormDoneTemplate; + private ModuleContent contentModule; + private ModuleImages imageModule; + + // Singelton / Kontruktor + private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy(); + public static ServletModule getInstance() { return instance; } + + private ServletModuleOpenIndy() { + try { + theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.OpenIndy.Logfile")); + commentFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentTemplate"); + commentFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentDoneTemplate"); + postingFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingTemplate"); + postingFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingDoneTemplate"); + + mainModule = new ModuleComment(DatabaseComment.getInstance()); + contentModule = new ModuleContent(DatabaseContent.getInstance()); + imageModule = new ModuleImages(DatabaseImages.getInstance()); defaultAction="addposting"; - } - catch (StorageObjectException e) { - theLog.printError("servletmoduleopenindy could not be initialized"); - } - } - - - /** - * Method for making a comment - */ - - public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - String aid = req.getParameter("aid"); // the article id the comment will belong to - if (aid!=null && !aid.equals("")) - { - SimpleHash mergeData = new SimpleHash(); - // ok, article - mergeData.put("aid", aid); - deliver(req, res, mergeData, commentFormTemplate); - } - else throw new ServletModuleException("aid not set!"); - } - - /** - * Method for inserting a comment into the Database and delivering - * the commentDone Page - */ - - public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - String aid = req.getParameter("to_media"); // the article id the comment will belong to - if (aid!=null && !aid.equals("")) - { - // ok, collecting data from form - try { - HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance()); - withValues.put("is_published","1"); - - // inserting into database - String id = mainModule.add(withValues); - - // producing new page - new ProducerContent().handle(null, null, true, false, aid); - - // sync the server - int exitValue = Helper.rsync(); - - // redirecting to url - // should implement back to article - SimpleHash mergeData = new SimpleHash(); - deliver(req, res, mergeData, commentFormDoneTemplate); - } - catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} - catch (ModuleException e) { throw new ServletModuleException(e.toString());} - - } - else throw new ServletModuleException("aid not set!"); - - } - - /** - * Method for delivering the form-Page for open posting - */ - - public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - SimpleHash mergeData = new SimpleHash(); - /** @todo popups missing */ - deliver(req, res, mergeData, postingFormTemplate); - } - - /** - * Method for inserting an open posting into the Database and delivering - * the postingDone Page - */ - - public void insposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - SimpleHash mergeData = new SimpleHash(); - - try { - - WebdbMultipartRequest mp = new WebdbMultipartRequest(req); - HashMap withValues = mp.getParameters(); - byte[] mediaData=mp.getMedia(); - String fileName=mp.getFilename(); - - // if op contains imagedata - String mediaId=null; - if (mediaData!=null && fileName!=null) { - HashMap mediaValues = new HashMap(); - 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 mediaTitle=(String)withValues.get("media_title"); - if (mediaTitle==null) - mediaTitle = (String)withValues.get("title"); - mediaValues.put("title",mediaTitle); - - if (fileName.toLowerCase().endsWith("rm")) { - // this is video !! - //theLog.printDebugInfo("--GOT VIDEO"); - EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance()); - entVideo.setValues(mediaValues); - mediaId = entVideo.insert(); - entVideo.setVideoData(mediaData); - } - else if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) { - // this is image !! - mediaId = imageModule.add(mediaValues); - EntityImage entImage = (EntityImage)imageModule.getById(mediaId); - - int fileType = -1; - if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; - if (fileName.toLowerCase().endsWith(".gif")) fileType=1; - if (fileType>=0) { - entImage.setImage(mediaData, fileType); - withValues.put("to_media",mediaId); - } - else - theLog.printDebugInfo("Wrong file uploaded!" + fileName); - } - } - - withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); - withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date"))); - withValues.put("is_produced", "0"); - // op-articles are immediatly published - withValues.put("is_published","1"); - // owner is openposting user - withValues.put("to_publisher","1"); + } + catch (StorageObjectException e) { + theLog.printError("servletmoduleopenindy could not be initialized"); + } + } + + + /** + * Method for making a comment + */ + + public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + String aid = req.getParameter("aid"); // the article id the comment will belong to + if (aid!=null && !aid.equals("")) + { + SimpleHash mergeData = new SimpleHash(); + // ok, article + mergeData.put("aid", aid); + deliver(req, res, mergeData, commentFormTemplate); + } + else throw new ServletModuleException("aid not set!"); + } + + /** + * Method for inserting a comment into the Database and delivering + * the commentDone Page + */ + + public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + String aid = req.getParameter("to_media"); // the article id the comment will belong to + if (aid!=null && !aid.equals("")) + { + // ok, collecting data from form + try { + HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance()); + withValues.put("is_published","1"); + + // inserting into database + String id = mainModule.add(withValues); + + // producing new page + new ProducerContent().handle(null, null, true, false, aid); + + // sync the server + int exitValue = Helper.rsync(); + + // redirecting to url + // should implement back to article + SimpleHash mergeData = new SimpleHash(); + deliver(req, res, mergeData, commentFormDoneTemplate); + } + catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} + catch (ModuleException e) { throw new ServletModuleException(e.toString());} + + } + else throw new ServletModuleException("aid not set!"); + + } + + /** + * Method for delivering the form-Page for open posting + */ + + public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + SimpleHash mergeData = new SimpleHash(); + /** @todo popups missing */ + try{ + mergeData.put("languagePopUpData",DatabaseLanguage.getInstance().getPopupData()); + } catch (Exception e) { + theLog.printError("languagePopUpData failed"); + } + deliver(req, res, mergeData, postingFormTemplate); + } + + /** + * Method for inserting an open posting into the Database and delivering + * the postingDone Page + */ + + public void insposting(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { + SimpleHash mergeData = new SimpleHash(); + + try { + + WebdbMultipartRequest mp = new WebdbMultipartRequest(req); + HashMap withValues = mp.getParameters(); + byte[] mediaData=mp.getMedia(); + String fileName=mp.getFilename(); + + theLog.printDebugInfo("ContentType: "+mp.getContentType()); + + // if op contains imagedata + String mediaId=null; + if (mediaData!=null && fileName!=null) { + HashMap mediaValues = new HashMap(); + 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 mediaTitle=(String)withValues.get("media_title"); + if (mediaTitle==null) + mediaTitle = (String)withValues.get("title"); + mediaValues.put("title",mediaTitle); + + if (fileName.toLowerCase().endsWith("rm")) { + // this is video !! + //theLog.printDebugInfo("--GOT VIDEO"); + EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance()); + entVideo.setValues(mediaValues); + mediaId = entVideo.insert(); + entVideo.setVideoData(mediaData); + } + else if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) { + // this is image !! + mediaId = imageModule.add(mediaValues); + EntityImage entImage = (EntityImage)imageModule.getById(mediaId); + + int fileType = -1; + if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; + if (fileName.toLowerCase().endsWith(".gif")) fileType=1; + if (fileType>=0) { + entImage.setImage(mediaData, fileType); + withValues.put("to_media",mediaId); + } + else + theLog.printDebugInfo("Wrong file uploaded!" + fileName); + } + } + + withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); + withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date"))); + withValues.put("is_produced", "0"); + // op-articles are immediatly published + withValues.put("is_published","1"); + // owner is openposting user + withValues.put("to_publisher","1"); if (withValues.get("creator").toString().equals("")) - withValues.put("creator","Anonym"); + withValues.put("creator","Anonym"); - // inserting content into database - String id = contentModule.add(withValues); + // inserting content into database + String id = contentModule.add(withValues); - // producing new page - if(mediaId!=null){ - new ProducerImages().handle(null, null, false, false, mediaId); - } - // producing openpostinglist - new ProducerOpenPosting().handle(null,null,false,false); - // producing new page - new ProducerContent().handle(null, null, false, false,id); + // producing new page + if(mediaId!=null){ + new ProducerImages().handle(null, null, false, false, mediaId); + } + // producing openpostinglist + new ProducerOpenPosting().handle(null,null,false,false); + // producing new page + new ProducerContent().handle(null, null, false, false,id); - // sync the server - int exitValue = Helper.rsync(); + // sync the server + int exitValue = Helper.rsync(); - } - catch (IOException e) { throw new ServletModuleException(e.toString());} - catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} - catch (ModuleException e) { throw new ServletModuleException(e.toString());} + } + catch (IOException e) { throw new ServletModuleException(e.toString());} + catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} + catch (ModuleException e) { throw new ServletModuleException(e.toString());} - deliver(req, res, mergeData, postingFormDoneTemplate); - } + deliver(req, res, mergeData, postingFormDoneTemplate); + } } -- 2.11.0