-/*
- * 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.global;
-
-import mir.config.MirPropertiesConfiguration;
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
-import mir.misc.ConfigException;
-import mircoders.localizer.MirCachingLocalizerDecorator;
-import mircoders.localizer.MirLocalizer;
-
-public class MirGlobal {
- static private MirPropertiesConfiguration configuration;
- static private MirLocalizer localizer;
- static private ProducerEngine producerEngine;
- static private Abuse abuse;
-
- public static MirLocalizer localizer() {
- String localizerClassName;
- Class localizerClass;
-
- if (localizer == null ) {
- synchronized(MirGlobal.class) {
- if (localizer == null ) {
- localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer");
-
- try {
- localizerClass = Class.forName(localizerClassName);
- }
- catch (Throwable t) {
- throw new ConfigException("localizer class '" + localizerClassName + "' not found: " + t.toString());
- }
-
- if (!(MirLocalizer.class.isAssignableFrom(localizerClass)))
- throw new ConfigException("localizer class '" + localizerClassName + "' is not assignable from MirLocalizer");
-
- try {
- localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance());
- }
- catch (Throwable t) {
- throw new ConfigException("localizer class '" + localizerClassName + "' cannot be instantiated: " + t.toString());
- }
- }
- }
- }
-
- return localizer;
- }
-
- public static Abuse abuse() {
- if (abuse==null) {
- synchronized(MirGlobal.class) {
- if (abuse==null)
- abuse = new Abuse();
- }
- }
-
- return abuse;
- }
-
- public static MirPropertiesConfiguration config() {
- try {
- return MirPropertiesConfiguration.instance();
- }
- catch (PropertiesConfigExc e) {
- throw new RuntimeException(e.getMessage());
- }
- }
-
- public static ProducerEngine producerEngine() {
- if (producerEngine == null) {
- producerEngine = new ProducerEngine();
- }
-
- return producerEngine;
- }
-}
+/*\r
+ * Copyright (C) 2001, 2002 The Mir-coders group\r
+ *\r
+ * This file is part of Mir.\r
+ *\r
+ * Mir is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Mir is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Mir; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ *\r
+ * In addition, as a special exception, The Mir-coders gives permission to link\r
+ * the code of this program with any library licensed under the Apache Software License,\r
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
+ * (or with modified versions of the above that use the same license as the above),\r
+ * and distribute linked combinations including the two. You must obey the\r
+ * GNU General Public License in all respects for all of the code used other than\r
+ * the above mentioned libraries. If you modify this file, you may extend this\r
+ * exception to your version of the file, but you are not obligated to do so.\r
+ * If you do not wish to do so, delete this exception statement from your version.\r
+ */\r
+\r
+package mircoders.global;\r
+\r
+import java.util.*;\r
+\r
+import mir.config.MirPropertiesConfiguration;\r
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;\r
+import mir.misc.ConfigException;\r
+import mircoders.localizer.MirCachingLocalizerDecorator;\r
+import mircoders.localizer.*;\r
+import mircoders.accesscontrol.*;\r
+import mircoders.entity.*;\r
+import mir.entity.adapter.*;\r
+\r
+public class MirGlobal {\r
+ static private MirPropertiesConfiguration configuration;\r
+ static private MirLocalizer localizer;\r
+ static private ProducerEngine producerEngine;\r
+ static private Abuse abuse;\r
+ static private MRUCache mruCache;\r
+ static private AccessControl accessControl;\r
+ static private Map articleOperations;\r
+ static private Map commentOperations;\r
+\r
+ public synchronized static MirLocalizer localizer() {\r
+ String localizerClassName;\r
+ Class localizerClass;\r
+\r
+ if (localizer == null ) {\r
+ localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer");\r
+\r
+ try {\r
+ localizerClass = Class.forName(localizerClassName);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new ConfigException("localizer class '" + localizerClassName + "' not found: " + t.toString());\r
+ }\r
+\r
+ if (!(MirLocalizer.class.isAssignableFrom(localizerClass)))\r
+ throw new ConfigException("localizer class '" + localizerClassName + "' is not assignable from MirLocalizer");\r
+\r
+ try {\r
+ localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance());\r
+ }\r
+ catch (Throwable t) {\r
+ throw new ConfigException("localizer class '" + localizerClassName + "' cannot be instantiated: " + t.toString());\r
+ }\r
+ }\r
+\r
+ return localizer;\r
+ }\r
+\r
+ public static Abuse abuse() {\r
+ if (abuse==null) {\r
+ synchronized(MirGlobal.class) {\r
+ if (abuse==null)\r
+ abuse = new Abuse();\r
+ }\r
+ }\r
+\r
+ return abuse;\r
+ }\r
+\r
+ public static MirPropertiesConfiguration config() {\r
+ try {\r
+ return MirPropertiesConfiguration.instance();\r
+ }\r
+ catch (PropertiesConfigExc e) {\r
+ throw new RuntimeException(e.getMessage());\r
+ }\r
+ }\r
+\r
+ public static ProducerEngine producerEngine() {\r
+ if (producerEngine == null) {\r
+ producerEngine = new ProducerEngine();\r
+ }\r
+\r
+ return producerEngine;\r
+ }\r
+\r
+ public static MRUCache mruCache() {\r
+ synchronized(MirGlobal.class) {\r
+ if (mruCache == null) {\r
+ mruCache = new MRUCache();\r
+ }\r
+ return mruCache;\r
+ }\r
+ }\r
+\r
+ public static synchronized AccessControl accessControl() {\r
+ if (accessControl == null) {\r
+ accessControl=new AccessControl();\r
+ }\r
+\r
+ return accessControl;\r
+ }\r
+\r
+ public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) {\r
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getArticleOperationForName(anOperation);\r
+\r
+ try {\r
+ if (operation!=null)\r
+ operation.perform(\r
+ localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser),\r
+ localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle));\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.toString());\r
+ }\r
+ }\r
+\r
+ public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) {\r
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getCommentOperationForName(anOperation);\r
+\r
+ try {\r
+ if (operation!=null)\r
+ operation.perform(\r
+ localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser),\r
+ localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment));\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.toString());\r
+ }\r
+ }\r
+\r
+ private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getArticleOperationForName(String aName) {\r
+ try {\r
+ if (articleOperations == null) {\r
+ articleOperations = new HashMap();\r
+ Iterator i = localizer().adminInterface().simpleArticleOperations().iterator();\r
+ while (i.hasNext()) {\r
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();\r
+ articleOperations.put(operation.getName(), operation);\r
+ }\r
+ }\r
+\r
+ return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) articleOperations.get(aName);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.toString());\r
+ }\r
+ }\r
+\r
+ private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getCommentOperationForName(String aName) {\r
+ try {\r
+ if (commentOperations == null) {\r
+ commentOperations = new HashMap();\r
+ Iterator i = localizer().adminInterface().simpleCommentOperations().iterator();\r
+ while (i.hasNext()) {\r
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();\r
+ commentOperations.put(operation.getName(), operation);\r
+ }\r
+ }\r
+\r
+ return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) commentOperations.get(aName);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.toString());\r
+ }\r
+ }\r
+\r
+}\r
+\r
+\r