From: zapata Date: Thu, 10 Apr 2003 03:31:46 +0000 (+0000) Subject: media in comments, part 1: the admin side X-Git-Tag: BEFORE_MERGE_1_1~187 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=3d6d6279b8ad710d4ec72ddec1976894ef8099a4;p=mir.git media in comments, part 1: the admin side --- diff --git a/dbscripts/create_pg.sql b/dbscripts/create_pg.sql index 41cd7cc2..1e331c33 100755 --- a/dbscripts/create_pg.sql +++ b/dbscripts/create_pg.sql @@ -155,8 +155,8 @@ CREATE TABLE "img_color" ( -- language -CREATE SEQUENCE "language_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; - +CREATE SEQUENCE "language_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + CREATE TABLE "language" ( "id" integer DEFAULT nextval('language_id_seq') NOT NULL, "name" character varying(40) NOT NULL, @@ -220,13 +220,13 @@ CREATE TABLE "content_x_topic" ( -- article type -CREATE SEQUENCE "article_type_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; - +CREATE SEQUENCE "article_type_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + CREATE TABLE "article_type" ( "id" integer DEFAULT nextval('article_type_id_seq') NOT NULL, "name" character varying(40) NOT NULL, CONSTRAINT "article_type_pkey" PRIMARY KEY ("id") -); +); -- -- TOC Entry ID 24 (OID 20183) @@ -261,6 +261,7 @@ CREATE TABLE "comment" ( "address" character varying(80), "phone" character varying(20), "webdb_create" timestamp with time zone NOT NULL, + "webdb_lastchange" timestamp with time zone, "is_published" boolean DEFAULT '1' NOT NULL, "to_language" integer DEFAULT '0' NOT NULL, "to_media" integer NOT NULL, @@ -387,14 +388,14 @@ CREATE TABLE "messages" ( -- comment_status -CREATE SEQUENCE "comment_status_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; - +CREATE SEQUENCE "comment_status_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + CREATE TABLE "comment_status" ( "id" integer DEFAULT nextval('comment_status_id_seq') NOT NULL, "name" character varying(40) NOT NULL, CONSTRAINT "comment_status_pkey" PRIMARY KEY ("id") ); - + -- -- TOC Entry ID 33 (OID 20588) @@ -697,3 +698,10 @@ CREATE INDEX "idx_comment_tomedia_ispublished" on "comment" using btree ( "to_m CREATE UNIQUE INDEX "idx_comment_id" on "comment" using btree ( "id" "int4_ops" ); +CREATE TABLE "comment_x_media" ( + "comment_id" integer, + "media_id" integer +); + +CREATE UNIQUE INDEX idx_comment_media on comment_x_media (comment_id, media_id); +CREATE UNIQUE INDEX idx_media_comment on comment_x_media (media_id, comment_id); diff --git a/dbscripts/updates/update20030409.sql b/dbscripts/updates/update20030409.sql new file mode 100755 index 00000000..366dfbc3 --- /dev/null +++ b/dbscripts/updates/update20030409.sql @@ -0,0 +1,100 @@ +-- update script 2002-12-12 by Zapata +-- * creates table comment_x_media, to support media in comments +-- * adds webdb_lastchange to comment +-- This script will the second time this script is run, +-- so running this script when it isn't needed can't do any harm. +-- +-- IMPORTANT: after running this script, run the update_all_sequences script as well + +BEGIN TRANSACTION; + +-- task 1: comment_x_media + +CREATE TABLE comment_x_media ( + comment_id integer, + media_id integer +); + +CREATE UNIQUE INDEX idx_comment_media on comment_x_media (comment_id, media_id); +CREATE UNIQUE INDEX idx_media_comment on comment_x_media (media_id, comment_id); + +-- task 2: add webdb_lastchange to table comment + + ALTER TABLE "comment" RENAME TO "comment_old"; + DROP INDEX comment_pkey; + + CREATE TABLE "comment" ( + "id" integer DEFAULT nextval('comment_id_seq') NOT NULL, + "title" character varying(80) NOT NULL, + "creator" character varying(80) NOT NULL, + "description" text NOT NULL, + "main_url" character varying(255), + "email" character varying(80), + "address" character varying(80), + "phone" character varying(20), + "webdb_create" timestamp with time zone NOT NULL, + "webdb_lastchange" timestamp with time zone, + "is_published" boolean DEFAULT '1' NOT NULL, + "to_language" integer DEFAULT '0' NOT NULL, + "to_media" integer NOT NULL, + "to_comment_status" smallint, + "checksum" integer, + "is_html" boolean DEFAULT '0' NOT NULL, + Constraint "comment_pkey" Primary Key ("id") + ); + + INSERT INTO "comment" ( + "id", + "title", + "creator", + "description", + "main_url", + "email", + "address", + "phone", + "webdb_create", + "webdb_lastchange", + "is_published", + "to_language", + "to_media", + "to_comment_status", + "checksum", + "is_html" + ) + SELECT + "id", + "title", + "creator", + "description", + "main_url", + "email", + "address", + "phone", + "webdb_create", + "webdb_create", + "is_published", + "to_language", + "to_media", + "to_comment_status", + "checksum", + "is_html" + FROM "comment_old"; + + UPDATE pg_class + SET + relowner = (SELECT relowner FROM pg_class WHERE relname='comment_old'), + relacl = (SELECT relacl FROM pg_class WHERE relname='comment_old') + WHERE + relname = 'comment'; + + DROP TABLE "comment_old"; + + CREATE INDEX "comment_checksum_index" on "comment" using btree ( "checksum" "int4_ops" ); + CREATE INDEX "idx_comment_to_media" on "comment" using btree ( "to_media" "int4_ops" ); + create index idx_comment_webdb_create on comment(webdb_create); + CREATE INDEX "idx_comment_tomedia_ispublished" on "comment" using btree ( "to_media" "int4_ops", "is_published" "bool_ops" ); + CREATE UNIQUE INDEX "idx_comment_id" on "comment" using btree ( "id" "int4_ops" ); + +-- that's it! + +COMMIT TRANSACTION; diff --git a/source/mircoders/entity/EntityComment.java b/source/mircoders/entity/EntityComment.java index cfec128b..bf4283f9 100755 --- a/source/mircoders/entity/EntityComment.java +++ b/source/mircoders/entity/EntityComment.java @@ -1,84 +1,131 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.entity; - -import java.util.Map; - -import mir.entity.Entity; -import mir.storage.StorageObject; - -/** - * This class maps one line of the comment-table to a java-object. - * - * @author $Author: zapata $ - * @version $Revision: 1.14 $ $Date: 2003/03/04 22:00:52 $ - */ - - -public class EntityComment extends Entity -{ - - public EntityComment() - { - super(); - } - - public EntityComment(StorageObject theStorage) { - this(); - setStorage(theStorage); - } - - - /** - * overridden method setValues to patch creator_main_url - */ - public void setValues(Map theStringValues) - { - if (theStringValues != null) { - if (!theStringValues.containsKey("is_published")) { - theStringValues.put("is_published","0"); - } - - if (theStringValues.containsKey("main_url")){ - if (((String)theStringValues.get("main_url")).equalsIgnoreCase("http://")) { - theStringValues.remove("main_url"); - } - else if ((!((String)theStringValues.get("main_url")).startsWith("http://")) - && ((String)theStringValues.get("main_url")).length()>0) { - theStringValues.put("main_url","http://"+((String)theStringValues.get("main_url"))); - } - } - - } - super.setValues(theStringValues); - } -} +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.entity; + +import java.util.Map; + +import mir.entity.Entity; +import mir.storage.StorageObject; +import mir.storage.StorageObjectFailure; +import mircoders.storage.DatabaseCommentToMedia; +import mircoders.storage.DatabaseContent; + +/** + * This class maps one line of the comment-table to a java-object. + * + * @author $Author: zapata $ + * @version $Revision: 1.15 $ $Date: 2003/04/10 03:31:46 $ + */ + + +public class EntityComment extends Entity +{ + + public EntityComment() + { + super(); + } + + public EntityComment(StorageObject theStorage) { + this(); + setStorage(theStorage); + } + + + /** + * overridden method setValues to patch creator_main_url + */ + public void setValues(Map theStringValues) + { + if (theStringValues != null) { + if (!theStringValues.containsKey("is_published")) { + theStringValues.put("is_published","0"); + } + + if (theStringValues.containsKey("main_url")){ + if (((String)theStringValues.get("main_url")).equalsIgnoreCase("http://")) { + theStringValues.remove("main_url"); + } + else if ((!((String)theStringValues.get("main_url")).startsWith("http://")) + && ((String)theStringValues.get("main_url")).length()>0) { + theStringValues.put("main_url","http://"+((String)theStringValues.get("main_url"))); + } + } + + } + super.setValues(theStringValues); + } + + /** + * Deattaches media from a comment + * + * @param aCommentId + * @param aMediaId + * @throws StorageObjectFailure + */ + public void dettach(String aCommentId,String aMediaId) throws StorageObjectFailure + { + if (aMediaId!=null){ + try{ + DatabaseCommentToMedia.getInstance().delete(aCommentId, aMediaId); + } + catch (Exception e){ + throwStorageObjectFailure(e, "dettach: failed to get instance"); + } + + DatabaseContent.getInstance().setUnproduced("id="+getValue("to_media")); + } + } + + /** + * + * @param aMediaId + * @throws StorageObjectFailure + */ + + public void attach(String aMediaId) throws StorageObjectFailure + { + if (aMediaId!=null) { + try{ + DatabaseCommentToMedia.getInstance().addMedia(getId(), aMediaId); + } + catch(StorageObjectFailure e){ + throwStorageObjectFailure(e, "attach: could not get the instance"); + } + + DatabaseContent.getInstance().setUnproduced("id="+getValue("to_media")); + } + else { + logger.error("EntityContent: attach without mid"); + } + } +} diff --git a/source/mircoders/entity/EntityContent.java b/source/mircoders/entity/EntityContent.java index 3e6bbb30..46bc838e 100755 --- a/source/mircoders/entity/EntityContent.java +++ b/source/mircoders/entity/EntityContent.java @@ -54,7 +54,7 @@ import freemarker.template.TemplateModelException; * this class implements mapping of one line of the database table content * to a java object * - * @version $Id: EntityContent.java,v 1.17 2003/03/05 19:23:15 idfx Exp $ + * @version $Id: EntityContent.java,v 1.18 2003/04/10 03:31:47 zapata Exp $ * @author mir-coders group * */ @@ -85,6 +85,7 @@ public class EntityContent extends Entity public EntityContent(StorageObject theStorage) { this(); + setStorage(theStorage); } @@ -119,56 +120,43 @@ public class EntityContent extends Entity } } - - /** - * make openposting to newswire - */ - - public void newswire() throws StorageObjectFailure - { - String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'"; - try { - theStorageObject.executeUpdate(sql); - } catch (StorageObjectFailure e) { - throwStorageObjectFailure(e, "\n -- newswire failed"); - } catch (SQLException e) { - throwStorageObjectFailure(e, "\n -- newswire failed"); - } - } - - /** - * dettach from media + * Deattaches media from an article + * + * @param anArticleId + * @param aMediaId + * @throws StorageObjectFailure */ - public void dettach(String cid,String mid) throws StorageObjectFailure + public void dettach(String anArticleId, String aMediaId) throws StorageObjectFailure { - if (mid!=null){ + if (aMediaId!=null){ try{ - DatabaseContentToMedia.getInstance().delete(cid,mid); + DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId); } catch (Exception e){ throwStorageObjectFailure(e, "\n -- failed to get instance"); } - //set Content to unproduced setProduced(false); } } /** - * attach to media + * Attaches media to an article + * + * @param mid + * @throws StorageObjectFailure */ - public void attach(String mid) throws StorageObjectFailure + public void attach(String aMediaId) throws StorageObjectFailure { - if (mid!=null) { - //write media-id mid and content-id in table content_x_media + if (aMediaId!=null) { try{ - DatabaseContentToMedia.getInstance().addMedia(getId(),mid); - } catch(StorageObjectFailure e){ + DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId); + } + catch(StorageObjectFailure e){ throwStorageObjectFailure(e, "attach: could not get the instance"); } - //set Content to unproduced setProduced(false); } else { diff --git a/source/mircoders/entity/EntityUploadedMedia.java b/source/mircoders/entity/EntityUploadedMedia.java index ecff9254..13e34d89 100755 --- a/source/mircoders/entity/EntityUploadedMedia.java +++ b/source/mircoders/entity/EntityUploadedMedia.java @@ -31,29 +31,26 @@ package mircoders.entity; -import java.util.Map; -import java.sql.SQLException; - -import freemarker.template.SimpleList; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; - -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.log.LoggerWrapper; -import mir.media.MediaHelper; -import mir.media.MirMedia; -import mir.misc.NumberUtils; -import mir.storage.StorageObject; -import mir.storage.StorageObjectFailure; -import mircoders.storage.DatabaseContentToMedia; +import java.sql.SQLException; +import java.util.Map; + +import freemarker.template.SimpleList; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; +import mir.entity.Entity; +import mir.log.LoggerWrapper; +import mir.media.MediaHelper; +import mir.media.MirMedia; +import mir.misc.NumberUtils; +import mir.storage.StorageObject; +import mir.storage.StorageObjectFailure; import mircoders.storage.DatabaseUploadedMedia; /** * * @author mh, mir-coders group - * @version $Id: EntityUploadedMedia.java,v 1.24 2003/03/16 19:54:45 zapata Exp $ + * @version $Id: EntityUploadedMedia.java,v 1.25 2003/04/10 03:31:47 zapata Exp $ */ diff --git a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java index 859da23a..e7d7857b 100755 --- a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java @@ -97,11 +97,16 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'")); anEntityAdapterDefinition.addCalculatedField("fullcommentcount", new ContentCommentCountField("")); - anEntityAdapterDefinition.addCalculatedField("to_media_images", new ContentToMediaField( "image" )); anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new ContentToMediaField( "uploadedMedia" )); + anEntityAdapterDefinition.addCalculatedField("to_media_images", new ContentToMediaField( "image" )); anEntityAdapterDefinition.addCalculatedField("to_media_audio", new ContentToMediaField( "audio" )); anEntityAdapterDefinition.addCalculatedField("to_media_video", new ContentToMediaField( "video" )); anEntityAdapterDefinition.addCalculatedField("to_media_other", new ContentToMediaField( "otherMedia" )); + anEntityAdapterDefinition.addCalculatedField("to_all_uploaded_media", new ContentToMediaField( "uploadedMedia", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_images", new ContentToMediaField( "image", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_audio", new ContentToMediaField( "audio", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_video", new ContentToMediaField( "video", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new ContentToMediaField( "otherMedia", false)); anEntityAdapterDefinition.addCalculatedField("to_media_icon", new ContentToIconField()); anEntityAdapterDefinition.addCalculatedField("article_type", new ContentToArticleTypeField()); @@ -126,6 +131,17 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { anEntityAdapterDefinition.addCalculatedField("to_content", new CommentToContentField()); anEntityAdapterDefinition.addCalculatedField("status", new CommentToStatusField()); + anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new CommentToMediaField( "uploadedMedia" )); + anEntityAdapterDefinition.addCalculatedField("to_media_images", new CommentToMediaField( "image" )); + anEntityAdapterDefinition.addCalculatedField("to_media_audio", new CommentToMediaField( "audio" )); + anEntityAdapterDefinition.addCalculatedField("to_media_video", new CommentToMediaField( "video" )); + anEntityAdapterDefinition.addCalculatedField("to_media_other", new CommentToMediaField( "otherMedia" )); + anEntityAdapterDefinition.addCalculatedField("to_all_uploaded_media", new CommentToMediaField( "uploadedMedia", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_images", new CommentToMediaField( "image", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_audio", new CommentToMediaField( "audio", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_video", new CommentToMediaField( "video", false)); + anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new CommentToMediaField( "otherMedia", false)); + anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description")); anEntityAdapterDefinition.addCalculatedField("operations", new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleCommentOperations())); @@ -342,16 +358,54 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } protected class ContentToMediaField implements EntityAdapterDefinition.CalculatedField { - String definition; + private String definition; + private boolean published; + + public ContentToMediaField(String aDefinition, boolean anOnlyPublished) { + definition = aDefinition; + published = anOnlyPublished; + } public ContentToMediaField(String aDefinition) { + this(aDefinition, true); + } + + public Object getValue(EntityAdapter anEntityAdapter) { + try { + String condition = "exists (select * from content_x_media where content_id="+anEntityAdapter.get("id")+" and media_id=id)"; + if (published) + condition = "is_published='t' and " + condition; + return anEntityAdapter.getRelation( + condition, + "id", + definition); + } + catch (Throwable t) { + throw new RuntimeException(t.getMessage()); + } + } + } + + protected class CommentToMediaField implements EntityAdapterDefinition.CalculatedField { + private String definition; + private boolean published; + + public CommentToMediaField(String aDefinition, boolean anOnlyPublished) { definition = aDefinition; + published = anOnlyPublished; + } + + public CommentToMediaField(String aDefinition) { + this(aDefinition, true); } public Object getValue(EntityAdapter anEntityAdapter) { try { + String condition = "exists (select * from comment_x_media where comment_id="+anEntityAdapter.get("id")+" and media_id=id)"; + if (published) + condition = "is_published='t' and " + condition; return anEntityAdapter.getRelation( - "is_published='t' and exists (select * from content_x_media where content_id="+anEntityAdapter.get("id")+" and media_id=id)", + condition, "id", definition); } diff --git a/source/mircoders/servlet/ServletModuleComment.java b/source/mircoders/servlet/ServletModuleComment.java index 50173476..7fb3b819 100755 --- a/source/mircoders/servlet/ServletModuleComment.java +++ b/source/mircoders/servlet/ServletModuleComment.java @@ -1,262 +1,316 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.servlet; - -import java.util.Map; -import java.util.Locale; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import mir.config.MirPropertiesConfiguration; -import mir.entity.adapter.EntityAdapterModel; -import mir.entity.adapter.EntityIteratorAdapter; -import mir.log.LoggerWrapper; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleExc; -import mir.servlet.ServletModuleFailure; -import mir.util.CachingRewindableIterator; -import mir.util.HTTPRequestParser; -import mir.util.JDBCStringRoutines; -import mir.util.SQLQueryBuilder; -import mir.util.URLBuilder; -import mircoders.global.MirGlobal; -import mircoders.module.ModuleComment; -import mircoders.module.ModuleContent; -import mircoders.storage.DatabaseComment; -import mircoders.storage.DatabaseCommentStatus; -import mircoders.storage.DatabaseContent; -import mircoders.storage.DatabaseLanguage; -import freemarker.template.SimpleHash; -import freemarker.template.TemplateModelRoot; - -/* - * ServletModuleComment - controls navigation for Comments - * - * - * @author RK - */ - -public class ServletModuleComment extends ServletModule -{ - - private ModuleContent moduleContent; - - // Singelton / Kontruktor - private static ServletModuleComment instance = new ServletModuleComment(); - public static ServletModule getInstance() { return instance; } - - private ServletModuleComment() { - logger = new LoggerWrapper("ServletModule.Comment"); - - - try { - configuration = MirPropertiesConfiguration.instance(); - templateListString = configuration.getString("ServletModule.Comment.ListTemplate"); - templateObjektString = configuration.getString("ServletModule.Comment.ObjektTemplate"); - templateConfirmString = configuration.getString("ServletModule.Comment.ConfirmTemplate"); - - mainModule = new ModuleComment(DatabaseComment.getInstance()); - moduleContent = new ModuleContent(DatabaseContent.getInstance()); - } - catch (Exception e) { - logger.error("servletmodule comment could not be initialized:" + e.getMessage()); - } - } - - public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc - { - String idParam = req.getParameter("id"); - - if (idParam == null) - throw new ServletModuleExc("Invalid call: id not supplied "); - - showComment(idParam, req, res); - } - - public void showComment(String anId, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { - try { - SimpleHash extraInfo = new SimpleHash(); - TemplateModelRoot data; - - data = (TemplateModelRoot) mainModule.getById(anId); - - extraInfo.put("languages", DatabaseLanguage.getInstance().getPopupData()); - extraInfo.put("comment_status_values", DatabaseCommentStatus.getInstance().getPopupData()); - - deliver(aRequest, aResponse, data, extraInfo, templateObjektString); - } - catch (Throwable e) { - throw new ServletModuleFailure(e); - } - } - - - public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc - { - HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); - - String where = requestParser.getParameter("where"); - String order = requestParser.getParameterWithDefault("order", "webdb_create desc"); - int offset = requestParser.getIntegerWithDefault("offset", 0); - - returnCommentList(aRequest, aResponse, where, order, offset); - } - - public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc - { - HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); - SQLQueryBuilder queryBuilder = new SQLQueryBuilder(); - - String queryField = ""; - String searchField = requestParser.getParameter("searchfield"); - String searchText = requestParser.getParameter("searchtext"); - String searchIsPublished = requestParser.getParameter("searchispublished"); - String searchStatus = requestParser.getParameter("searchstatus"); - String searchOrder = requestParser.getParameter("searchorder"); - - if (searchIsPublished.equals("0")) { - queryBuilder.appendAndCondition("is_published='f'"); - } - else if (searchIsPublished.equals("1")) { - queryBuilder.appendAndCondition("is_published='t'"); - } - - if (searchText.length()>0) { - queryBuilder.appendAndCondition( - "lower("+ searchField + ") like " + - "'%" + JDBCStringRoutines.escapeStringLiteral(searchText.toLowerCase()) + "%'"); - } - - if (searchStatus.length()>0) { - queryBuilder.appendAndCondition("to_comment_status="+Integer.parseInt(searchStatus)); - } - - if (searchOrder.length()>0) { - if (searchOrder.equals("datedesc")) - queryBuilder.appendAscendingOrder("webdb_create"); - else if (searchOrder.equals("dateasc")) - queryBuilder.appendDescendingOrder("webdb_create"); - else if (searchOrder.equals("articletitle")) - queryBuilder.appendAscendingOrder("(select content.title from content where content.id = comment.to_media)"); - else if (searchOrder.equals("creator")) - queryBuilder.appendDescendingOrder("creator"); - } - - returnCommentList(aRequest, aResponse, queryBuilder.getWhereClause(), queryBuilder.getOrderByClause(), 0); - } - - public void articlecomments(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc - { - String articleIdString = req.getParameter("articleid"); - int articleId; - - try { - articleId = Integer.parseInt(articleIdString); - - returnCommentList( req, res, "to_media="+articleId, "webdb_create desc", 0); - } - catch (Throwable e) { - throw new ServletModuleFailure(e); - } - } - - public void returnCommentList(HttpServletRequest aRequest, HttpServletResponse aResponse, - String aWhereClause, String anOrderByClause, int anOffset) throws ServletModuleExc { - // ML: experiment in using the producer's generation system instead of the - // old one... - - HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); - URLBuilder urlBuilder = new URLBuilder(); - EntityAdapterModel model; - int nrCommentsPerPage = 20; - int count; - - try { - Map responseData = ServletHelper.makeGenerationData(new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)}); - model = MirGlobal.localizer().dataModel().adapterModel(); - - Object commentList = - new CachingRewindableIterator( - new EntityIteratorAdapter( aWhereClause, anOrderByClause, nrCommentsPerPage, - MirGlobal.localizer().dataModel().adapterModel(), "comment", nrCommentsPerPage, anOffset) - ); - - responseData.put("nexturl", null); - responseData.put("prevurl", null); - - count=mainModule.getSize(aWhereClause); - - urlBuilder.setValue("module", "Comment"); - urlBuilder.setValue("do", "list"); - urlBuilder.setValue("where", aWhereClause); - urlBuilder.setValue("order", anOrderByClause); - - urlBuilder.setValue("searchfield", requestParser.getParameter("searchfield")); - urlBuilder.setValue("searchtext", requestParser.getParameter("searchtext")); - urlBuilder.setValue("searchispublished", requestParser.getParameter("searchispublished")); - urlBuilder.setValue("searchstatus", requestParser.getParameter("searchstatus")); - urlBuilder.setValue("searchorder", requestParser.getParameter("searchorder")); - - responseData.put("searchfield", requestParser.getParameter("searchfield")); - responseData.put("searchtext", requestParser.getParameter("searchtext")); - responseData.put("searchispublished", requestParser.getParameter("searchispublished")); - responseData.put("searchstatus", requestParser.getParameter("searchstatus")); - responseData.put("searchorder", requestParser.getParameter("searchorder")); - - urlBuilder.setValue("offset", anOffset); - responseData.put("offset" , new Integer(anOffset).toString()); - responseData.put("thisurl" , urlBuilder.getQuery()); - - if (count>=anOffset+nrCommentsPerPage) { - urlBuilder.setValue("offset", anOffset + nrCommentsPerPage); - responseData.put("nexturl" , urlBuilder.getQuery()); - } - - if (anOffset>0) { - urlBuilder.setValue("offset", Math.max(anOffset - nrCommentsPerPage, 0)); - responseData.put("prevurl" , urlBuilder.getQuery()); - } - - responseData.put("comments", commentList); - responseData.put("from" , Integer.toString(anOffset+1)); - responseData.put("count", Integer.toString(count)); - responseData.put("to", Integer.toString(Math.min(anOffset+nrCommentsPerPage, count))); - - ServletHelper.generateResponse(aResponse.getWriter(), responseData, "commentlist.template"); - } - catch (Throwable e) { - throw new ServletModuleFailure(e); - } - } -} - +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.servlet; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import mir.config.MirPropertiesConfiguration; +import mir.entity.adapter.EntityAdapterModel; +import mir.entity.adapter.EntityIteratorAdapter; +import mir.log.LoggerWrapper; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; +import mir.util.CachingRewindableIterator; +import mir.util.HTTPRequestParser; +import mir.util.JDBCStringRoutines; +import mir.util.SQLQueryBuilder; +import mir.util.URLBuilder; +import mircoders.entity.EntityComment; +import mircoders.global.MirGlobal; +import mircoders.module.ModuleComment; +import mircoders.module.ModuleContent; +import mircoders.storage.DatabaseComment; +import mircoders.storage.DatabaseContent; + +/* + * ServletModuleComment - controls navigation for Comments + * + * + * @author RK + */ + +public class ServletModuleComment extends ServletModule +{ + private ModuleContent moduleContent; + + private static ServletModuleComment instance = new ServletModuleComment(); + public static ServletModule getInstance() { return instance; } + + private ServletModuleComment() { + logger = new LoggerWrapper("ServletModule.Comment"); + try { + configuration = MirPropertiesConfiguration.instance(); + templateListString = configuration.getString("ServletModule.Comment.ListTemplate"); + templateObjektString = configuration.getString("ServletModule.Comment.ObjektTemplate"); + templateConfirmString = configuration.getString("ServletModule.Comment.ConfirmTemplate"); + + mainModule = new ModuleComment(DatabaseComment.getInstance()); + moduleContent = new ModuleContent(DatabaseContent.getInstance()); + } + catch (Exception e) { + logger.error("servletmodule comment could not be initialized:" + e.getMessage()); + } + } + + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc + { + String idParam = req.getParameter("id"); + + if (idParam == null) + throw new ServletModuleExc("Invalid call: id not supplied "); + + showComment(idParam, req, res); + } + + public void showComment(String anId, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { + try { + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + Map responseData = ServletHelper.makeGenerationData(new Locale[] {getLocale(aRequest), getFallbackLocale(aRequest)}); + EntityAdapterModel model = MirGlobal.localizer().dataModel().adapterModel(); + Map comment; + URLBuilder urlBuilder = new URLBuilder(); + + urlBuilder.setValue("module", "Comment"); + urlBuilder.setValue("do", "edit"); + urlBuilder.setValue("id", anId); + urlBuilder.setValue("returnurl", requestParser.getParameter("returnurl")); + + if (anId != null) { + responseData.put("new", Boolean.FALSE); + comment = model.makeEntityAdapter("comment", mainModule.getById(anId)); + } + else { + List fields = DatabaseComment.getInstance().getFields(); + responseData.put("new", Boolean.TRUE); + comment = new HashMap(); + Iterator i = fields.iterator(); + while (i.hasNext()) { + comment.put(i.next(), null); + } + +// MirGlobal.localizer().adminInterface().initializeArticle(article); + } + responseData.put("comment", comment); + + responseData.put("returnurl", requestParser.getParameter("returnurl")); + responseData.put("thisurl", urlBuilder.getQuery()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, templateObjektString); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } + + public void attach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc + { + String mediaIdParam = req.getParameter("mid"); + String commentId = req.getParameter("commentid"); + + if (commentId == null || mediaIdParam==null) throw new ServletModuleExc("smod comment :: attach :: commentid/mid missing"); + + try { + EntityComment comment = (EntityComment) mainModule.getById(commentId); + comment.attach(mediaIdParam); + } + catch(Throwable e) { + throw new ServletModuleFailure(e); + } + + showComment(commentId, req, res); + } + + public void dettach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc + { + String commentId = req.getParameter("commentid"); + String midParam = req.getParameter("mid"); + if (commentId == null) + throw new ServletModuleExc("smod comment :: dettach :: commentid missing"); + if (midParam == null) + throw new ServletModuleExc("smod comment :: dettach :: mid missing"); + + try { + EntityComment comment = (EntityComment)mainModule.getById(commentId); + comment.dettach(commentId, midParam); + } + catch(Throwable e) { + throw new ServletModuleFailure(e); + } + + showComment(commentId, req, res); + } + + + public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc + { + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + + String where = requestParser.getParameter("where"); + String order = requestParser.getParameterWithDefault("order", "webdb_create desc"); + int offset = requestParser.getIntegerWithDefault("offset", 0); + + returnCommentList(aRequest, aResponse, where, order, offset); + } + + public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc + { + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + SQLQueryBuilder queryBuilder = new SQLQueryBuilder(); + + String queryField = ""; + String searchField = requestParser.getParameter("searchfield"); + String searchText = requestParser.getParameter("searchtext"); + String searchIsPublished = requestParser.getParameter("searchispublished"); + String searchStatus = requestParser.getParameter("searchstatus"); + String searchOrder = requestParser.getParameter("searchorder"); + + if (searchIsPublished.equals("0")) { + queryBuilder.appendAndCondition("is_published='f'"); + } + else if (searchIsPublished.equals("1")) { + queryBuilder.appendAndCondition("is_published='t'"); + } + + if (searchText.length()>0) { + queryBuilder.appendAndCondition( + "lower("+ searchField + ") like " + + "'%" + JDBCStringRoutines.escapeStringLiteral(searchText.toLowerCase()) + "%'"); + } + + if (searchStatus.length()>0) { + queryBuilder.appendAndCondition("to_comment_status="+Integer.parseInt(searchStatus)); + } + + if (searchOrder.length()>0) { + if (searchOrder.equals("datedesc")) + queryBuilder.appendAscendingOrder("webdb_create"); + else if (searchOrder.equals("dateasc")) + queryBuilder.appendDescendingOrder("webdb_create"); + else if (searchOrder.equals("articletitle")) + queryBuilder.appendAscendingOrder("(select content.title from content where content.id = comment.to_media)"); + else if (searchOrder.equals("creator")) + queryBuilder.appendDescendingOrder("creator"); + } + + returnCommentList(aRequest, aResponse, queryBuilder.getWhereClause(), queryBuilder.getOrderByClause(), 0); + } + + public void articlecomments(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc + { + String articleIdString = req.getParameter("articleid"); + int articleId; + + try { + articleId = Integer.parseInt(articleIdString); + + returnCommentList( req, res, "to_media="+articleId, "webdb_create desc", 0); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } + + public void returnCommentList(HttpServletRequest aRequest, HttpServletResponse aResponse, + String aWhereClause, String anOrderByClause, int anOffset) throws ServletModuleExc { + + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + URLBuilder urlBuilder = new URLBuilder(); + EntityAdapterModel model; + int nrCommentsPerPage = 20; + int count; + + try { + Map responseData = ServletHelper.makeGenerationData(new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)}); + model = MirGlobal.localizer().dataModel().adapterModel(); + + Object commentList = + new CachingRewindableIterator( + new EntityIteratorAdapter( aWhereClause, anOrderByClause, nrCommentsPerPage, + MirGlobal.localizer().dataModel().adapterModel(), "comment", nrCommentsPerPage, anOffset) + ); + + responseData.put("nexturl", null); + responseData.put("prevurl", null); + + count=mainModule.getSize(aWhereClause); + + urlBuilder.setValue("module", "Comment"); + urlBuilder.setValue("do", "list"); + urlBuilder.setValue("where", aWhereClause); + urlBuilder.setValue("order", anOrderByClause); + + urlBuilder.setValue("searchfield", requestParser.getParameter("searchfield")); + urlBuilder.setValue("searchtext", requestParser.getParameter("searchtext")); + urlBuilder.setValue("searchispublished", requestParser.getParameter("searchispublished")); + urlBuilder.setValue("searchstatus", requestParser.getParameter("searchstatus")); + urlBuilder.setValue("searchorder", requestParser.getParameter("searchorder")); + + responseData.put("searchfield", requestParser.getParameter("searchfield")); + responseData.put("searchtext", requestParser.getParameter("searchtext")); + responseData.put("searchispublished", requestParser.getParameter("searchispublished")); + responseData.put("searchstatus", requestParser.getParameter("searchstatus")); + responseData.put("searchorder", requestParser.getParameter("searchorder")); + + urlBuilder.setValue("offset", anOffset); + responseData.put("offset" , new Integer(anOffset).toString()); + responseData.put("thisurl" , urlBuilder.getQuery()); + + if (count>=anOffset+nrCommentsPerPage) { + urlBuilder.setValue("offset", anOffset + nrCommentsPerPage); + responseData.put("nexturl" , urlBuilder.getQuery()); + } + + if (anOffset>0) { + urlBuilder.setValue("offset", Math.max(anOffset - nrCommentsPerPage, 0)); + responseData.put("prevurl" , urlBuilder.getQuery()); + } + + responseData.put("comments", commentList); + responseData.put("from" , Integer.toString(anOffset+1)); + responseData.put("count", Integer.toString(count)); + responseData.put("to", Integer.toString(Math.min(anOffset+nrCommentsPerPage, count))); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, "commentlist.template"); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } +} + diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index 3c168514..78b9ff06 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -31,46 +31,45 @@ package mircoders.servlet; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Locale; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.lucene.index.IndexReader; -import freemarker.template.SimpleHash; -import mir.entity.adapter.EntityAdapterModel; -import mir.entity.adapter.EntityIteratorAdapter; -import mir.log.LoggerWrapper; -import mir.misc.StringUtil; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleExc; -import mir.servlet.ServletModuleFailure; -import mir.util.CachingRewindableIterator; -import mir.util.HTTPRequestParser; -import mir.util.JDBCStringRoutines; -import mir.util.SQLQueryBuilder; -import mir.util.URLBuilder; - -import mircoders.entity.EntityContent; -import mircoders.entity.EntityUsers; -import mircoders.global.MirGlobal; -import mircoders.module.ModuleContent; -import mircoders.search.IndexUtil; -import mircoders.storage.DatabaseComment; -import mircoders.storage.DatabaseContent; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.lucene.index.IndexReader; +import freemarker.template.SimpleHash; +import mir.entity.adapter.EntityAdapterModel; +import mir.entity.adapter.EntityIteratorAdapter; +import mir.log.LoggerWrapper; +import mir.misc.StringUtil; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; +import mir.util.CachingRewindableIterator; +import mir.util.HTTPRequestParser; +import mir.util.JDBCStringRoutines; +import mir.util.SQLQueryBuilder; +import mir.util.URLBuilder; +import mircoders.entity.EntityContent; +import mircoders.entity.EntityUsers; +import mircoders.global.MirGlobal; +import mircoders.module.ModuleContent; +import mircoders.search.IndexUtil; +import mircoders.storage.DatabaseComment; +import mircoders.storage.DatabaseContent; +import mircoders.storage.DatabaseContentToMedia; import mircoders.storage.DatabaseContentToTopics; -import mircoders.storage.DatabaseContentToMedia; /* * ServletModuleContent - * deliver html for the article admin form. * - * @version $Id: ServletModuleContent.java,v 1.47 2003/04/09 02:06:09 zapata Exp $ + * @version $Id: ServletModuleContent.java,v 1.48 2003/04/10 03:31:47 zapata Exp $ * @author rk, mir-coders * */ @@ -263,38 +262,40 @@ public class ServletModuleContent extends ServletModule public void attach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String mediaIdParam = req.getParameter("mid"); - String idParam = req.getParameter("cid"); - if (idParam == null||mediaIdParam==null) throw new ServletModuleExc("smod content :: attach :: cid/mid missing"); + String articleId = req.getParameter("articleid"); + + if (articleId == null || mediaIdParam==null) + throw new ServletModuleExc("smod content :: attach :: articleid/mid missing"); try { - EntityContent entContent = (EntityContent)mainModule.getById(idParam); + EntityContent entContent = (EntityContent) mainModule.getById(articleId); entContent.attach(mediaIdParam); } catch(Throwable e) { - logger.error("smod content :: attach :: could not get entityContent"); + throw new ServletModuleFailure(e); } - _showObject(idParam, req, res); + _showObject(articleId, req, res); } public void dettach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { - String cidParam = req.getParameter("cid"); + String articleId = req.getParameter("articleid"); String midParam = req.getParameter("mid"); - if (cidParam == null) - throw new ServletModuleExc("smod content :: dettach :: cid missing"); + if (articleId == null) + throw new ServletModuleExc("smod content :: dettach :: articleid missing"); if (midParam == null) throw new ServletModuleExc("smod content :: dettach :: mid missing"); try { - EntityContent entContent = (EntityContent)mainModule.getById(cidParam); - entContent.dettach(cidParam,midParam); + EntityContent entContent = (EntityContent)mainModule.getById(articleId); + entContent.dettach(articleId, midParam); } catch(Throwable e) { - logger.error("smod content :: dettach :: could not get entityContent"); + throw new ServletModuleFailure(e); } - _showObject(cidParam, req, res); + _showObject(articleId, req, res); } public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index d2e48110..db23bc0a 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -118,7 +118,7 @@ import mircoders.storage.DatabaseTopics; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.71 2003/04/09 02:06:09 zapata Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.72 2003/04/10 03:31:47 zapata Exp $ * */ @@ -1085,9 +1085,4 @@ public class ServletModuleOpenIndy extends ServletModule throw new ServletModuleFailure(e); } } - - } - - - diff --git a/source/mircoders/servlet/ServletModuleUploadedMedia.java b/source/mircoders/servlet/ServletModuleUploadedMedia.java index 88dfa689..d7904127 100755 --- a/source/mircoders/servlet/ServletModuleUploadedMedia.java +++ b/source/mircoders/servlet/ServletModuleUploadedMedia.java @@ -1,373 +1,391 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.servlet; - -import java.io.InputStream; -import java.net.URLEncoder; -import java.util.Map; - -import javax.servlet.ServletContext; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import mir.config.MirPropertiesConfiguration; -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.log.LoggerWrapper; -import mir.media.MediaHelper; -import mir.media.MirMedia; -import mir.misc.FileHandler; -import mir.misc.WebdbMultipartRequest; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleExc; -import mir.servlet.ServletModuleFailure; -import mir.servlet.ServletModuleUserExc; -import mir.util.ExceptionFunctions; -import mircoders.entity.EntityContent; -import mircoders.entity.EntityUploadedMedia; -import mircoders.entity.EntityUsers; -import mircoders.media.MediaRequest; -import mircoders.media.UnsupportedMediaFormatExc; -import mircoders.storage.DatabaseContent; -import mircoders.storage.DatabaseMediafolder; -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; - -/* - * ServletModuleBilder - - * liefert HTML fuer Bilder - * - * @version $Id: ServletModuleUploadedMedia.java,v 1.23 2003/03/09 19:14:21 idfx Exp $ - * @author RK, the mir-coders group - */ - -public abstract class ServletModuleUploadedMedia - extends mir.servlet.ServletModule { - - //private static DatabaseRights dbRights; - - public static ServletModule getInstance() { - return null; - } - - public ServletModuleUploadedMedia() { - super(); - logger = new LoggerWrapper("ServletModule.UploadedMedia"); - } - - public void insert(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc { - try { - EntityUsers user = _getUser(req); - MediaRequest mediaReq = new MediaRequest(user.getId(), false); - WebdbMultipartRequest mp = new WebdbMultipartRequest(req, (FileHandler)mediaReq); - EntityList mediaList = mediaReq.getEntityList(); - String articleid = (String) mp.getParameters().get("articleid"); - - if (articleid!=null) { - EntityContent entContent = (EntityContent) DatabaseContent.getInstance().selectById(articleid); - - mediaList.rewind(); - - while (mediaList.hasNext()) { - entContent.attach( ( (EntityUploadedMedia) mediaList.next()).getId()); - } - mediaList.rewind(); - - ((ServletModuleContent) ServletModuleContent.getInstance())._showObject(articleid, req, res); - - return; - } - - SimpleHash mergeData = new SimpleHash(); - SimpleHash popups = new SimpleHash(); - mergeData.put("contentlist", mediaList); - if (mediaList.getOrder() != null) { - mergeData.put("order", mediaList.getOrder()); - mergeData.put("order_encoded", URLEncoder.encode(mediaList.getOrder())); - } - mergeData.put("count", (new Integer(mediaList.getCount())).toString()); - mergeData.put("from", (new Integer(mediaList.getFrom())).toString()); - mergeData.put("to", (new Integer(mediaList.getTo())).toString()); - if (mediaList.hasNextBatch()) - mergeData.put("next", (new Integer(mediaList.getNextBatch())).toString()); - if (mediaList.hasPrevBatch()) - mergeData.put("prev", (new Integer(mediaList.getPrevBatch())).toString()); - //fetch the popups - popups.put("mediafolderPopupData", DatabaseMediafolder.getInstance().getPopupData()); - // raus damit - deliver(req, res, mergeData, popups, templateListString); - } - catch (Throwable t) { - Throwable cause = ExceptionFunctions.traceCauseException(t); - - if (cause instanceof UnsupportedMediaFormatExc) { - throw new ServletModuleUserExc("media.error.unsupportedformat", new String[] {}); - } - throw new ServletModuleFailure("ServletModuleUploadedMedia.insert: " + t.toString(), t); - } - } - - public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { - - try { - EntityUsers user = _getUser(req); - WebdbMultipartRequest mp = new WebdbMultipartRequest(req, null); - Map parameters = mp.getParameters(); - - parameters.put("to_publisher", user.getId()); - parameters.put("is_produced", "0"); - if (!parameters.containsKey("is_published")) - parameters.put("is_published", "0"); - - String id = mainModule.set(parameters); - logger.debug("update: media ID = " + id); - _edit(id, req, res); - } - catch (Throwable e) { - throw new ServletModuleFailure("upload -- exception " + e.toString(), e); - } - - } - - - public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { - // Parameter auswerten - SimpleHash mergeData = new SimpleHash(); - SimpleHash popups = new SimpleHash(); - - String query_text = req.getParameter("query_text"); - mergeData.put("query_text", query_text); - if (query_text != null) mergeData.put("query_text_encoded", URLEncoder.encode(query_text)); - String query_field = req.getParameter("query_field"); - mergeData.put("query_field", query_field); - String query_is_published = req.getParameter("query_is_published"); - mergeData.put("query_is_published", query_is_published); - String query_media_folder = req.getParameter("query_media_folder"); - mergeData.put("query_media_folder", query_media_folder); - String offset = req.getParameter("offset"); - if (offset == null || offset.equals("")) offset = "0"; - mergeData.put("offset", offset); - - String order = req.getParameter("order"); - if (order == null || order.equals("")) order = "webdb_lastchange desc"; - - // if in connection mode to content - String cid = req.getParameter("cid"); - mergeData.put("cid", cid); - - - // sql basteln - String whereClause = ""; - boolean isFirst = true; - if (query_text != null && !query_text.equalsIgnoreCase("")) { - whereClause += "lower(" + query_field + ") like lower('%" + query_text + "%')"; - isFirst = false; - } - if (query_is_published != null && !query_is_published.equals("")) { - if (isFirst == false) whereClause += " and "; - whereClause += "is_published='" + query_is_published + "'"; - isFirst = false; - } - if (query_media_folder != null && !query_media_folder.equals("")) { - if (isFirst == false) whereClause += " and "; - whereClause += "to_media_folder='" + query_media_folder + "'"; - } - //theLog.printDebugInfo("sql-whereclause: " + whereClause + " order: " + order + " offset: " + offset); - - // fetch and deliver - try { - if (query_text != null || query_is_published != null || query_media_folder != null) { - EntityList theList = mainModule.getByWhereClause(whereClause, order, (new Integer(offset)).intValue(), 10); - if (theList != null) { - mergeData.put("contentlist", theList); - if (theList.getOrder() != null) { - mergeData.put("order", theList.getOrder()); - mergeData.put("order_encoded", URLEncoder.encode(theList.getOrder())); - } - mergeData.put("count", (new Integer(theList.getCount())).toString()); - mergeData.put("from", (new Integer(theList.getFrom())).toString()); - mergeData.put("to", (new Integer(theList.getTo())).toString()); - if (theList.hasNextBatch()) - mergeData.put("next", (new Integer(theList.getNextBatch())).toString()); - if (theList.hasPrevBatch()) - mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString()); - } - } - popups.put("mediafolderPopupData", DatabaseMediafolder.getInstance().getPopupData()); - - deliver(req, res, mergeData, popups, templateListString); - } - catch (Throwable e) { - throw new ServletModuleFailure(e); - } - } - - - public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { - try { - SimpleHash mergeData = new SimpleHash(); - SimpleHash popups = new SimpleHash(); - String maxMedia = MirPropertiesConfiguration.instance().getString("ServletModule.OpenIndy.MaxMediaUploadItems"); - String numOfMedia = req.getParameter("medianum"); - - mergeData.put("new", "1"); - mergeData.put("articleid", req.getParameter("articleid")); - - popups.put("mediafolderPopupData", DatabaseMediafolder.getInstance().getPopupData()); - - if (numOfMedia==null || numOfMedia.equals("")) { - numOfMedia="1"; - } - else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) { - numOfMedia = maxMedia; - } - - int mediaNum = Integer.parseInt(numOfMedia); - SimpleList mediaFields = new SimpleList(); - for(int i =0; i Integer.parseInt(maxMedia)) { + numOfMedia = maxMedia; + } + + int mediaNum = Integer.parseInt(numOfMedia); + SimpleList mediaFields = new SimpleList(); + for(int i =0; iThis class implements the access to the comment-table for the diff --git a/source/mircoders/storage/DatabaseCommentToMedia.java b/source/mircoders/storage/DatabaseCommentToMedia.java new file mode 100755 index 00000000..71befbb8 --- /dev/null +++ b/source/mircoders/storage/DatabaseCommentToMedia.java @@ -0,0 +1,562 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.storage; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import mir.entity.EntityList; +import mir.log.LoggerWrapper; +import mir.storage.Database; +import mir.storage.StorageObject; +import mir.storage.StorageObjectExc; +import mir.storage.StorageObjectFailure; +import mircoders.entity.EntityComment; +import mircoders.entity.EntityUploadedMedia; + +/** + * implements abstract DB connection to the comment_x_media SQL table + * + * @author RK, mir-coders group + * @version $Id: DatabaseCommentToMedia.java,v 1.1 2003/04/10 03:31:47 zapata Exp $ + * + */ + +public class DatabaseCommentToMedia extends Database implements StorageObject{ + + private static DatabaseCommentToMedia instance; + + public static DatabaseCommentToMedia getInstance() { + if (instance == null) { + synchronized (DatabaseCommentToMedia.class) { + if (instance == null) { + instance = new DatabaseCommentToMedia(); + instance.myselfDatabase = instance; + } + } + } + return instance; + } + + private DatabaseCommentToMedia() { + super(); + + logger = new LoggerWrapper("Database.CommentToMedia"); + + hasTimestamp = false; + theTable = "comment_x_media"; + theEntityClass = mir.entity.GenericEntity.class; + } + + /** + * get all the media-files belonging to a comment entity + * + */ + public EntityList getMedia(EntityComment comment) throws StorageObjectFailure { + EntityList returnList = null; + if (comment != null) { + // get all to_topic from media_x_topic + String id = comment.getId(); + String subselect = "id in (select media_id from " + theTable + + " where comment_id=" + id + ")"; + + try { + // media should stay in uploaded order. this is especially important + // for photo stories which require a specific chronologic order. + // this is why we have the the second parameter "id" + returnList = DatabaseMedia.getInstance().selectByWhereClause(subselect, + "id", -1); + } + catch (Throwable e) { + logger.debug("-- get media failed " + e.toString()); + throw new StorageObjectFailure("-- get media failed ", e); + } + } + return returnList; + } + + public boolean hasMedia(EntityComment comment) throws StorageObjectFailure, + StorageObjectExc { + if (comment != null) { + try { + if (selectByWhereClause("comment_id=" + comment.getId(), -1).size() == + 0) + return false; + else + return true; + } + catch (Exception e) { + logger.error("DatabaseCommentToMedia.hasMedia: " + e.toString()); + throw new StorageObjectFailure("DatabaseCommentToMedia.hasMedia: " + + e.toString(), e); + } + } + else { + logger.error("DatabaseCommentToMedia.hasMedia: comment == null"); + throw new StorageObjectExc( + "DatabaseCommentToMedia.hasMedia: comment == null"); + } + } + + /** + * get all the audio belonging to a comment entity + * + */ + public EntityList getAudio(EntityComment comment) throws StorageObjectFailure { + EntityList returnList = null; + if (comment != null) { + // get all to_topic from media_x_topic + String id = comment.getId(); + //this is not supported by mysql + String subselect = "id in (select media_id from " + theTable + + " where comment_id=" + id + ")"; + + try { + // media should stay in uploaded order. this is especially important + // for photo stories which require a specific chronologic order. + // this is why we have the the second parameter "id" + returnList = DatabaseAudio.getInstance().selectByWhereClause(subselect, + "id", -1); + } + catch (Exception e) { + logger.error("DatabaseCommentToMedia.getAudio: " + e.toString()); + throw new StorageObjectFailure("DatabaseCommentToMedia.getAudio: " + + e.toString(), e); + } + } + return returnList; + } + + /** + * get all the video belonging to a comment entity + * + */ + public EntityList getVideo(EntityComment comment) throws StorageObjectFailure { + EntityList returnList = null; + if (comment != null) { + // get all to_topic from media_x_topic + String id = comment.getId(); + //this is not supported by mysql + String subselect = "id in (select media_id from " + theTable + + " where comment_id=" + id + ")"; + + try { + // media should stay in uploaded order. this is especially important + // for photo stories which require a specific chronologic order. + // this is why we have the the second parameter "id" + returnList = DatabaseVideo.getInstance().selectByWhereClause(subselect, + "id", -1); + } + catch (Exception e) { + logger.error("DatabaseCommentToMedia.getVideo: " + e.toString()); + throw new StorageObjectFailure("DatabaseCommentToMedia.getVideo: " + + e.toString(), e); + } + } + return returnList; + } + + /** + * get all the images belonging to a comment entity + * + */ + public EntityList getImages(EntityComment comment) throws + StorageObjectFailure { + EntityList returnList = null; + if (comment != null) { + // get all to_topic from media_x_topic + String id = comment.getId(); + //this is not supported by mysql + String subselect = "id in (select media_id from " + theTable + + " where comment_id=" + id + ")"; + + try { + // media should stay in uploaded order. this is especially important + // for photo stories which require a specific chronologic order. + // this is why we have the the second parameter "id" + returnList = DatabaseImages.getInstance().selectByWhereClause(subselect, + "id", -1); + } + catch (Exception e) { + logger.error("DatabaseCommentToMedia.getImages: " + e.toString()); + throw new StorageObjectFailure("DatabaseCommentToMedia.getImages: " + + e.toString(), e); + } + } + return returnList; + } + + /** + * get all the uploaded/other Media belonging to a comment entity + * + */ + public EntityList getOther(EntityComment comment) throws StorageObjectFailure { + /** @todo this should only fetch published media / rk */ + + EntityList returnList = null; + if (comment != null) { + // get all to_topic from media_x_topic + String id = comment.getId(); + //this is not supported by mysql + String subselect = "id in (select media_id from " + theTable + + " where comment_id=" + id + ")"; + + try { + // media should stay in uploaded order. this is especially important + // for photo stories which require a specific chronologic order. + // this is why we have the the second parameter "id" + returnList = DatabaseOther.getInstance().selectByWhereClause(subselect, + "id"); + } + catch (Exception e) { + logger.error("DatabaseCommentToMedia.getOther: " + e.toString()); + throw new StorageObjectFailure("DatabaseCommentToMedia.getOther: " + e.toString(), e); + } + } + return returnList; + } + + /** + * get all the uploaded/other Media belonging to a comment entity + * + */ + public EntityList getUploadedMedia(EntityComment comment) throws + StorageObjectFailure { + /** @todo this should only fetch published media / rk */ + + EntityList returnList = null; + if (comment != null) { + // get all to_topic from media_x_topic + String id = comment.getId(); + //this is not supported by mysql + String subselect = "id in (select media_id from " + theTable + + " where comment_id=" + id + ")"; + + try { + returnList = DatabaseUploadedMedia.getInstance().selectByWhereClause( + subselect, + "id"); + } + catch (Exception e) { + logger.error("DatabaseCommentToMedia.getUploadedMedia: " + e.toString()); + throw new StorageObjectFailure( + "DatabaseCommentToMedia.getUploadedMedia: " + e.toString(), e); + } + } + return returnList; + } + + public void setMedia(String commentId, String[] mediaId) throws + StorageObjectFailure { + if (commentId == null) { + return; + } + if (mediaId == null || mediaId[0] == null) { + return; + } + //first delete all row with comment_id=commentId + String sql = "delete from " + theTable + " where comment_id=" + commentId; + + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + ResultSet rs = executeSql(stmt, sql); + } + catch (Exception e) { + logger.error("-- set media failed -- delete"); + throw new StorageObjectFailure("-- set media failed -- delete", e); + } + finally { + freeConnection(con, stmt); + } + + //now insert + //first delete all row with comment_id=commentId + for (int i = 0; i < mediaId.length; i++) { + sql = "insert into " + theTable + " (comment_id,media_id) values (" + + commentId + "," + mediaId[i] + ")"; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + } + catch (Exception e) { + logger.error("-- set topics failed -- insert"); + throw new StorageObjectFailure("-- set topics failed -- insert ", e); + } + finally { + freeConnection(con, stmt); + } + } + } + + public void addMedia(String commentId, String mediaId) throws + StorageObjectFailure { + if (commentId == null && mediaId == null) { + return; + } + + Connection con = null; + Statement stmt = null; + //now insert + + String sql = "insert into " + theTable + " (comment_id,media_id) values (" + + commentId + "," + mediaId + ")"; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + } + catch (Exception e) { + logger.error("-- add media failed -- insert"); + throw new StorageObjectFailure("-- add media failed -- insert ", e); + } + finally { + freeConnection(con, stmt); + } + } + + public void setMedia(String commentId, String mediaId) throws + StorageObjectFailure { + if (commentId == null && mediaId == null) { + return; + } + //first delete all row with comment_id=commentId + String sql = "delete from " + theTable + " where comment_id=" + commentId; + + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + } + catch (Exception e) { + logger.error("-- set media failed -- delete"); + throw new StorageObjectFailure("-- set media failed -- delete ", e); + } + finally { + freeConnection(con, stmt); + } + + //now insert + //first delete all row with comment_id=commentId + + sql = "insert into " + theTable + " (comment_id,media_id) values (" + + commentId + "," + mediaId + ")"; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + } + catch (Exception e) { + logger.error("-- set media failed -- insert"); + throw new StorageObjectFailure("-- set media failed -- insert ", e); + } + finally { + freeConnection(con, stmt); + } + } + + public void deleteByCommentId(String commentId) throws StorageObjectFailure { + if (commentId == null) { + //theLog.printDebugInfo("-- delete topics failed -- no comment id"); + return; + } + //delete all row with comment_id=commentId + String sql = "delete from " + theTable + " where comment_id=" + commentId; + + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + } + catch (Exception e) { + logger.error("-- delete by commentId failed "); + throw new StorageObjectFailure( + "-- delete by comment id failed -- delete ", e); + } + finally { + freeConnection(con, stmt); + } + } + + public void deleteByMediaId(String mediaId) throws StorageObjectFailure { + if (mediaId == null) { + //theLog.printDebugInfo("-- delete topics failed -- no topic id"); + return; + } + //delete all row with comment_id=commentId + String sql = "delete from " + theTable + " where media_id=" + mediaId; + + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + logger.debug("-- delete media success "); + } + catch (Exception e) { + logger.error("-- delete media failed "); + throw new StorageObjectFailure("-- delete by media id failed -- ", e); + } + finally { + freeConnection(con, stmt); + } + } + + public void delete(String commentId, String mediaId) throws + StorageObjectFailure { + if (mediaId == null || commentId == null) { + logger.debug("-- delete media failed -- missing parameter"); + return; + } + //delete all row with comment_id=commentId and media_id=mediaId + String sql = "delete from " + theTable + " where media_id=" + mediaId + + " and comment_id= " + commentId; + + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt, sql); + logger.debug("-- delete comment_x_media success "); + } + catch (Exception e) { + logger.error("-- delete comment_x_media failed "); + throw new StorageObjectFailure("-- delete comment_x_media failed -- ", e); + } + finally { + freeConnection(con, stmt); + } + } + + public EntityList getComment(EntityUploadedMedia media) throws + StorageObjectFailure { + EntityList returnList = null; + if (media != null) { + String id = media.getId(); + String select = "select comment_id from " + theTable + " where media_id=" + + id; + + // execute select statement + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + ResultSet rs = executeSql(stmt, select); + if (rs != null) { + String mediaSelect = "id IN ("; + boolean first = true; + while (rs.next()) { + if (first == false) + mediaSelect += ","; + mediaSelect += rs.getString(1); + first = false; + } + mediaSelect += ")"; + if (first == false) + returnList = DatabaseComment.getInstance().selectByWhereClause( + mediaSelect, -1); + } + } + catch (Exception e) { + logger.error("-- get comment failed"); + throw new StorageObjectFailure("-- get comment failed -- ", e); + } + finally { + freeConnection(con, stmt); + } + } + return returnList; + } + + /** + * Returns a EntityList with all comment-objects having a relation to a media + */ + + public EntityList getComment() throws StorageObjectFailure { + EntityList returnList = null; + + String select = "select distinct comment_id from " + theTable; + // execute select statement + Connection con = null; + Statement stmt = null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + ResultSet rs = executeSql(stmt, select); + if (rs != null) { + String mediaSelect = "id IN ("; + boolean first = true; + while (rs.next()) { + if (first == false) + mediaSelect += ","; + mediaSelect += rs.getString(1); + first = false; + } + mediaSelect += ")"; + if (first == false) + returnList = DatabaseComment.getInstance().selectByWhereClause( + mediaSelect, "webdb_lastchange desc"); + } + } + catch (Exception e) { + logger.error("-- get comment failed"); + throw new StorageObjectFailure("-- get comment failed -- ", e); + } + finally { + freeConnection(con, stmt); + } + + return returnList; + } + +} diff --git a/templates/admin/FUNCTIONS.template b/templates/admin/FUNCTIONS.template index 296f540e..485a8340 100755 --- a/templates/admin/FUNCTIONS.template +++ b/templates/admin/FUNCTIONS.template @@ -229,3 +229,116 @@ + + + +functions to show media for an article/comment edit page + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ ${lang("content.attachments")} +
+ ${lang("content.images")}: + + [+] ${lang("content.addimage")} | + ${lang("content.uploadimage")} +
+ edit  + + [-] ${lang("delete")} +
+ ${lang("content.audio")}: + + [+] ${lang("content.addaudio")} | + ${lang("content.uploadaudio")} +
+ edit  + + [-] ${lang("delete")} +
+ ${lang("content.video")}: + + [+] ${lang("content.addvideo")} | + ${lang("content.uploadvideo")} +
+ edit  + + [-] ${lang("delete")} +
+ ${lang("content.other")}: + + [+] ${lang("content.addother")} | + ${lang("content.uploadother")} +
+ edit  + + [-] ${lang("delete")} +
+
+ + diff --git a/templates/admin/FUNCTIONS_media.template b/templates/admin/FUNCTIONS_media.template index ccd09247..04261fb7 100755 --- a/templates/admin/FUNCTIONS_media.template +++ b/templates/admin/FUNCTIONS_media.template @@ -9,7 +9,8 @@ - + + @@ -109,11 +110,15 @@ ${entry.creator}  @@ -127,10 +132,10 @@ diff --git a/templates/admin/audio.template b/templates/admin/audio.template index 215a51a0..d916214d 100755 --- a/templates/admin/audio.template +++ b/templates/admin/audio.template @@ -19,6 +19,9 @@ function openWin(url) { + + +
  - - ${lang("attach")} + + ${lang("attach")} - ${lang("delete")} + + ${lang("attach")} + + ${lang("delete")} | ${lang("edit")} +
- ${lang("list.previous")}  + ${lang("list.previous")}  - ${lang("list.next")} + ${lang("list.next")}
@@ -41,20 +39,20 @@ - - - - - - + + + + + + @@ -63,8 +61,8 @@ @@ -73,17 +71,17 @@
@@ -37,6 +40,9 @@ function openWin(url) { + + + diff --git a/templates/admin/comment.template b/templates/admin/comment.template index 2673cba7..517f6fe1 100755 --- a/templates/admin/comment.template +++ b/templates/admin/comment.template @@ -11,10 +11,8 @@
- - - - + + @@ -30,7 +28,7 @@ ${lang("comment.date")}
- ${utility.encodeHTML(utility.encodeHTML(data.webdb_create))} + ${utility.encodeHTML(utility.encodeHTML(comment.webdb_create))}
${lang("comment.text")}
- ${lang("comment.html")} checked> + ${lang("comment.html")} checked>
- +
- ${lang("comment.published")} checked> - + ${lang("comment.published")} checked> + @@ -92,6 +90,55 @@
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ ${lang("content.family")} +
+ ${lang("content.parent")}: + + + ${utility.encodeHTML(article.parent.title)}
+ ${lang("content.viewparent")} | + ${lang("content.clearparent")} | +
+  ${lang("content.selectparent")} +
+ ${lang("content.children")}: + + ${lang("content.viewchildren")} +
+ +
+ +
+ +
+

diff --git a/templates/admin/content.template b/templates/admin/content.template index 85be6bf0..944270ab 100755 --- a/templates/admin/content.template +++ b/templates/admin/content.template @@ -21,8 +21,8 @@
- - [ ${lang("content.comments")} ] + + [ ${lang("content.comments")} ] @@ -224,98 +224,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- ${lang("content.attachments")} -
- ${lang("content.images")}: - - [+] ${lang("content.addimage")} | - ${lang("content.uploadimage")} -
- edit  - - [-] ${lang("delete")} -
- ${lang("content.audio")}: - - [+] ${lang("content.addaudio")} | - ${lang("content.uploadaudio")} -
- edit  - - [-] ${lang("delete")} -
- ${lang("content.video")}: - - [+] ${lang("content.addvideo")} | - ${lang("content.uploadvideo")} -
- edit  - - [-] ${lang("delete")} -
- ${lang("content.other")}: - - [+] ${lang("content.addother")} | - ${lang("content.uploadother")} -
- edit  - - [-] ${lang("delete")} -
- +
diff --git a/templates/admin/image.template b/templates/admin/image.template index 623e733f..d73d1539 100755 --- a/templates/admin/image.template +++ b/templates/admin/image.template @@ -20,6 +20,10 @@ function openWin(url) { + + + + @@ -41,6 +45,10 @@ function openWin(url) { + + + + diff --git a/templates/admin/imagelist.template b/templates/admin/imagelist.template index 7359b0e1..12751309 100755 --- a/templates/admin/imagelist.template +++ b/templates/admin/imagelist.template @@ -63,11 +63,15 @@ function openWin(url) { ${entry.creator}  @@ -81,10 +85,10 @@ function openWin(url) { diff --git a/templates/admin/media.template b/templates/admin/media.template index 07e711e8..a7e827b9 100755 --- a/templates/admin/media.template +++ b/templates/admin/media.template @@ -19,6 +19,9 @@ function openWin(url) { + + +
  - - ${lang("attach")} + + ${lang("attach")} - ${lang("delete")} - | ${lang("edit")} + + ${lang("attach")} + + ${lang("delete")} + | ${lang("edit")} +
- ${lang("list.previous")}  + ${lang("list.previous")}  - ${lang("list.next")} + ${lang("list.next")}
@@ -39,6 +42,9 @@ function openWin(url) { + + + diff --git a/templates/admin/video.template b/templates/admin/video.template index c63d9206..71283a4d 100755 --- a/templates/admin/video.template +++ b/templates/admin/video.template @@ -18,6 +18,9 @@ function openWin(url) { + + +
@@ -36,6 +39,9 @@ function openWin(url) { + + +