X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Flocalizer%2Fbasic%2FMirBasicAdminInterfaceLocalizer.java;h=4ed7d6a7aea867bc12fe60359bcade22c3a33084;hb=314b6a22bd19592c88720a079a6fdf763e123be4;hp=6edb553039afeb55e0a53b0c2285fa203d468235;hpb=9af9180576ade4481f9a2f61379fb3ba1191f202;p=mir.git diff --git a/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java b/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java index 6edb5530..4ed7d6a7 100755 --- a/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2001, 2002 The Mir-coders group * * This file is part of Mir. * @@ -18,26 +18,36 @@ * 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. + * the code of this program with 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.localizer.basic; +import java.text.SimpleDateFormat; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.List; import java.util.*; -import mir.entity.adapter.*; -import mir.storage.*; -import mir.entity.*; -import mircoders.localizer.*; -import mircoders.entity.*; -import mircoders.storage.*; +import java.util.Vector; + +import mir.entity.Entity; +import mir.entity.adapter.EntityAdapter; +import mir.misc.StringUtil; +import mir.storage.StorageObjectFailure; +import mir.util.StringRoutines; +import mircoders.entity.EntityComment; +import mircoders.entity.EntityContent; +import mircoders.localizer.MirAdminInterfaceLocalizer; +import mircoders.localizer.MirLocalizerExc; +import mircoders.localizer.MirLocalizerFailure; +import mircoders.storage.DatabaseContent; public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocalizer { @@ -45,6 +55,7 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz private Vector simpleArticleOperations; private Map simpleCommentOperationsMap; private Map simpleArticleOperationsMap; + private static SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy HH:mm"); public MirBasicAdminInterfaceLocalizer() throws MirLocalizerFailure, MirLocalizerExc { simpleCommentOperations = new Vector(); @@ -52,14 +63,23 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz simpleCommentOperationsMap = new HashMap(); simpleArticleOperationsMap = new HashMap(); - addSimpleArticleOperation(new ChangeArticleFieldOperation("newswire", "to_article_type", "0", "1")); - addSimpleArticleOperation(new SetArticleFieldOperation("unhide", "is_published", "1")); - addSimpleArticleOperation(new SetArticleFieldOperation("hide", "is_published", "0")); + addSimpleArticleOperation(new ChangeArticleFieldOperation("newswire", "to_article_type", "0", "1", false)); + addSimpleArticleOperation(new ModifyArticleFieldOperation("unhide", "is_published", "1", false)); + addSimpleArticleOperation(new ModifyArticleFieldOperation("hide", "is_published", "0", false)); + + addSimpleCommentOperation(new ModifyCommentFieldOperation("unhide", "is_published", "1")); + addSimpleCommentOperation(new ModifyCommentFieldOperation("hide", "is_published", "0")); + } - addSimpleCommentOperation(new SetCommentFieldOperation("unhide", "is_published", "1")); - addSimpleCommentOperation(new SetCommentFieldOperation("hide", "is_published", "0")); + public String makePasswordDigest(String aPassword) { + return aPassword; } + public void initializeArticle(Map anArticle) { + anArticle.put("is_published", "0"); + anArticle.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); + }; + public List simpleCommentOperations() { return simpleCommentOperations; }; @@ -119,18 +139,19 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz } }; - public void perform(EntityAdapter anEntity) { + public void perform(EntityAdapter aUser, EntityAdapter anEntity) throws MirLocalizerExc, MirLocalizerFailure { Entity entity = anEntity.getEntity(); try { - performModification(entity); + performModification(aUser, entity); entity.update(); } catch (Throwable t) { + throw new MirLocalizerFailure(t); } }; - protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectException ; - protected abstract void performModification(Entity anEntity) throws StorageObjectException ; + protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectFailure ; + protected abstract void performModification(EntityAdapter aUser, Entity anEntity) throws MirLocalizerExc, MirLocalizerFailure ; } public static abstract class CommentModifyingOperation extends EntityModifyingOperation { @@ -138,35 +159,61 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz super(aName); } - protected boolean isAvailable(Entity anEntity) throws StorageObjectException { + protected boolean isAvailable(Entity anEntity) throws StorageObjectFailure { return anEntity instanceof EntityComment && isAvailable((EntityComment) anEntity); } - protected void performModification(Entity anEntity) throws StorageObjectException { - performModification((EntityComment) anEntity); + protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure { + performModification(aUser, (EntityComment) anEntity); DatabaseContent.getInstance().setUnproduced("id="+anEntity.getValue("to_media")); }; - protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectException ; - protected abstract void performModification(EntityComment aComment) throws StorageObjectException ; + protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectFailure ; + protected abstract void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectFailure ; } public static abstract class ArticleModifyingOperation extends EntityModifyingOperation { - public ArticleModifyingOperation(String aName) { + private boolean logOperation; + + public ArticleModifyingOperation(String aName, boolean aLogOperation) { super(aName); + + logOperation = aLogOperation; } - protected boolean isAvailable(Entity anEntity) throws StorageObjectException { + protected boolean isAvailable(Entity anEntity) throws StorageObjectFailure { return anEntity instanceof EntityContent && isAvailable((EntityContent) anEntity); } - protected void performModification(Entity anEntity) throws StorageObjectException { - performModification((EntityContent) anEntity); + protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure { + performModification(aUser, (EntityContent) anEntity); anEntity.setValueForProperty("is_produced", "0"); + + if (logOperation) { + StringBuffer comment = new StringBuffer(); + try { + comment.append(StringRoutines.interpretAsString(anEntity.getValue("comment"))); + } + catch (Throwable t) { + } + if (comment.length()>0 && comment.charAt(comment.length()-1)!='\n') { + comment.append('\n'); + } + comment.append(dateFormatter.format((new GregorianCalendar()).getTime())); + comment.append(" "); + try { + comment.append(StringRoutines.interpretAsString(aUser.get("login"))); + } + catch (Throwable t) { + } + comment.append(" "); + comment.append(getName()); + anEntity.setValueForProperty("comment", comment.toString()); + } }; - protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectException ; - protected abstract void performModification(EntityContent anArticle) throws StorageObjectException ; + protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectFailure ; + protected abstract void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectFailure ; } protected static class SetCommentFieldOperation extends CommentModifyingOperation { @@ -181,10 +228,57 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz } protected boolean isAvailable(EntityComment aComment) { + return true; + } + + protected void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectFailure { + aComment.setValueForProperty(field, value); + } + } + + protected static class SetCommentFieldsOperation extends CommentModifyingOperation { + private Map values; + + public SetCommentFieldsOperation(String aName, String aFields[], String aValues[]) throws MirLocalizerExc { + super(aName); + + values = new HashMap(); + + for (int i=0; i