support for translations + lots of misc. fixes
[mir.git] / source / mircoders / servlet / ServletModuleContent.java
1 /*\r
2  * Copyright (C) 2001, 2002  The Mir-coders group\r
3  *\r
4  * This file is part of Mir.\r
5  *\r
6  * Mir is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 2 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Mir is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with Mir; if not, write to the Free Software\r
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19  *\r
20  * In addition, as a special exception, The Mir-coders gives permission to link\r
21  * the code of this program with the com.oreilly.servlet library, any library\r
22  * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
23  * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
24  * the above that use the same license as the above), and distribute linked\r
25  * combinations including the two.  You must obey the GNU General Public\r
26  * License in all respects for all of the code used other than the above\r
27  * mentioned libraries.  If you modify this file, you may extend this exception\r
28  * to your version of the file, but you are not obligated to do so.  If you do\r
29  * not wish to do so, delete this exception statement from your version.\r
30  */\r
31 \r
32 package mircoders.servlet;\r
33 \r
34 import java.io.PrintWriter;\r
35 import java.io.IOException;\r
36 import java.util.*;\r
37 \r
38 import javax.servlet.http.HttpServletRequest;\r
39 import javax.servlet.http.HttpServletResponse;\r
40 import javax.servlet.http.HttpSession;\r
41 \r
42 import mir.entity.EntityList;\r
43 import mir.entity.adapter.EntityAdapter;\r
44 import mir.entity.adapter.EntityAdapterModel;\r
45 import mir.entity.adapter.EntityIteratorAdapter;\r
46 import mir.log.LoggerWrapper;\r
47 import mir.misc.StringUtil;\r
48 import mir.module.ModuleException;\r
49 import mir.servlet.ServletModule;\r
50 import mir.servlet.ServletModuleException;\r
51 import mir.storage.StorageObjectFailure;\r
52 import mir.util.CachingRewindableIterator;\r
53 import mir.util.HTMLRoutines;\r
54 import mir.util.JDBCStringRoutines;\r
55 import mir.util.HTTPRequestParser;\r
56 import mir.util.URLBuilder;\r
57 import mir.util.SQLQueryBuilder;\r
58 import mir.log.*;\r
59 \r
60 import mircoders.entity.EntityContent;\r
61 import mircoders.entity.EntityUsers;\r
62 import mircoders.global.MirGlobal;\r
63 import mircoders.module.ModuleContent;\r
64 import mircoders.module.ModuleImages;\r
65 import mircoders.module.ModuleSchwerpunkt;\r
66 import mircoders.module.ModuleTopics;\r
67 import mircoders.search.IndexUtil;\r
68 import mircoders.storage.DatabaseArticleType;\r
69 import mircoders.storage.DatabaseComment;\r
70 import mircoders.storage.DatabaseContent;\r
71 import mircoders.storage.DatabaseContentToTopics;\r
72 import mircoders.storage.DatabaseFeature;\r
73 import mircoders.storage.DatabaseImages;\r
74 import mircoders.storage.DatabaseLanguage;\r
75 import mircoders.storage.DatabaseTopics;\r
76 \r
77 import org.apache.lucene.index.IndexReader;\r
78 \r
79 import freemarker.template.SimpleHash;\r
80 import freemarker.template.SimpleScalar;\r
81 import freemarker.template.TemplateModelRoot;\r
82 \r
83 /*\r
84  *  ServletModuleContent -\r
85  *  deliver html for the article admin form.\r
86  *\r
87  * @version $Id: ServletModuleContent.java,v 1.33 2003/02/20 16:05:34 zapata Exp $\r
88  * @author rk, mir-coders\r
89  *\r
90  */\r
91 \r
92 public class ServletModuleContent extends ServletModule\r
93 {\r
94   private String editTemplate = configuration.getString("ServletModule.Content.ObjektTemplate");;\r
95   private String listTemplate = configuration.getString("ServletModule.Content.ListTemplate");\r
96 \r
97   private static ServletModuleContent instance = new ServletModuleContent();\r
98   public static ServletModule getInstance() { return instance; }\r
99 \r
100   private ServletModuleContent() {\r
101     super();\r
102     logger = new LoggerWrapper("ServletModule.Content");\r
103     try {\r
104 \r
105       templateListString = configuration.getString("ServletModule.Content.ListTemplate");\r
106       templateObjektString = configuration.getString("ServletModule.Content.ObjektTemplate");\r
107       templateConfirmString = configuration.getString("ServletModule.Content.ConfirmTemplate");\r
108 \r
109       mainModule = new ModuleContent(DatabaseContent.getInstance());\r
110     }\r
111     catch (StorageObjectFailure e) {\r
112       logger.error("servletmodulecontent konnte nicht initialisiert werden");\r
113     }\r
114   }\r
115 \r
116   public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException\r
117   {\r
118     HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
119 \r
120     String where = requestParser.getParameter("where");\r
121     String order = requestParser.getParameterWithDefault("order", "webdb_create desc");\r
122     int offset = requestParser.getIntegerWithDefault("offset", 0);\r
123     String selectArticleUrl = requestParser.getParameter("selectarticleurl");\r
124 \r
125     returnArticleList(aRequest, aResponse, where, order, offset, selectArticleUrl);\r
126   }\r
127 \r
128   public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {\r
129     try {\r
130       HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
131       SQLQueryBuilder queryBuilder = new SQLQueryBuilder();\r
132       String searchField = requestParser.getParameterWithDefault("searchfield", "");\r
133       String searchValue = requestParser.getParameterWithDefault("searchvalue", "").trim();\r
134       String searchOrder = requestParser.getParameterWithDefault("searchorder", "");\r
135       String searchispublished = requestParser.getParameterWithDefault("searchispublished", "");\r
136       String searchArticleType = requestParser.getParameterWithDefault("searcharticletype", "");\r
137       String selectArticleUrl = requestParser.getParameter("selectarticleurl");\r
138 \r
139       if (searchValue.length()>0) {\r
140         if (searchField.equals("contents"))\r
141           queryBuilder.appendAndCondition(\r
142             "(lower(content_data) like " + "'%" + JDBCStringRoutines.escapeStringLiteral(searchValue.toLowerCase()) + "%')"+\r
143             " or (lower(description) like " + "'%" + JDBCStringRoutines.escapeStringLiteral(searchValue.toLowerCase()) + "%')");\r
144         else\r
145           queryBuilder.appendAndCondition(\r
146             "lower("+ searchField + ") like " +\r
147             "'%" + JDBCStringRoutines.escapeStringLiteral(searchValue.toLowerCase()) + "%'");\r
148       }\r
149 \r
150       if (searchispublished.length()>0) {\r
151         if (searchispublished.equals("0"))\r
152           queryBuilder.appendAndCondition("is_published='f'");\r
153         else\r
154           queryBuilder.appendAndCondition("is_published='t'");\r
155       }\r
156 \r
157       if (searchArticleType.length()>0) {\r
158         queryBuilder.appendAndCondition("to_article_type="+searchArticleType);\r
159       }\r
160 \r
161       if (searchOrder.length()>0) {\r
162         if (searchOrder.equals("datedesc"))\r
163           queryBuilder.appendAscendingOrder("webdb_create");\r
164         else if (searchOrder.equals("dateasc"))\r
165           queryBuilder.appendDescendingOrder("webdb_create");\r
166         else if (searchOrder.equals("title"))\r
167           queryBuilder.appendDescendingOrder("title");\r
168         else if (searchOrder.equals("creator"))\r
169           queryBuilder.appendDescendingOrder("creator");\r
170       }\r
171 \r
172       returnArticleList(aRequest, aResponse, queryBuilder.getWhereClause(), queryBuilder.getOrderByClause(), 0, selectArticleUrl);\r
173     }\r
174     catch (Throwable e) {\r
175       throw new ServletModuleException(e.toString());\r
176     }\r
177   }\r
178 \r
179   public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException {\r
180     _showObject(null, req, res);\r
181   }\r
182 \r
183 \r
184   public void insert(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException\r
185   {\r
186 //theLog.printDebugInfo(":: content :: trying to insert");\r
187     try {\r
188       EntityUsers   user = _getUser(req);\r
189       HashMap withValues = getIntersectingValues(req, DatabaseContent.getInstance());\r
190 \r
191       String now = StringUtil.date2webdbDate(new GregorianCalendar());\r
192       withValues.put("date", now);\r
193       withValues.put("publish_path", StringUtil.webdbDate2path(now));\r
194       withValues.put("to_publisher", user.getId());\r
195       withValues.put("is_produced", "0");\r
196       if (!withValues.containsKey("is_published"))\r
197         withValues.put("is_published","0");\r
198       if (!withValues.containsKey("is_html"))\r
199         withValues.put("is_html","0");\r
200 \r
201       String id = mainModule.add(withValues);\r
202       DatabaseContentToTopics.getInstance().setTopics(id,req.getParameterValues("to_topic"));\r
203 \r
204       _showObject(id, req, res);\r
205     }\r
206     catch (StorageObjectFailure e) {\r
207       throw new ServletModuleException(e.toString());\r
208     }\r
209     catch (ModuleException e) {\r
210       throw new ServletModuleException(e.toString());\r
211     }\r
212   }\r
213 \r
214   public void delete(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException\r
215   {\r
216     EntityUsers   user = _getUser(req);\r
217 \r
218     String idParam = req.getParameter("id");\r
219     if (idParam == null) throw new ServletModuleException("Invalid call: id missing");\r
220 \r
221     String confirmParam = req.getParameter("confirm");\r
222     String cancelParam = req.getParameter("cancel");\r
223 \r
224     logger.info("where = " + req.getParameter("where"));\r
225 \r
226     if (confirmParam == null && cancelParam == null) {\r
227 \r
228       SimpleHash mergeData = new SimpleHash();\r
229       mergeData.put("module", "Content");\r
230       mergeData.put("infoString", "Content: " + idParam);\r
231       mergeData.put("id", idParam);\r
232       mergeData.put("where", req.getParameter("where"));\r
233       mergeData.put("order", req.getParameter("order"));\r
234       mergeData.put("offset", req.getParameter("offset"));\r
235       deliver(req, res, mergeData, templateConfirmString);\r
236     }\r
237     else {\r
238       if (confirmParam!= null && !confirmParam.equals("")) {\r
239         try {\r
240           mainModule.deleteById(idParam);\r
241 \r
242           /** @todo the following two should be implied in\r
243            *  DatabaseContent */\r
244 \r
245           //delete rows in the content_x_topic-table\r
246           DatabaseContentToTopics.getInstance().deleteByContentId(idParam);\r
247           //delete rows in the comment-table\r
248           DatabaseComment.getInstance().deleteByContentId(idParam);\r
249           //delete from lucene index, if any\r
250           String index = configuration.getString("IndexPath");\r
251           if (IndexReader.indexExists(index)){\r
252             IndexUtil.unindexID(idParam,index);\r
253           }\r
254 \r
255         }\r
256         catch (ModuleException e) {\r
257           throw new ServletModuleException(e.toString());\r
258         }\r
259         catch (StorageObjectFailure e) {\r
260           throw new ServletModuleException(e.toString());\r
261         }\r
262         catch (IOException e) {\r
263           throw new ServletModuleException(e.toString());\r
264         }\r
265         list(req,res);\r
266       }\r
267       else {\r
268         // Datensatz anzeigen\r
269         _showObject(idParam, req, res);\r
270       }\r
271     }\r
272   }\r
273 \r
274   public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException\r
275   {\r
276     String idParam = req.getParameter("id");\r
277     if (idParam == null)\r
278       throw new ServletModuleException("Invalid call: id not supplied ");\r
279     _showObject(idParam, req, res);\r
280   }\r
281 \r
282 // methods for attaching media file\r
283   public void attach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException\r
284   {\r
285     String  mediaIdParam = req.getParameter("mid");\r
286     String  idParam = req.getParameter("cid");\r
287     if (idParam == null||mediaIdParam==null) throw new ServletModuleException("smod content :: attach :: cid/mid missing");\r
288 \r
289     try {\r
290       EntityContent entContent = (EntityContent)mainModule.getById(idParam);\r
291       entContent.attach(mediaIdParam);\r
292     }\r
293     catch(ModuleException e) {\r
294       logger.error("smod content :: attach :: could not get entityContent");\r
295     }\r
296     catch(StorageObjectFailure e) {\r
297       logger.error("smod content :: attach :: could not get entityContent");\r
298     }\r
299 \r
300     _showObject(idParam, req, res);\r
301   }\r
302 \r
303   public void dettach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException\r
304   {\r
305     String  cidParam = req.getParameter("cid");\r
306     String  midParam = req.getParameter("mid");\r
307     if (cidParam == null) throw new ServletModuleException("smod content :: dettach :: cid missing");\r
308     if (midParam == null) throw new ServletModuleException("smod content :: dettach :: mid missing");\r
309 \r
310     try {\r
311       EntityContent entContent = (EntityContent)mainModule.getById(cidParam);\r
312       entContent.dettach(cidParam,midParam);\r
313     }\r
314     catch(ModuleException e) {\r
315       logger.error("smod content :: dettach :: could not get entityContent");\r
316     }\r
317     catch(StorageObjectFailure e) {\r
318       logger.error("smod content :: dettach :: could not get entityContent");\r
319     }\r
320 \r
321     _showObject(cidParam, req, res);\r
322   }\r
323 \r
324   public void update(HttpServletRequest aRequest, HttpServletResponse aResponse)\r
325       throws ServletModuleException\r
326   {\r
327     try {\r
328       HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
329 \r
330       String returnUrl = requestParser.getParameter("returnurl");\r
331 \r
332       String idParam = aRequest.getParameter("id");\r
333       if (idParam == null) throw new ServletModuleException("Wrong call: (id) is missing");\r
334 \r
335       HashMap withValues = getIntersectingValues(aRequest, DatabaseContent.getInstance());\r
336       String[] topic_id = aRequest.getParameterValues("to_topic");\r
337       String content_id = aRequest.getParameter("id");\r
338 \r
339       withValues.put("is_produced", "0");\r
340       if (!withValues.containsKey("is_published"))\r
341         withValues.put("is_published","0");\r
342       if (!withValues.containsKey("is_html"))\r
343         withValues.put("is_html","0");\r
344 \r
345       String id = mainModule.set(withValues);\r
346       DatabaseContentToTopics.getInstance().setTopics(aRequest.getParameter("id"),topic_id);\r
347 \r
348       String whereParam = aRequest.getParameter("where");\r
349       String orderParam = aRequest.getParameter("order");\r
350 \r
351       if (returnUrl!=null){\r
352         redirect(aResponse, returnUrl);\r
353       }\r
354       else\r
355         _showObject(idParam, aRequest, aResponse);\r
356     }\r
357     catch (Throwable e) {\r
358       throw new ServletModuleException(e.toString());\r
359     }\r
360   }\r
361 \r
362 /*\r
363   * HelperMethod shows the basic article editing form.\r
364   *\r
365   * if the "id" parameter is null, it means show an empty form to add a new\r
366   * article.\r
367 */\r
368   private void _showObject(String id, HttpServletRequest aRequest, HttpServletResponse aResponse)\r
369       throws ServletModuleException {\r
370 \r
371     try {\r
372       HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
373       Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest));\r
374       EntityAdapterModel model = MirGlobal.localizer().dataModel().adapterModel();\r
375       Map article;\r
376       URLBuilder urlBuilder = new URLBuilder();\r
377 \r
378       urlBuilder.setValue("module", "Content");\r
379       urlBuilder.setValue("do", "edit");\r
380       urlBuilder.setValue("id", id);\r
381       urlBuilder.setValue("returnurl", requestParser.getParameter("returnurl"));\r
382 \r
383       if (id!=null) {\r
384         responseData.put("new", Boolean.FALSE);\r
385         article = model.makeEntityAdapter("content", mainModule.getById(id));\r
386       }\r
387       else {\r
388         List fields = DatabaseContent.getInstance().getFields();\r
389         responseData.put("new", Boolean.TRUE);\r
390         article = new HashMap();\r
391         Iterator i = fields.iterator();\r
392         while (i.hasNext()) {\r
393           article.put(i.next(), null);\r
394         }\r
395 \r
396         article.put("to_topics", null);\r
397 \r
398         MirGlobal.localizer().adminInterface().initializeArticle(article);\r
399       }\r
400       responseData.put("article", article);\r
401 \r
402       Object languages =\r
403           new CachingRewindableIterator(\r
404             new EntityIteratorAdapter( "", "id", 30,\r
405                MirGlobal.localizer().dataModel().adapterModel(), "language"));\r
406       Object topics =\r
407           new CachingRewindableIterator(\r
408             new EntityIteratorAdapter("", "id", 30,\r
409                MirGlobal.localizer().dataModel().adapterModel(), "topic"));\r
410       Object articleTypes =\r
411           new CachingRewindableIterator(\r
412             new EntityIteratorAdapter( "", "id", 30,\r
413                MirGlobal.localizer().dataModel().adapterModel(), "articleType"));\r
414 \r
415       responseData.put("articleTypes", articleTypes);\r
416       responseData.put("languages", languages);\r
417       responseData.put("topics", topics);\r
418       responseData.put("returnurl", requestParser.getParameter("returnurl"));\r
419       responseData.put("thisurl", urlBuilder.getQuery());\r
420 \r
421       ServletHelper.generateResponse(aResponse.getWriter(), responseData, editTemplate);\r
422     }\r
423     catch (Exception e) {\r
424       throw new ServletModuleException(e.toString());\r
425     }\r
426   }\r
427 \r
428   public void returnArticleList(\r
429        HttpServletRequest aRequest,\r
430        HttpServletResponse aResponse,\r
431        String aWhereClause,\r
432        String anOrderByClause,\r
433        int anOffset,\r
434        String aSelectArticleUrl) throws ServletModuleException {\r
435 \r
436     HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
437     URLBuilder urlBuilder = new URLBuilder();\r
438     EntityAdapterModel model;\r
439     int nrArticlesPerPage = 20;\r
440     int count;\r
441 \r
442     try {\r
443       Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest));\r
444       model = MirGlobal.localizer().dataModel().adapterModel();\r
445 \r
446       Object articleList =\r
447           new CachingRewindableIterator(\r
448             new EntityIteratorAdapter( aWhereClause, anOrderByClause, nrArticlesPerPage,\r
449                MirGlobal.localizer().dataModel().adapterModel(), "content", nrArticlesPerPage, anOffset)\r
450       );\r
451 \r
452       responseData.put("nexturl", null);\r
453       responseData.put("prevurl", null);\r
454 \r
455       count=mainModule.getSize(aWhereClause);\r
456 \r
457       urlBuilder.setValue("module", "Content");\r
458       urlBuilder.setValue("do", "list");\r
459       urlBuilder.setValue("where", aWhereClause);\r
460       urlBuilder.setValue("order", anOrderByClause);\r
461 \r
462 \r
463       urlBuilder.setValue("searchfield", requestParser.getParameter("searchfield"));\r
464       urlBuilder.setValue("searchvalue", requestParser.getParameter("searchvalue"));\r
465       urlBuilder.setValue("searchispublished", requestParser.getParameter("searchispublished"));\r
466       urlBuilder.setValue("searchorder", requestParser.getParameter("searchorder"));\r
467       urlBuilder.setValue("searcharticletype", requestParser.getParameter("searcharticletype"));\r
468       urlBuilder.setValue("selectarticleurl", aSelectArticleUrl);\r
469 \r
470       responseData.put("searchfield", requestParser.getParameter("searchfield"));\r
471       responseData.put("searchvalue", requestParser.getParameter("searchvalue"));\r
472       responseData.put("searchispublished", requestParser.getParameter("searchispublished"));\r
473       responseData.put("searchorder", requestParser.getParameter("searchorder"));\r
474       responseData.put("searcharticletype", requestParser.getParameter("searcharticletype"));\r
475       responseData.put("selectarticleurl", aSelectArticleUrl);\r
476 \r
477       urlBuilder.setValue("offset", anOffset);\r
478       responseData.put("offset" , new Integer(anOffset).toString());\r
479       responseData.put("thisurl" , urlBuilder.getQuery());\r
480 \r
481       if (count>=anOffset+nrArticlesPerPage) {\r
482         urlBuilder.setValue("offset", anOffset + nrArticlesPerPage);\r
483         responseData.put("nexturl" , urlBuilder.getQuery());\r
484       }\r
485 \r
486       if (anOffset>0) {\r
487         urlBuilder.setValue("offset", Math.max(anOffset - nrArticlesPerPage, 0));\r
488         responseData.put("prevurl" , urlBuilder.getQuery());\r
489       }\r
490 \r
491       responseData.put("articles", articleList);\r
492 \r
493       responseData.put("from" , Integer.toString(anOffset+1));\r
494       responseData.put("count", Integer.toString(count));\r
495       responseData.put("to", Integer.toString(Math.min(anOffset+nrArticlesPerPage, count)));\r
496       responseData.put("offset" , Integer.toString(anOffset));\r
497       responseData.put("order", anOrderByClause);\r
498       responseData.put("where" , aWhereClause);\r
499 \r
500       ServletHelper.generateResponse(aResponse.getWriter(), responseData, listTemplate);\r
501     }\r
502     catch (Throwable e) {\r
503       throw new ServletModuleException(e.toString());\r
504     }\r
505   }\r
506 \r
507   public void selectparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException\r
508   {\r
509     try {\r
510       HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
511       URLBuilder urlBuilder = new URLBuilder();\r
512 \r
513       urlBuilder.setValue("module", "Content");\r
514       urlBuilder.setValue("do", "setparent");\r
515       urlBuilder.setValue("childid", requestParser.getParameter("id"));\r
516       urlBuilder.setValue("returnurl", requestParser.getParameter("returnurl"));\r
517 \r
518       returnArticleList(aRequest, aResponse, "", "", 0, urlBuilder.getQuery());\r
519     }\r
520     catch (Throwable e) {\r
521       throw new ServletModuleException(e.getMessage());\r
522     }\r
523   }\r
524 \r
525   public void listchildren(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException\r
526   {\r
527     try {\r
528       HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
529       String articleId = requestParser.getParameter("article_id");\r
530 \r
531       if (articleId == null)\r
532         throw new ServletModuleException("ServletModuleContent.listchildren: article_id not set!");\r
533 \r
534       returnArticleList(aRequest, aResponse, "to_content = " + articleId, "", 0, null);\r
535     }\r
536     catch (Throwable e) {\r
537       throw new ServletModuleException(e.getMessage());\r
538     }\r
539   }\r
540 \r
541   public void setparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException\r
542   {\r
543     HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
544     String articleId = aRequest.getParameter("childid");\r
545     String parentId  = aRequest.getParameter("id");\r
546     String returnUrl = aRequest.getParameter("returnurl");\r
547 \r
548     try {\r
549       EntityContent article = (EntityContent) mainModule.getById(articleId);\r
550       article.setValueForProperty("to_content", parentId);\r
551       article.setProduced(false);\r
552       article.update();\r
553     }\r
554     catch(Throwable e) {\r
555       logger.error("ServletModuleContent.setparent: " + e.getMessage());\r
556       throw new ServletModuleException("ServletModuleContent.setparent: " + e.getMessage());\r
557     }\r
558 \r
559     redirect(aResponse, returnUrl);\r
560   }\r
561 \r
562   public void clearparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException\r
563   {\r
564     HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
565     String articleId = requestParser.getParameter("id");\r
566     String returnUrl = requestParser.getParameter("returnurl");\r
567 \r
568     try {\r
569       EntityContent article = (EntityContent) mainModule.getById(articleId);\r
570       article.setValueForProperty("to_content", "");\r
571       article.setProduced(false);\r
572       article.update();\r
573     }\r
574     catch(Throwable e) {\r
575       e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE));\r
576       logger.error("ServletModuleContent.clearparent: " + e.getMessage());\r
577 \r
578       throw new ServletModuleException("ServletModuleContent.clearparent: " + e.getMessage());\r
579     }\r
580 \r
581     redirect(aResponse, returnUrl);\r
582   }\r
583 \r
584   private EntityUsers _getUser(HttpServletRequest req)\r
585   {\r
586     HttpSession session=req.getSession(false);\r
587 \r
588     return (EntityUsers)session.getAttribute("login.uid");\r
589   }\r
590 }\r