-/*
- * 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.
- */
-
+/*\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 the com.oreilly.servlet library, any library\r
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
+ * the above that use the same license as the above), and distribute linked\r
+ * combinations including the two. You must obey the GNU General Public\r
+ * License in all respects for all of the code used other than the above\r
+ * mentioned libraries. If you modify this file, you may extend this exception\r
+ * to your version of the file, but you are not obligated to do so. If you do\r
+ * not wish to do so, delete this exception statement from your version.\r
+ */\r
+\r
package mircoders.localizer.basic;\r
\r
-import java.util.*;\r
-import mir.entity.*;\r
-import mir.entity.adapter.*;\r
-import mir.media.*;\r
-import mir.misc.*;\r
-import mir.util.*;\r
-import mircoders.storage.*;\r
-import mircoders.global.*;\r
-import mircoders.entity.*;\r
-import mircoders.localizer.*;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Vector;\r
+\r
+import mir.entity.Entity;\r
+import mir.entity.adapter.EntityAdapter;\r
+import mir.entity.adapter.EntityAdapterDefinition;\r
+import mir.entity.adapter.EntityAdapterModel;\r
+import mir.media.MediaHelper;\r
+import mir.media.MirMedia;\r
+import mir.util.RewindableIterator;\r
+import mircoders.entity.EntityUploadedMedia;\r
+import mircoders.global.MirGlobal;\r
+import mircoders.localizer.MirAdminInterfaceLocalizer;\r
+import mircoders.localizer.MirDataModelLocalizer;\r
+import mircoders.localizer.MirLocalizerFailure;\r
+import mircoders.storage.DatabaseArticleType;\r
+import mircoders.storage.DatabaseAudio;\r
+import mircoders.storage.DatabaseBreaking;\r
+import mircoders.storage.DatabaseComment;\r
+import mircoders.storage.DatabaseCommentStatus;\r
+import mircoders.storage.DatabaseContent;\r
+import mircoders.storage.DatabaseFeature;\r
+import mircoders.storage.DatabaseImageType;\r
+import mircoders.storage.DatabaseImages;\r
+import mircoders.storage.DatabaseLanguage;\r
+import mircoders.storage.DatabaseMedia;\r
+import mircoders.storage.DatabaseMediaType;\r
+import mircoders.storage.DatabaseMediafolder;\r
+import mircoders.storage.DatabaseMessages;\r
+import mircoders.storage.DatabaseOther;\r
+import mircoders.storage.DatabaseTopics;\r
+import mircoders.storage.DatabaseUploadedMedia;\r
+import mircoders.storage.DatabaseUsers;\r
+import mircoders.storage.DatabaseVideo;\r
\r
public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {\r
private EntityAdapterModel model;\r
anEntityAdapterDefinition.addMirDateField("date", "date");\r
anEntityAdapterDefinition.addCalculatedField("to_topics", new ContentToTopicsField());\r
anEntityAdapterDefinition.addCalculatedField("to_comments", new ContentToCommentsField());\r
+ anEntityAdapterDefinition.addCalculatedField("language", new ContentToLanguageField());\r
+\r
+ anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'"));\r
+ anEntityAdapterDefinition.addCalculatedField("fullcommentcount", new ContentCommentCountField(""));\r
\r
anEntityAdapterDefinition.addCalculatedField("to_media_images", new ContentToMediaField( "image" ));\r
anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new ContentToMediaField( "uploadedMedia" ));\r
anEntityAdapterDefinition.addCalculatedField("to_media_other", new ContentToMediaField( "otherMedia" ));\r
anEntityAdapterDefinition.addCalculatedField("to_media_icon", new ContentToIconField());\r
\r
+ anEntityAdapterDefinition.addCalculatedField("article_type", new ContentToArticleTypeField());\r
+\r
anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description"));\r
anEntityAdapterDefinition.addCalculatedField("content_data_parsed", new FilteredField("content_data"));\r
+\r
+ anEntityAdapterDefinition.addCalculatedField("operations",\r
+ new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleArticleOperations()));\r
}\r
catch (Throwable t) {\r
throw new MirLocalizerFailure(t.getMessage(), t);\r
try {\r
anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create");\r
anEntityAdapterDefinition.addCalculatedField("to_content", new CommentToContentField());\r
+ anEntityAdapterDefinition.addCalculatedField("status", new CommentToStatusField());\r
\r
anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description"));\r
- anEntityAdapterDefinition.addCalculatedField("operations", new CommentToOperationsField());\r
+ anEntityAdapterDefinition.addCalculatedField("operations",\r
+ new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleCommentOperations()));\r
}\r
catch (Throwable t) {\r
throw new MirLocalizerFailure(t.getMessage(), t);\r
result.addMapping( "comment", DatabaseComment.getInstance(), definition);\r
\r
result.addMapping( "articleType", DatabaseArticleType.getInstance(), new EntityAdapterDefinition());\r
- result.addMapping( "breakingNews", DatabaseBreaking.getInstance(), new EntityAdapterDefinition());\r
+ result.addMapping( "commentStatus", DatabaseCommentStatus.getInstance(), new EntityAdapterDefinition());\r
+\r
+ definition = new EntityAdapterDefinition();\r
+ definition.addDBDateField("creationdate", "webdb_create");\r
+ result.addMapping( "breakingNews", DatabaseBreaking.getInstance(), definition);\r
+\r
result.addMapping( "feature", DatabaseFeature.getInstance(), new EntityAdapterDefinition());\r
result.addMapping( "imageType", DatabaseImageType.getInstance(), new EntityAdapterDefinition());\r
result.addMapping( "language", DatabaseLanguage.getInstance(), new EntityAdapterDefinition());\r
protected class CommentToContentField implements EntityAdapterDefinition.CalculatedField {\r
public Object getValue(EntityAdapter anEntityAdapter) {\r
try {\r
- return anEntityAdapter.getRelation(\r
+ return anEntityAdapter.getToOneRelation(\r
"id="+anEntityAdapter.get("to_media"),\r
"id",\r
"content" );\r
}\r
}\r
\r
- protected class CommentToOperationsField implements EntityAdapterDefinition.CalculatedField {\r
+ protected class CommentToStatusField implements EntityAdapterDefinition.CalculatedField {\r
+ public Object getValue(EntityAdapter anEntityAdapter) {\r
+ try {\r
+ return anEntityAdapter.getToOneRelation(\r
+ "id="+anEntityAdapter.get("to_comment_status"),\r
+ "id",\r
+ "commentStatus" );\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ protected class EntityToSimpleOperationsField implements EntityAdapterDefinition.CalculatedField {\r
+ private List operations;\r
+\r
+ public EntityToSimpleOperationsField(List anOperations) {\r
+ operations = anOperations;\r
+ }\r
+\r
public Object getValue(EntityAdapter anEntityAdapter) {\r
try {\r
- Map operations = MirGlobal.localizer().adminInterface().simpleCommentOperations();\r
- Iterator i = operations.entrySet().iterator();\r
+ Iterator i = operations.iterator();\r
List availableOperations = new Vector();\r
\r
while (i.hasNext()) {\r
- Map.Entry entry = (Map.Entry) i.next();\r
-\r
MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =\r
- (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) entry.getValue();\r
+ (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();\r
\r
if (operation.isAvailable(anEntityAdapter)) {\r
- availableOperations.add(entry.getKey());\r
+ availableOperations.add(operation.getName());\r
}\r
};\r
\r
}\r
}\r
\r
+ protected class ContentToLanguageField implements EntityAdapterDefinition.CalculatedField {\r
+ public Object getValue(EntityAdapter anEntityAdapter) {\r
+ try {\r
+ return anEntityAdapter.getToOneRelation(\r
+ "id="+anEntityAdapter.get("to_language"),\r
+ "id",\r
+ "language" );\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ protected class ContentToArticleTypeField implements EntityAdapterDefinition.CalculatedField {\r
+ public Object getValue(EntityAdapter anEntityAdapter) {\r
+ try {\r
+ return anEntityAdapter.getToOneRelation(\r
+ "id="+anEntityAdapter.get("to_article_type"),\r
+ "id",\r
+ "articleType" );\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
protected class ContentToCommentsField implements EntityAdapterDefinition.CalculatedField {\r
public Object getValue(EntityAdapter anEntityAdapter) {\r
try {\r
iconAlt = "Image";\r
}\r
else {\r
- tinyIcon = mediaHandler.getTinyIcon();\r
- iconAlt = mediaHandler.getIconAlt();\r
+ tinyIcon = mediaHandler.getTinyIconName();\r
+ iconAlt = mediaHandler.getIconAltName();\r
}\r
\r
}\r
return result;\r
}\r
}\r
-}
\ No newline at end of file
+\r
+ protected class ContentCommentCountField implements EntityAdapterDefinition.CalculatedField {\r
+ private String extraCondition;\r
+\r
+ public ContentCommentCountField(String anExtraCondition) {\r
+ super();\r
+\r
+ extraCondition = anExtraCondition;\r
+ }\r
+\r
+ public Object getValue(EntityAdapter anEntityAdapter) {\r
+ try {\r
+ return Integer.toString(\r
+ DatabaseComment.getInstance().getSize(\r
+ "to_media="+anEntityAdapter.get("id")+" " + extraCondition));\r
+ }\r
+ catch (Throwable t) {\r
+ throw new RuntimeException(t.getMessage());\r
+ }\r
+ }\r
+ }\r
+}\r