2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with the com.oreilly.servlet library, any library
\r
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
\r
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
\r
24 * the above that use the same license as the above), and distribute linked
\r
25 * combinations including the two. You must obey the GNU General Public
\r
26 * License in all respects for all of the code used other than the above
\r
27 * mentioned libraries. If you modify this file, you may extend this exception
\r
28 * to your version of the file, but you are not obligated to do so. If you do
\r
29 * not wish to do so, delete this exception statement from your version.
\r
32 package mircoders.localizer.basic;
\r
37 import mir.entity.adapter.*;
\r
38 import mir.storage.*;
\r
39 import mir.entity.*;
\r
42 import mircoders.localizer.*;
\r
43 import mircoders.entity.*;
\r
44 import mircoders.storage.*;
\r
47 public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocalizer {
\r
48 private Vector simpleCommentOperations;
\r
49 private Vector simpleArticleOperations;
\r
50 private Map simpleCommentOperationsMap;
\r
51 private Map simpleArticleOperationsMap;
\r
52 private static SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy HH:mm");
\r
54 public MirBasicAdminInterfaceLocalizer() throws MirLocalizerFailure, MirLocalizerExc {
\r
55 simpleCommentOperations = new Vector();
\r
56 simpleArticleOperations = new Vector();
\r
57 simpleCommentOperationsMap = new HashMap();
\r
58 simpleArticleOperationsMap = new HashMap();
\r
60 addSimpleArticleOperation(new ChangeArticleFieldOperation("newswire", "to_article_type", "0", "1", false));
\r
61 addSimpleArticleOperation(new ModifyArticleFieldOperation("unhide", "is_published", "1", false));
\r
62 addSimpleArticleOperation(new ModifyArticleFieldOperation("hide", "is_published", "0", false));
\r
64 addSimpleCommentOperation(new ModifyCommentFieldOperation("unhide", "is_published", "1"));
\r
65 addSimpleCommentOperation(new ModifyCommentFieldOperation("hide", "is_published", "0"));
\r
68 public List simpleCommentOperations() {
\r
69 return simpleCommentOperations;
\r
72 public List simpleArticleOperations() {
\r
73 return simpleArticleOperations;
\r
76 public MirSimpleEntityOperation simpleArticleOperationForName(String aName) {
\r
77 return (MirSimpleEntityOperation) simpleArticleOperationsMap.get(aName);
\r
80 public MirSimpleEntityOperation simpleCommentOperationForName(String aName) {
\r
81 return (MirSimpleEntityOperation) simpleCommentOperationsMap.get(aName);
\r
84 public void removeSimpleArticleOperation(String aName) {
\r
85 simpleArticleOperations.remove(simpleArticleOperationsMap.get(aName));
\r
86 simpleArticleOperationsMap.remove(aName);
\r
89 public void addSimpleArticleOperation(MirSimpleEntityOperation anOperation) {
\r
90 removeSimpleArticleOperation(anOperation.getName());
\r
91 simpleArticleOperationsMap.put(anOperation.getName(), anOperation);
\r
92 simpleArticleOperations.add(anOperation);
\r
95 public void removeSimpleCommentOperation(String aName) {
\r
96 simpleCommentOperations.remove(simpleCommentOperationsMap.get(aName));
\r
97 simpleCommentOperationsMap.remove(aName);
\r
100 public void addSimpleCommentOperation(MirSimpleEntityOperation anOperation) {
\r
101 removeSimpleCommentOperation(anOperation.getName());
\r
102 simpleCommentOperationsMap.put(anOperation.getName(), anOperation);
\r
103 simpleCommentOperations.add(anOperation);
\r
106 protected abstract static class EntityModifyingOperation implements MirSimpleEntityOperation {
\r
107 private String name;
\r
109 protected EntityModifyingOperation(String aName) {
\r
113 public String getName() {
\r
117 public boolean isAvailable(EntityAdapter anEntity) {
\r
119 Entity entity = anEntity.getEntity();
\r
120 return isAvailable(entity);
\r
122 catch (Throwable t) {
\r
127 public void perform(EntityAdapter aUser, EntityAdapter anEntity) {
\r
128 Entity entity = anEntity.getEntity();
\r
130 performModification(aUser, entity);
\r
133 catch (Throwable t) {
\r
137 protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectException ;
\r
138 protected abstract void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectException ;
\r
141 public static abstract class CommentModifyingOperation extends EntityModifyingOperation {
\r
142 public CommentModifyingOperation(String aName) {
\r
146 protected boolean isAvailable(Entity anEntity) throws StorageObjectException {
\r
147 return anEntity instanceof EntityComment && isAvailable((EntityComment) anEntity);
\r
150 protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectException {
\r
151 performModification(aUser, (EntityComment) anEntity);
\r
152 DatabaseContent.getInstance().setUnproduced("id="+anEntity.getValue("to_media"));
\r
155 protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectException ;
\r
156 protected abstract void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectException ;
\r
159 public static abstract class ArticleModifyingOperation extends EntityModifyingOperation {
\r
160 private boolean logOperation;
\r
162 public ArticleModifyingOperation(String aName, boolean aLogOperation) {
\r
165 logOperation = aLogOperation;
\r
168 protected boolean isAvailable(Entity anEntity) throws StorageObjectException {
\r
169 return anEntity instanceof EntityContent && isAvailable((EntityContent) anEntity);
\r
172 protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectException {
\r
173 performModification(aUser, (EntityContent) anEntity);
\r
174 anEntity.setValueForProperty("is_produced", "0");
\r
176 if (logOperation) {
\r
177 StringBuffer comment = new StringBuffer();
\r
179 comment.append(StringRoutines.interpretAsString(anEntity.getValue("comment")));
\r
181 catch (Throwable t) {
\r
183 if (comment.length()>0 && comment.charAt(comment.length()-1)!='\n') {
\r
184 comment.append('\n');
\r
186 comment.append(dateFormatter.format((new GregorianCalendar()).getTime()));
\r
187 comment.append(" ");
\r
189 comment.append(StringRoutines.interpretAsString(aUser.get("login")));
\r
191 catch (Throwable t) {
\r
193 comment.append(" ");
\r
194 comment.append(getName());
\r
195 anEntity.setValueForProperty("comment", comment.toString());
\r
199 protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectException ;
\r
200 protected abstract void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectException ;
\r
203 protected static class SetCommentFieldOperation extends CommentModifyingOperation {
\r
204 private String field;
\r
205 private String value;
\r
207 public SetCommentFieldOperation(String aName, String aField, String aValue) {
\r
214 protected boolean isAvailable(EntityComment aComment) {
\r
218 protected void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectException {
\r
219 aComment.setValueForProperty(field, value);
\r
223 protected static class ModifyCommentFieldOperation extends CommentModifyingOperation {
\r
224 private String field;
\r
225 private String value;
\r
227 public ModifyCommentFieldOperation(String aName, String aField, String aValue) {
\r
234 protected boolean isAvailable(EntityComment aComment) {
\r
235 return aComment.getValue(field) == null || !aComment.getValue(field).equals(value);
\r
238 protected void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectException {
\r
239 aComment.setValueForProperty(field, value);
\r
243 protected static class SetArticleFieldOperation extends ArticleModifyingOperation {
\r
244 private String field;
\r
245 private String value;
\r
247 public SetArticleFieldOperation(String aName, String aField, String aValue, boolean aLogOperation) {
\r
248 super(aName, aLogOperation);
\r
254 protected boolean isAvailable(EntityContent anArticle) {
\r
258 protected void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectException {
\r
259 anArticle.setValueForProperty(field, value);
\r
263 protected static class ModifyArticleFieldOperation extends ArticleModifyingOperation {
\r
264 private String field;
\r
265 private String value;
\r
267 public ModifyArticleFieldOperation(String aName, String aField, String aValue, boolean aLogOperation) {
\r
268 super(aName, aLogOperation);
\r
274 protected boolean isAvailable(EntityContent anArticle) {
\r
275 return anArticle.getValue(field) == null || !anArticle.getValue(field).equals(value);
\r
278 protected void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectException {
\r
279 anArticle.setValueForProperty(field, value);
\r
283 protected static class ChangeArticleFieldOperation extends ArticleModifyingOperation {
\r
284 private String field;
\r
285 private String oldValue;
\r
286 private String newValue;
\r
288 public ChangeArticleFieldOperation(String aName, String aField, String anOldValue, String aNewValue, boolean aLogOperation) {
\r
289 super(aName, aLogOperation);
\r
292 newValue = aNewValue;
\r
293 oldValue = anOldValue;
\r
296 protected boolean isAvailable(EntityContent anArticle) {
\r
297 return anArticle.getValue(field) != null && anArticle.getValue(field).equals(oldValue);
\r
300 protected void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectException {
\r
301 anArticle.setValueForProperty(field, newValue);
\r