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;
40 private String directOp ="yes";
42 // Singelton / Kontruktor
43 private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy();
44 public static ServletModule getInstance() { return instance; }
46 private ServletModuleOpenIndy() {
48 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.OpenIndy.Logfile"));
49 commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate");
50 commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate");
51 postingFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingTemplate");
52 postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate");
53 directOp = MirConfig.getProp("DirectOpenposting").toLowerCase();
55 mainModule = new ModuleComment(DatabaseComment.getInstance());
56 contentModule = new ModuleContent(DatabaseContent.getInstance());
57 imageModule = new ModuleImages(DatabaseImages.getInstance());
58 defaultAction="addposting";
60 catch (StorageObjectException e) {
61 theLog.printError("servletmoduleopenindy could not be initialized");
67 * Method for making a comment
70 public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
72 String aid = req.getParameter("aid"); // the article id the comment will belong to
73 if (aid!=null && !aid.equals(""))
75 SimpleHash mergeData = new SimpleHash();
77 mergeData.put("aid", aid);
78 deliver(req, res, mergeData, commentFormTemplate);
80 else throw new ServletModuleException("aid not set!");
84 * Method for inserting a comment into the Database and delivering
85 * the commentDone Page
88 public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
90 String aid = req.getParameter("to_media"); // the article id the comment will belong to
91 if (aid!=null && !aid.equals(""))
93 // ok, collecting data from form
95 HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance());
96 withValues.put("is_published","1");
98 // inserting into database
99 String id = mainModule.add(withValues);
101 // producing new page
102 new ProducerContent().handle(null, null, true, false, aid);
105 int exitValue = Helper.rsync();
106 theLog.printDebugInfo("rsync:"+exitValue);
108 // redirecting to url
109 // should implement back to article
110 SimpleHash mergeData = new SimpleHash();
111 deliver(req, res, mergeData, commentFormDoneTemplate);
113 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
114 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
117 else throw new ServletModuleException("aid not set!");
122 * Method for delivering the form-Page for open posting
125 public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
127 SimpleHash mergeData = new SimpleHash();
128 /** @todo popups missing */
130 mergeData.put("languagePopUpData",DatabaseLanguage.getInstance().getPopupData());
131 } catch (Exception e) {
132 theLog.printError("languagePopUpData failed");
134 deliver(req, res, mergeData, postingFormTemplate);
138 * Method for inserting an open posting into the Database and delivering
139 * the postingDone Page
142 public void insposting(HttpServletRequest req, HttpServletResponse res)
143 throws ServletModuleException
145 SimpleHash mergeData = new SimpleHash();
146 boolean setMedia=false;
150 WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
151 HashMap withValues = mp.getParameters();
152 byte[] mediaData=mp.getMedia();
153 String fileName=mp.getFilename();
155 theLog.printDebugInfo("ContentType: "+mp.getContentType());
157 // if op contains imagedata
159 if (mediaData!=null && fileName!=null) {
160 HashMap mediaValues = new HashMap();
161 mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
162 mediaValues.put("to_publisher", "1"); // op user
163 mediaValues.put("to_media_folder", "7"); // op media_folder
164 mediaValues.put("is_produced", "0");
165 mediaValues.put("is_published","1");
167 String mediaTitle=(String)withValues.get("media_title");
168 if (mediaTitle==null)
169 mediaTitle = (String)withValues.get("title");
170 mediaValues.put("title",mediaTitle);
172 if (fileName.toLowerCase().endsWith("rm")) {
174 //theLog.printDebugInfo("--GOT VIDEO");
175 EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
176 entVideo.setValues(mediaValues);
177 mediaId = entVideo.insert();
178 entVideo.setVideoData(mediaData);
180 else if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) {
182 mediaId = imageModule.add(mediaValues);
183 EntityImage entImage = (EntityImage)imageModule.getById(mediaId);
186 if (fileName.toLowerCase().endsWith(".jpg")) fileType=0;
187 if (fileName.toLowerCase().endsWith(".gif")) fileType=1;
189 entImage.setImage(mediaData, fileType);
193 theLog.printDebugInfo("Wrong file uploaded!" + fileName);
197 withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
198 withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date")));
199 withValues.put("is_produced", "0");
200 // op-articles are immediatly published
201 withValues.put("is_published","1");
202 // if op direct article-type == newswire
203 if (directOp.equals("yes")) withValues.put("to_article_type","1");
204 theLog.printDebugInfo("direct op: "+directOp);
206 // owner is openposting user
207 withValues.put("to_publisher","1");
208 if (withValues.get("creator").toString().equals(""))
209 withValues.put("creator","Anonym");
211 // inserting content into database
212 String id = contentModule.add(withValues);
214 // inserting content and media id in table content_x_media
216 DatabaseContentToMedia.getInstance().setMedia(id,mediaId);
217 theLog.printError("setting content_x_topic success");
218 } catch (Exception e) {
219 theLog.printError("setting content_x_topic failed");
223 // producing new page
225 new ProducerImages().handle(null, null, false, false, mediaId);
227 // producing openpostinglist
228 new ProducerOpenPosting().handle(null,null,false,false);
229 // producing new page
230 new ProducerContent().handle(null, null, false, false,id);
231 //if direct op producing startpage
232 if (directOp.equals("yes")) new ProducerStartPage().handle(null,null);
236 //should be configureable
237 int exitValue = Helper.rsync();
238 theLog.printDebugInfo("rsync: "+exitValue);
241 catch (IOException e) { throw new ServletModuleException(e.toString());}
242 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
243 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
245 deliver(req, res, mergeData, postingFormDoneTemplate);