2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.localizer.basic;
35 import mir.entity.adapter.*;
38 import mircoders.localizer.*;
39 import mircoders.entity.*;
40 import mircoders.storage.*;
43 public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocalizer {
44 private Map simpleCommentOperations;
45 private Map simpleArticleOperations;
47 public MirBasicAdminInterfaceLocalizer() throws MirLocalizerFailure, MirLocalizerException {
48 simpleCommentOperations = new HashMap();
49 simpleArticleOperations = new HashMap();
51 buildSimpleCommentOperations(simpleCommentOperations);
52 buildSimpleArticleOperations(simpleArticleOperations);
55 public Map simpleCommentOperations() {
56 return simpleCommentOperations;
59 public Map simpleArticleOperations() {
60 return simpleArticleOperations;
63 public void buildSimpleCommentOperations(Map anOperations) throws MirLocalizerFailure, MirLocalizerException {
64 anOperations.put("hide", new HideCommentOperation());
65 anOperations.put("unhide", new UnhideCommentOperation());
68 public void buildSimpleArticleOperations(Map anOperations) throws MirLocalizerFailure, MirLocalizerException {
69 anOperations.put("hide", new HideArticleOperation());
70 anOperations.put("unhide", new UnhideArticleOperation());
73 protected abstract static class EntityModifyingOperation implements MirSimpleEntityOperation {
74 public boolean isAvailable(EntityAdapter anEntity) {
77 Entity entity = anEntity.getEntity();
78 return (entity instanceof EntityComment) && isAvailable((EntityComment) entity);
85 public void perform(EntityAdapter anEntity) {
86 Entity entity = anEntity.getEntity();
88 performModification(entity);
95 protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectException ;
96 protected abstract void performModification(Entity anEntity) throws StorageObjectException ;
99 public static abstract class CommentModifyingOperation extends EntityModifyingOperation {
100 protected boolean isAvailable(Entity anEntity) throws StorageObjectException {
101 return anEntity instanceof EntityComment && isAvailable((EntityComment) anEntity);
104 protected void performModification(Entity anEntity) throws StorageObjectException {
105 performModification((EntityComment) anEntity);
106 DatabaseContent.getInstance().setUnproduced("id="+anEntity.getValue("to_media"));
109 protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectException ;
110 protected abstract void performModification(EntityComment aComment) throws StorageObjectException ;
113 public static abstract class ArticleModifyingOperation extends EntityModifyingOperation {
114 protected boolean isAvailable(Entity anEntity) throws StorageObjectException {
115 return anEntity instanceof EntityContent && isAvailable((EntityComment) anEntity);
118 protected void performModification(Entity anEntity) throws StorageObjectException {
119 performModification((EntityContent) anEntity);
120 anEntity.setValueForProperty("is_produced", "0");
123 protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectException ;
124 protected abstract void performModification(EntityContent anArticle) throws StorageObjectException ;
127 private static class HideCommentOperation extends CommentModifyingOperation {
128 protected boolean isAvailable(EntityComment aComment) {
129 return aComment.getValue("is_published").equals("1");
131 protected void performModification(EntityComment aComment) throws StorageObjectException {
132 aComment.setValueForProperty("is_published", "0");
136 private static class UnhideCommentOperation extends CommentModifyingOperation {
137 protected boolean isAvailable(EntityComment aComment) {
138 return aComment.getValue("is_published").equals("0");
140 protected void performModification(EntityComment aComment) throws StorageObjectException {
141 aComment.setValueForProperty("is_published", "1");
145 private static class HideArticleOperation extends ArticleModifyingOperation {
146 protected boolean isAvailable(EntityContent anArticle) {
147 return anArticle.getValue("is_published").equals("1");
149 protected void performModification(EntityContent anArticle) throws StorageObjectException {
150 anArticle.setValueForProperty("is_published", "0");
154 private static class UnhideArticleOperation extends ArticleModifyingOperation {
155 protected boolean isAvailable(EntityContent anArticle) {
156 return anArticle.getValue("is_published").equals("0");
158 protected void performModification(EntityContent anArticle) throws StorageObjectException {
159 anArticle.setValueForProperty("is_published", "1");