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 */
126 deliver(req, res, mergeData, postingFormTemplate);
130 * Method for inserting an open posting into the Database and delivering
131 * the postingDone Page
134 public void insposting(HttpServletRequest req, HttpServletResponse res)
135 throws ServletModuleException
137 SimpleHash mergeData = new SimpleHash();
141 WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
142 HashMap withValues = mp.getParameters();
143 byte[] mediaData=mp.getMedia();
144 String fileName=mp.getFilename();
146 // if op contains imagedata
148 if (mediaData!=null && fileName!=null) {
149 HashMap mediaValues = new HashMap();
150 mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
151 mediaValues.put("to_publisher", "1"); // op user
152 mediaValues.put("to_media_folder", "7"); // op media_folder
153 mediaValues.put("is_produced", "0");
154 mediaValues.put("is_published","1");
156 String mediaTitle=(String)withValues.get("media_title");
157 if (mediaTitle==null)
158 mediaTitle = (String)withValues.get("title");
159 mediaValues.put("title",mediaTitle);
161 if (fileName.toLowerCase().endsWith("rm")) {
163 //theLog.printDebugInfo("--GOT VIDEO");
164 EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
165 entVideo.setValues(mediaValues);
166 mediaId = entVideo.insert();
167 entVideo.setVideoData(mediaData);
169 else if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) {
171 mediaId = imageModule.add(mediaValues);
172 EntityImage entImage = (EntityImage)imageModule.getById(mediaId);
175 if (fileName.toLowerCase().endsWith(".jpg")) fileType=0;
176 if (fileName.toLowerCase().endsWith(".gif")) fileType=1;
178 entImage.setImage(mediaData, fileType);
179 withValues.put("to_media",mediaId);
182 theLog.printDebugInfo("Wrong file uploaded!" + fileName);
186 withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
187 withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date")));
188 withValues.put("is_produced", "0");
189 // op-articles are immediatly published
190 withValues.put("is_published","1");
191 // owner is openposting user
192 withValues.put("to_publisher","1");
193 if (withValues.get("creator").toString().equals(""))
194 withValues.put("creator","Anonym");
196 // inserting content into database
197 String id = contentModule.add(withValues);
200 // producing new page
202 new ProducerImages().handle(null, null, false, false, mediaId);
204 // producing openpostinglist
205 new ProducerOpenPosting().handle(null,null,false,false);
206 // producing new page
207 new ProducerContent().handle(null, null, false, false,id);
210 int exitValue = Helper.rsync();
213 catch (IOException e) { throw new ServletModuleException(e.toString());}
214 catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
215 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
217 deliver(req, res, mergeData, postingFormDoneTemplate);