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 */
+ }
}
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);
+ }
}