1 package mircoders.servlet;
6 import javax.servlet.*;
7 import javax.servlet.http.*;
9 import freemarker.template.*;
10 import com.oreilly.servlet.multipart.*;
11 import com.oreilly.servlet.*;
19 import mircoders.entity.*;
20 import mircoders.storage.*;
21 import mircoders.module.*;
22 import mircoders.producer.*;
25 * ServletModuleOpenIndy -
26 * is the open-access-servlet, which is responsible for
27 * adding comments to articles &
28 * open-postings to the newswire
33 public class ServletModuleOpenIndy extends ServletModule
36 private String commentFormTemplate, commentFormDoneTemplate;
37 private String postingFormTemplate, postingFormDoneTemplate;
38 private ModuleContent contentModule;
39 private ModuleImages imageModule;
41 // Singelton / Kontruktor
42 private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy();
43 public static ServletModule getInstance() { return instance; }
45 private ServletModuleOpenIndy() {
47 theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.OpenIndy.Logfile"));
48 commentFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentTemplate");
49 commentFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentDoneTemplate");
50 postingFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingTemplate");
51 postingFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingDoneTemplate");
53 mainModule = new ModuleComment(DatabaseComment.getInstance());
54 contentModule = new ModuleContent(DatabaseContent.getInstance());
55 imageModule = new ModuleImages(DatabaseImages.getInstance());
56 defaultAction="addposting";
58 catch (StorageObjectException e) {
59 theLog.printError("servletmoduleopenindy could not be initialized");
65 * Method for making a comment
68 public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
70 String aid = req.getParameter("aid"); // the article id the comment will belong to
71 if (aid!=null && !aid.equals(""))
73 SimpleHash mergeData = new SimpleHash();
75 mergeData.put("aid", aid);
76 deliver(req, res, mergeData, commentFormTemplate);
78 else throw new ServletModuleException("aid not set!");
82 * Method for inserting a comment into the Database and delivering
83 * the commentDone Page
86 public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
88 String aid = req.getParameter("to_media"); // the article id the comment will belong to
89 if (aid!=null && !aid.equals(""))
91 // ok, collecting data from form
93 HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance());
94 withValues.put("is_published","1");
96 // inserting into database
97 String id = mainModule.add(withValues);
100 new ProducerContent().handle(null, null, true, false, aid);
103 int exitValue = Helper.rsync();
105 // redirecting to url
106 // should implement back to article
107 SimpleHash mergeData = new SimpleHash();
108 deliver(req, res, mergeData, commentFormDoneTemplate);
110 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
111 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
114 else throw new ServletModuleException("aid not set!");
119 * Method for delivering the form-Page for open posting
122 public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
124 SimpleHash mergeData = new SimpleHash();
125 /** @todo popups missing */
127 mergeData.put("languagePopUpData",DatabaseLanguage.getInstance().getPopupData());
128 } catch (Exception e) {
129 theLog.printError("languagePopUpData failed");
131 deliver(req, res, mergeData, postingFormTemplate);
135 * Method for inserting an open posting into the Database and delivering
136 * the postingDone Page
139 public void insposting(HttpServletRequest req, HttpServletResponse res)
140 throws ServletModuleException
142 SimpleHash mergeData = new SimpleHash();
143 boolean setMedia=false;
147 WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
148 HashMap withValues = mp.getParameters();
149 byte[] mediaData=mp.getMedia();
150 String fileName=mp.getFilename();
152 theLog.printDebugInfo("ContentType: "+mp.getContentType());
154 // if op contains imagedata
156 if (mediaData!=null && fileName!=null) {
157 HashMap mediaValues = new HashMap();
158 mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
159 mediaValues.put("to_publisher", "1"); // op user
160 mediaValues.put("to_media_folder", "7"); // op media_folder
161 mediaValues.put("is_produced", "0");
162 mediaValues.put("is_published","1");
164 String mediaTitle=(String)withValues.get("media_title");
165 if (mediaTitle==null)
166 mediaTitle = (String)withValues.get("title");
167 mediaValues.put("title",mediaTitle);
169 if (fileName.toLowerCase().endsWith("rm")) {
171 //theLog.printDebugInfo("--GOT VIDEO");
172 EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
173 entVideo.setValues(mediaValues);
174 mediaId = entVideo.insert();
175 entVideo.setVideoData(mediaData);
177 else if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) {
179 mediaId = imageModule.add(mediaValues);
180 EntityImage entImage = (EntityImage)imageModule.getById(mediaId);
183 if (fileName.toLowerCase().endsWith(".jpg")) fileType=0;
184 if (fileName.toLowerCase().endsWith(".gif")) fileType=1;
186 entImage.setImage(mediaData, fileType);
190 theLog.printDebugInfo("Wrong file uploaded!" + fileName);
194 withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
195 withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date")));
196 withValues.put("is_produced", "0");
197 // op-articles are immediatly published
198 withValues.put("is_published","1");
199 // owner is openposting user
200 withValues.put("to_publisher","1");
201 if (withValues.get("creator").toString().equals(""))
202 withValues.put("creator","Anonym");
204 // inserting content into database
205 String id = contentModule.add(withValues);
207 // inserting content and media id in table content_x_media
209 DatabaseContentToMedia.getInstance().setMedia(id,mediaId);
210 theLog.printError("setting content_x_topic success");
211 } catch (Exception e) {
212 theLog.printError("setting content_x_topic failed");
216 // producing new page
218 new ProducerImages().handle(null, null, false, false, mediaId);
220 // producing openpostinglist
221 new ProducerOpenPosting().handle(null,null,false,false);
222 // producing new page
223 new ProducerContent().handle(null, null, false, false,id);
226 //should be configureable
227 int exitValue = Helper.rsync();
230 catch (IOException e) { throw new ServletModuleException(e.toString());}
231 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
232 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
234 deliver(req, res, mergeData, postingFormDoneTemplate);