import mir.entity.adapter.EntityAdapterModel;
import mir.entity.adapter.EntityIteratorAdapter;
+import mir.entity.adapter.EntityAdapter;
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
import mir.servlet.ServletModule;
import mir.util.SQLQueryBuilder;
import mir.util.StringRoutines;
import mir.util.URLBuilder;
+import mir.generator.Generator;
import mircoders.entity.*;
import mircoders.global.MirGlobal;
import mircoders.module.ModuleContent;
import mircoders.storage.DatabaseContent;
import mircoders.storage.DatabaseContentToTopics;
-/*
- * ServletModuleContent -
- * deliver html for the article admin form.
- *
- * @version $Id: ServletModuleContent.java,v 1.52.2.13 2003/12/21 13:32:06 zapata Exp $
- * @author rk, mir-coders
- *
+/**
+ * Article admin interface code
*/
public class ServletModuleContent extends ServletModule
logger = new LoggerWrapper("ServletModule.Content");
try {
- contentModule = new ModuleContent(DatabaseContent.getInstance());
+ contentModule = new ModuleContent();
mainModule = contentModule;
}
catch (Throwable e) {
editObject(aRequest, aResponse, null);
}
- public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
try {
Map withValues = getIntersectingValues(aRequest, DatabaseContent.getInstance());
String id = mainModule.add(withValues);
logAdminUsage(aRequest, id, "object added");
- List topics;
-
DatabaseContentToTopics.getInstance().setTopics(id, aRequest.getParameterValues("to_topic"));
editObject(aRequest, aResponse, id);
}
}
- public void edit(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void edit(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String idParam = aRequest.getParameter("id");
if (idParam == null)
throw new ServletModuleExc("Invalid call: id not supplied ");
* Attaches media to an article
*
*/
- public void attach(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void attach(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String mediaIdParam = aRequest.getParameter("mid");
String articleId = aRequest.getParameter("articleid");
{
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
- String returnUrl = requestParser.getParameter("returnurl");
-
- String idParam = aRequest.getParameter("id");
+ String idParam = requestParser.getParameter("id");
if (idParam == null)
throw new ServletModuleExc("Wrong call: (id) is missing");
{
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
- String returnUrl = requestParser.getParameter("returnurl");
-
- String idParam = aRequest.getParameter("id");
+ String idParam = requestParser.getParameter("id");
if (idParam == null)
throw new ServletModuleExc("Wrong call: (id) is missing");
{
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
- String returnUrl = requestParser.getParameter("returnurl");
-
- String idParam = aRequest.getParameter("id");
+ String idParam = requestParser.getParameter("id");
if (idParam == null)
throw new ServletModuleExc("Wrong call: (id) is missing");
try {
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
- String returnUrl = requestParser.getParameter("returnurl");
-
- String idParam = aRequest.getParameter("id");
+ String idParam = requestParser.getParameter("id");
if (idParam == null)
throw new ServletModuleExc("Wrong call: (id) is missing");
Map withValues = getIntersectingValues(aRequest, DatabaseContent.getInstance());
- String content_id = aRequest.getParameter("id");
-
withValues.put("is_produced", "0");
if (!withValues.containsKey("is_published"))
withValues.put("is_published","0");
responseData.put("mayUnlock", new Boolean(MirGlobal.accessControl().article().mayUnlockArticle(user, id)));
}
else {
- List fields = DatabaseContent.getInstance().getFields();
+ List fields = DatabaseContent.getInstance().getFieldNames();
responseData.put("new", Boolean.TRUE);
article = new HashMap();
Iterator i = fields.iterator();
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
URLBuilder urlBuilder = new URLBuilder();
- EntityAdapterModel model;
int count;
try {
Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
- model = MirGlobal.localizer().dataModel().adapterModel();
-
Object articleList =
new CachingRewindableIterator(
new EntityIteratorAdapter( aWhereClause, anOrderByClause, nrEntitiesPerListPage,
}
}
- public void listchildren(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void listchildren(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
try {
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
String articleId = requestParser.getParameter("article_id");
if (articleId == null)
throw new ServletModuleExc("ServletModuleContent.listchildren: article_id not set!");
- returnList(aRequest, aResponse, "to_content = " + articleId, "", 0, null);
+ returnList(aRequest, aResponse, "to_content = " + articleId, "webdb_create desc", 0, null);
}
catch (Throwable e) {
throw new ServletModuleFailure(e);
public void setparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
{
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
- String articleId = aRequest.getParameter("childid");
- String parentId = aRequest.getParameter("id");
- String returnUrl = aRequest.getParameter("returnurl");
+ String articleId = requestParser.getParameter("childid");
+ String parentId = requestParser.getParameter("id");
+ String returnUrl = requestParser.getParameter("returnurl");
if (!MirGlobal.accessControl().article().mayEditArticle(ServletHelper.getUser(aRequest), articleId))
throw new ServletModuleExc("Article has been locked");
try {
EntityContent article = (EntityContent) mainModule.getById(articleId);
- article.setValueForProperty("to_content", parentId);
+ article.setFieldValue("to_content", parentId);
article.setProduced(false);
article.update();
logAdminUsage(aRequest, articleId, "parent set to " + parentId);
throw new ServletModuleFailure(e);
}
- redirect(aResponse, returnUrl);
+ ServletHelper.redirect(aResponse, returnUrl);
}
public void clearparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
try {
EntityContent article = (EntityContent) mainModule.getById(articleId);
- article.setValueForProperty("to_content", "");
+ article.setFieldValue("to_content", "");
article.setProduced(false);
article.update();
logAdminUsage(aRequest, articleId, "parent cleared");
throw new ServletModuleFailure("ServletModuleContent.clearparent: " + e.getMessage(), e);
}
- redirect(aResponse, returnUrl);
+ ServletHelper.redirect(aResponse, returnUrl);
+ }
+
+ public void showPreview(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ try {
+ HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
+ String articleId = requestParser.getParameter("id");
+ EntityAdapter article = model.makeEntityAdapter("content", mainModule.getById(articleId));
+ String preview = requestParser.getParameterWithDefault("preview", "default");
+
+ Map generationValues = new HashMap();
+ Generator generator =
+ MirGlobal.localizer().adminInterface().prepareArticlePreview(preview, article, generationValues);
+
+ generator.generate(aResponse.getWriter(), generationValues, logger);
+ }
+ catch (Exception e) {
+ throw new ServletModuleFailure(e);
+ }
}
}