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 boolean directOp;
42 // Singelton / Kontruktor
43 private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy();
44 public static ServletModule getInstance() { return instance; }
46 private ServletModuleOpenIndy() {
48 theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.OpenIndy.Logfile"));
49 commentFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentTemplate");
50 commentFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentDoneTemplate");
51 postingFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingTemplate");
52 postingFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingDoneTemplate");
53 directOp = Configuration.directOp();
54 mainModule = new ModuleComment(DatabaseComment.getInstance());
55 contentModule = new ModuleContent(DatabaseContent.getInstance());
56 imageModule = new ModuleImages(DatabaseImages.getInstance());
57 defaultAction="addposting";
59 catch (StorageObjectException e) {
60 theLog.printError("servletmoduleopenindy could not be initialized");
66 * Method for making a comment
69 public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
71 String aid = req.getParameter("aid"); // the article id the comment will belong to
72 if (aid!=null && !aid.equals(""))
74 SimpleHash mergeData = new SimpleHash();
76 mergeData.put("aid", aid);
77 deliver(req, res, mergeData, commentFormTemplate);
79 else throw new ServletModuleException("aid not set!");
83 * Method for inserting a comment into the Database and delivering
84 * the commentDone Page
87 public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
89 String aid = req.getParameter("to_media"); // the article id the comment will belong to
90 if (aid!=null && !aid.equals(""))
92 // ok, collecting data from form
94 HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance());
95 withValues.put("is_published","1");
97 // inserting into database
98 String id = mainModule.add(withValues);
100 // producing new page
101 new ProducerContent().handle(null, null, true, false, aid);
104 int exitValue = Helper.rsync();
106 // redirecting to url
107 // should implement back to article
108 SimpleHash mergeData = new SimpleHash();
109 deliver(req, res, mergeData, commentFormDoneTemplate);
111 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
112 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
115 else throw new ServletModuleException("aid not set!");
120 * Method for delivering the form-Page for open posting
123 public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
125 SimpleHash mergeData = new SimpleHash();
126 /** @todo popups missing */
128 mergeData.put("languagePopUpData",DatabaseLanguage.getInstance().getPopupData());
129 } catch (Exception e) {
130 theLog.printError("languagePopUpData failed");
132 deliver(req, res, mergeData, postingFormTemplate);
136 * Method for inserting an open posting into the Database and delivering
137 * the postingDone Page
140 public void insposting(HttpServletRequest req, HttpServletResponse res)
141 throws ServletModuleException
143 SimpleHash mergeData = new SimpleHash();
144 boolean setMedia=false;
148 WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
149 HashMap withValues = mp.getParameters();
150 byte[] mediaData=mp.getMedia();
151 String fileName=mp.getFilename();
153 theLog.printDebugInfo("ContentType: "+mp.getContentType());
155 // if op contains imagedata
157 if (mediaData!=null && fileName!=null) {
158 HashMap mediaValues = new HashMap();
159 mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
160 mediaValues.put("to_publisher", "1"); // op user
161 mediaValues.put("to_media_folder", "7"); // op media_folder
162 mediaValues.put("is_produced", "0");
163 mediaValues.put("is_published","1");
165 String mediaTitle=(String)withValues.get("media_title");
166 if (mediaTitle==null)
167 mediaTitle = (String)withValues.get("title");
168 mediaValues.put("title",mediaTitle);
170 if (fileName.toLowerCase().endsWith("rm")) {
172 //theLog.printDebugInfo("--GOT VIDEO");
173 EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
174 entVideo.setValues(mediaValues);
175 mediaId = entVideo.insert();
176 entVideo.setVideoData(mediaData);
178 else if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) {
180 mediaId = imageModule.add(mediaValues);
181 EntityImage entImage = (EntityImage)imageModule.getById(mediaId);
184 if (fileName.toLowerCase().endsWith(".jpg")) fileType=0;
185 if (fileName.toLowerCase().endsWith(".gif")) fileType=1;
187 entImage.setImage(mediaData, fileType);
191 theLog.printDebugInfo("Wrong file uploaded!" + fileName);
195 withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
196 withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date")));
197 withValues.put("is_produced", "0");
198 // op-articles are immediatly published
199 withValues.put("is_published","1");
200 // if op direct article-type == newswire
201 if (directOp==true) withValues.put("to_article_type","1");
202 // owner is openposting user
203 withValues.put("to_publisher","1");
204 if (withValues.get("creator").toString().equals(""))
205 withValues.put("creator","Anonym");
207 // inserting content into database
208 String id = contentModule.add(withValues);
210 // inserting content and media id in table content_x_media
212 DatabaseContentToMedia.getInstance().setMedia(id,mediaId);
213 theLog.printError("setting content_x_topic success");
214 } catch (Exception e) {
215 theLog.printError("setting content_x_topic failed");
219 // producing new page
221 new ProducerImages().handle(null, null, false, false, mediaId);
223 // producing openpostinglist
224 new ProducerOpenPosting().handle(null,null,false,false);
225 // producing new page
226 new ProducerContent().handle(null, null, false, false,id);
227 //if direct op producing startpage
228 if (directOp==true) new ProducerStartPage().handle(null,null,false,false);
232 //should be configureable
233 int exitValue = Helper.rsync();
236 catch (IOException e) { throw new ServletModuleException(e.toString());}
237 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
238 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
240 deliver(req, res, mergeData, postingFormDoneTemplate);