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 Vector simpleCommentOperations;
45 private Vector simpleArticleOperations;
46 private Map simpleCommentOperationsMap;
47 private Map simpleArticleOperationsMap;
49 public MirBasicAdminInterfaceLocalizer() throws MirLocalizerFailure, MirLocalizerExc {
50 simpleCommentOperations = new Vector();
51 simpleArticleOperations = new Vector();
52 simpleCommentOperationsMap = new HashMap();
53 simpleArticleOperationsMap = new HashMap();
55 addSimpleArticleOperation(new ChangeArticleFieldOperation("newswire", "to_article_type", "0", "1"));
56 addSimpleArticleOperation(new SetArticleFieldOperation("unhide", "is_published", "1"));
57 addSimpleArticleOperation(new SetArticleFieldOperation("hide", "is_published", "0"));
59 addSimpleCommentOperation(new SetCommentFieldOperation("unhide", "is_published", "1"));
60 addSimpleCommentOperation(new SetCommentFieldOperation("hide", "is_published", "0"));
63 public List simpleCommentOperations() {
64 return simpleCommentOperations;
67 public List simpleArticleOperations() {
68 return simpleArticleOperations;
71 public MirSimpleEntityOperation simpleArticleOperationForName(String aName) {
72 return (MirSimpleEntityOperation) simpleArticleOperationsMap.get(aName);
75 public MirSimpleEntityOperation simpleCommentOperationForName(String aName) {
76 return (MirSimpleEntityOperation) simpleCommentOperationsMap.get(aName);
79 public void removeSimpleArticleOperation(String aName) {
80 simpleArticleOperations.remove(simpleArticleOperationsMap.get(aName));
81 simpleArticleOperationsMap.remove(aName);
84 public void addSimpleArticleOperation(MirSimpleEntityOperation anOperation) {
85 removeSimpleArticleOperation(anOperation.getName());
86 simpleArticleOperationsMap.put(anOperation.getName(), anOperation);
87 simpleArticleOperations.add(anOperation);
90 public void removeSimpleCommentOperation(String aName) {
91 simpleCommentOperations.remove(simpleCommentOperationsMap.get(aName));
92 simpleCommentOperationsMap.remove(aName);
95 public void addSimpleCommentOperation(MirSimpleEntityOperation anOperation) {
96 removeSimpleCommentOperation(anOperation.getName());
97 simpleCommentOperationsMap.put(anOperation.getName(), anOperation);
98 simpleCommentOperations.add(anOperation);
101 protected abstract static class EntityModifyingOperation implements MirSimpleEntityOperation {
104 protected EntityModifyingOperation(String aName) {
108 public String getName() {
112 public boolean isAvailable(EntityAdapter anEntity) {
114 Entity entity = anEntity.getEntity();
115 return isAvailable(entity);
117 catch (Throwable t) {
122 public void perform(EntityAdapter anEntity) {
123 Entity entity = anEntity.getEntity();
125 performModification(entity);
128 catch (Throwable t) {
132 protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectException ;
133 protected abstract void performModification(Entity anEntity) throws StorageObjectException ;
136 public static abstract class CommentModifyingOperation extends EntityModifyingOperation {
137 public CommentModifyingOperation(String aName) {
141 protected boolean isAvailable(Entity anEntity) throws StorageObjectException {
142 return anEntity instanceof EntityComment && isAvailable((EntityComment) anEntity);
145 protected void performModification(Entity anEntity) throws StorageObjectException {
146 performModification((EntityComment) anEntity);
147 DatabaseContent.getInstance().setUnproduced("id="+anEntity.getValue("to_media"));
150 protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectException ;
151 protected abstract void performModification(EntityComment aComment) throws StorageObjectException ;
154 public static abstract class ArticleModifyingOperation extends EntityModifyingOperation {
155 public ArticleModifyingOperation(String aName) {
159 protected boolean isAvailable(Entity anEntity) throws StorageObjectException {
160 return anEntity instanceof EntityContent && isAvailable((EntityContent) anEntity);
163 protected void performModification(Entity anEntity) throws StorageObjectException {
164 performModification((EntityContent) anEntity);
165 anEntity.setValueForProperty("is_produced", "0");
168 protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectException ;
169 protected abstract void performModification(EntityContent anArticle) throws StorageObjectException ;
172 protected static class SetCommentFieldOperation extends CommentModifyingOperation {
173 private String field;
174 private String value;
176 public SetCommentFieldOperation(String aName, String aField, String aValue) {
183 protected boolean isAvailable(EntityComment aComment) {
184 return aComment.getValue(field) == null || !aComment.getValue(field).equals(value);
187 protected void performModification(EntityComment aComment) throws StorageObjectException {
188 aComment.setValueForProperty(field, value);
192 protected static class SetArticleFieldOperation extends ArticleModifyingOperation {
193 private String field;
194 private String value;
196 public SetArticleFieldOperation(String aName, String aField, String aValue) {
203 protected boolean isAvailable(EntityContent anArticle) {
204 return anArticle.getValue(field) == null || !anArticle.getValue(field).equals(value);
207 protected void performModification(EntityContent anArticle) throws StorageObjectException {
208 anArticle.setValueForProperty(field, value);
212 protected static class ChangeArticleFieldOperation extends ArticleModifyingOperation {
213 private String field;
214 private String oldValue;
215 private String newValue;
217 public ChangeArticleFieldOperation(String aName, String aField, String anOldValue, String aNewValue) {
221 newValue = aNewValue;
222 oldValue = anOldValue;
225 protected boolean isAvailable(EntityContent anArticle) {
226 return anArticle.getValue(field) != null && anArticle.getValue(field).equals(oldValue);
229 protected void performModification(EntityContent anArticle) throws StorageObjectException {
230 anArticle.setValueForProperty(field, newValue);