From c785369f4ca9b7a6b295464041c14206c6db84bf Mon Sep 17 00:00:00 2001 From: idfx Date: Mon, 10 Sep 2001 09:54:45 +0000 Subject: [PATCH] 1-n-content-media, tomcat-session-tracking without cookies, and more --- build.sh | 2 +- source/Mir.java | 54 ++++++++------ source/OpenMir.java | 6 +- source/mir/misc/HTMLTemplateProcessor.java | 32 ++++---- source/mir/servlet/AbstractServlet.java | 4 +- source/mir/servlet/ServletModule.java | 10 +-- source/mircoders/entity/EntityContent.java | 43 +++++------ source/mircoders/module/ModuleContent.java | 3 +- source/mircoders/producer/Producer.java | 2 +- source/mircoders/producer/ProducerContent.java | 8 +- source/mircoders/producer/ProducerList.java | 9 ++- .../mircoders/servlet/ServletModuleBreaking.java | 2 +- source/mircoders/servlet/ServletModuleComment.java | 2 +- source/mircoders/servlet/ServletModuleContent.java | 36 +++------ source/mircoders/servlet/ServletModuleImages.java | 2 +- source/mircoders/servlet/ServletModuleMessage.java | 2 +- .../mircoders/storage/DatabaseContentToMedia.java | 87 ++++++++++++++++++++-- templates-dist/de/content.template | 12 ++- templates-dist/de/start_admin.template | 2 +- templates-dist/en/content.template | 35 +++++---- templates-dist/producer/content.template | 10 ++- 21 files changed, 222 insertions(+), 141 deletions(-) diff --git a/build.sh b/build.sh index d26f9004..b15c31e2 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ TOMCAT_HOME=/usr/share/tomcat ANT_HOME=/usr/share/ant -CP=$LIB_HOME/servlet-2.2.jar +CP=$LIB_HOME/servlet.jar CP=$CP:$LOCALCLASSPATH CP=$CP:$LIB_HOME/xerxes.jar:$TOMCAT_HOME/lib/tomcat.jar CP=$CP:$LIB_HOME/gnu-regexp-1.0.8.jar diff --git a/source/Mir.java b/source/Mir.java index 88183f48..37789137 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -51,11 +51,12 @@ public class Mir extends AbstractServlet confed = getConfig(req); } - + HttpSession session = req.getSession(true); + if (req.getServerPort() == 443) http="https"; else http="http"; res.setContentType("text/html"); String moduleName = req.getParameter("module"); - HttpSession session = req.getSession(true); + if(session.getAttribute("Language")==null){ setLanguage(req,getAcceptLanguage(req)); @@ -71,7 +72,7 @@ public class Mir extends AbstractServlet if (userEntity==null) { // login failed: redirecting to login theLog.printWarning("--login: failed!"); - _sendLoginPage(req,res.getWriter()); + _sendLoginPage(res,req,res.getWriter()); return; } else { // login successful @@ -98,11 +99,17 @@ public class Mir extends AbstractServlet + res.encodeURL(http +"://" + req.getServerName() +":"+ serverPort + target) + "\">going " + target + ""; } - res.getWriter().println(redirect); + //res.getWriter().println(redirect); + + res.encodeRedirectURL(http + "://" + req.getServerName() + + ":" +req.getServerPort() + target); + } else { + theLog.printDebugInfo("testurl: "+res.encodeURL("")); + theLog.printDebugInfo("querystring: "+req.getQueryString()); // redirecting to default target //theLog.printDebugInfo("--login: no target - redirecting to default"); - _sendStartPage(req, res.getWriter(),userEntity); + _sendStartPage(res,req, res.getWriter(),userEntity); } return; } // if login succesful @@ -111,7 +118,7 @@ public class Mir extends AbstractServlet if (moduleName!=null && moduleName.equals("logout")) { theLog.printDebugInfo("--logout"); session.invalidate(); - _sendLoginPage(req,res.getWriter()); + _sendLoginPage(res,req,res.getWriter()); return; } @@ -123,13 +130,13 @@ public class Mir extends AbstractServlet if (req.getQueryString()!=null) redirectString += "?" + req.getQueryString(); theLog.printDebugInfo("STORING: " + redirectString); session.setAttribute("login.target", redirectString); - _sendLoginPage(req,res.getWriter()); + _sendLoginPage(res,req,res.getWriter()); return; } // Bei blossem Serveltaufruf redirect auf Standardstarttemplate if (moduleName == null || moduleName.equals("")) { - _sendStartPage(req, res.getWriter(),userEntity); + _sendStartPage(res,req, res.getWriter(),userEntity); return; } @@ -146,26 +153,26 @@ public class Mir extends AbstractServlet smod = (ServletModule)m.invoke(null,null); ServletModuleDispatch.dispatch(smod,req,res); } - catch (NoSuchMethodException e) { handleError( res.getWriter(), "ServletModule" + moduleName + " getInstance() nicht gefunden."); } - catch (InvocationTargetException e) { handleError( res.getWriter(), "ServletModule" + moduleName + " target nicht gefunden."); } - catch (ClassNotFoundException e) { handleError( res.getWriter(), "ServletModule" + moduleName + " nicht gefunden."); } - catch (IllegalArgumentException e) { handleError( res.getWriter(), "ServletModule" + moduleName + " nicht gefunden."); } - catch (ServletModuleException e){ handleError(res.getWriter(), "ServletException in Module ServletModule" + moduleName + " -- " + e.toString()); } + catch (NoSuchMethodException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " getInstance() nicht gefunden."); } + catch (InvocationTargetException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " target nicht gefunden."); } + catch (ClassNotFoundException e) { handleError(res, res.getWriter(), "ServletModule" + moduleName + " nicht gefunden."); } + catch (IllegalArgumentException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " nicht gefunden."); } + catch (ServletModuleException e){ handleError(res,res.getWriter(), "ServletException in Module ServletModule" + moduleName + " -- " + e.toString()); } catch (IllegalAccessException e){ - handleError(res.getWriter(), "Kein Zugriff auf Klasse ServletModule" + moduleName + " -- " + e.toString()); } + handleError(res,res.getWriter(), "Kein Zugriff auf Klasse ServletModule" + moduleName + " -- " + e.toString()); } // timing... sessionConnectTime = new java.util.Date().getTime() - startTime; theLog.printInfo("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms"); } - private void handleError(PrintWriter out, String errorString) { + private void handleError(HttpServletResponse res, PrintWriter out, String errorString) { try { theLog.printError(errorString); SimpleHash modelRoot = new SimpleHash(); modelRoot.put("errorstring", new SimpleScalar(errorString)); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - HTMLTemplateProcessor.process(Configuration.getProperty("Mir.ErrorTemplate"),modelRoot,out); + HTMLTemplateProcessor.process(res,Configuration.getProperty("Mir.ErrorTemplate"),modelRoot,out); out.close(); } catch (Exception e) { @@ -185,31 +192,34 @@ public class Mir extends AbstractServlet } // Redirect-methods - private void _sendLoginPage(HttpServletRequest req, PrintWriter out) { + private void _sendLoginPage(HttpServletResponse res,HttpServletRequest req, PrintWriter out) { String loginTemplate = "login.template"; try { theLog.printDebugInfo("login: "+lang); if(lang==null){ lang=getAcceptLanguage(req); } - HTMLTemplateProcessor.process(lang+"/"+loginTemplate, new SimpleHash(), out); + HTMLTemplateProcessor.process(res,lang+"/"+loginTemplate, new SimpleHash(), out); } catch(HTMLParseException e) { - handleError( out, "fehler in logintemplate."); + handleError(res, out, "fehler in logintemplate."); } } - private void _sendStartPage(HttpServletRequest req,PrintWriter out, EntityUsers userEntity) { + private void _sendStartPage(HttpServletResponse res, HttpServletRequest req,PrintWriter out, EntityUsers userEntity) { String startTemplate = "start_admin.template"; + String sessionUrl=res.encodeURL(""); + theLog.printDebugInfo("testurl: "+sessionUrl); try { // merge with logged in user and messages SimpleHash mergeData = new SimpleHash(); + mergeData.put("session",sessionUrl); mergeData.put("login_user", HTMLTemplateProcessor.makeSimpleHash(userEntity)); if (messageModule == null) messageModule = new ModuleMessage(DatabaseMessages.getInstance()); mergeData.put("messages", HTMLTemplateProcessor.makeSimpleList(messageModule.getByWhereClause(null, "webdb_create desc",0,10))); - HTMLTemplateProcessor.process(getLanguage(req)+"/"+startTemplate, mergeData,out); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+startTemplate, mergeData,out); } catch(Exception e) { - handleError( out, "error while trying to send startpage. " + e.toString()); + handleError( res,out, "error while trying to send startpage. " + e.toString()); } } diff --git a/source/OpenMir.java b/source/OpenMir.java index 9219855d..cf4854e7 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -54,20 +54,20 @@ public class OpenMir extends AbstractServlet try { ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res); } - catch (ServletModuleException e){ handleError(res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString()); } + catch (ServletModuleException e){ handleError(res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString()); } // timing... sessionConnectTime = new java.util.Date().getTime() - startTime; theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms"); } - private void handleError(PrintWriter out, String errorString) { + private void handleError(HttpServletResponse res,PrintWriter out, String errorString) { try { theLog.printError(errorString); SimpleHash modelRoot = new SimpleHash(); modelRoot.put("errorstring", new SimpleScalar(errorString)); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - HTMLTemplateProcessor.process(Configuration.getProperty("Mir.ErrorTemplate"),modelRoot,out); + HTMLTemplateProcessor.process(res,Configuration.getProperty("Mir.ErrorTemplate"),modelRoot,out); out.close(); } catch (Exception e) { diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 70ec150d..1a613301 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -12,6 +12,7 @@ import java.net.*; import freemarker.template.*; import mir.entity.*; import mir.storage.*; +import javax.servlet.http.*; /** @@ -30,7 +31,7 @@ public final class HTMLTemplateProcessor { private static String imageHost; private static String openAction; protected static String producerDocRoot = Configuration.getProperty("Producer.DocRoot"); - protected static String producerStorageRoot = Configuration.getProperty("Producer.StorageRoot"); + protected static String producerStorageRoot = Configuration.getProperty("Producer.StorageRoot"); // @@ -94,9 +95,9 @@ public final class HTMLTemplateProcessor { * @param out * @exception HTMLParseException */ - public static void process(String templateFilename, EntityList entList, PrintWriter out) + public static void process(HttpServletResponse res,String templateFilename, EntityList entList, PrintWriter out) throws HTMLParseException { - process( templateFilename, entList, (String)null, (TemplateModelRoot)null, out); + process(res, templateFilename, entList, (String)null, (TemplateModelRoot)null, out); } /** @@ -112,7 +113,7 @@ public final class HTMLTemplateProcessor { * @param out * @exception HTMLParseException */ - public static void process(String templateFilename, EntityList entList, String additionalModelName, + public static void process(HttpServletResponse res,String templateFilename, EntityList entList, String additionalModelName, TemplateModelRoot additionalModel, PrintWriter out) throws HTMLParseException { @@ -120,7 +121,7 @@ public final class HTMLTemplateProcessor { if (entList == null) { //theLog.printInfo("Keine Daten! Suche erfolglos."); - process(templateFilename, modelRoot, out); + process(null,templateFilename, modelRoot, out); } else { try { modelRoot = makeSimpleHashWithEntitylistInfos(entList); @@ -129,7 +130,7 @@ public final class HTMLTemplateProcessor { if (additionalModelName != null && additionalModel != null) modelRoot.put(additionalModelName, additionalModel); - process(templateFilename, modelRoot, out); + process(res,templateFilename, modelRoot, out); } catch (StorageObjectException e) { throw new HTMLParseException(e.toString()); } @@ -146,9 +147,9 @@ public final class HTMLTemplateProcessor { * @param out * @exception HTMLParseException */ - public static void process(String templateFilename, HashMap mergeData, PrintWriter out) + public static void process(HttpServletResponse res,String templateFilename, HashMap mergeData, PrintWriter out) throws HTMLParseException { - process(templateFilename, makeSimpleHash(mergeData), out); + process(res,templateFilename, makeSimpleHash(mergeData), out); } /** @@ -162,7 +163,7 @@ public final class HTMLTemplateProcessor { */ public static void process(String templateFilename, PrintWriter out) throws HTMLParseException { - process(templateFilename, (TemplateModelRoot)null, out); + process(null,templateFilename, (TemplateModelRoot)null, out); } @@ -176,16 +177,16 @@ public final class HTMLTemplateProcessor { * @param out * @exception HTMLParseException */ - public static void process(String templateFilename, TemplateModelRoot tmr, PrintWriter out) + public static void process(HttpServletResponse res,String templateFilename, TemplateModelRoot tmr, PrintWriter out) throws HTMLParseException { if (out==null) throw new HTMLParseException("KEIN OUTPUTSTREAM"); Template tmpl = getTemplateFor(templateFilename); if (tmpl == null) throw new HTMLParseException("KEIN TEMPLATE: " + templateFilename); if (tmr==null) tmr = new SimpleHash(); - - //some utilities - SimpleHash utilityHash = new SimpleHash(); - utilityHash.put("htmlEscape",new freemarker.template.utility.HtmlEscape()); + String session=null; + if (res!=null) { + session=res.encodeURL(""); + } // put standard configuration into tempalteRootmodel SimpleHash configHash = new SimpleHash(); @@ -197,7 +198,7 @@ public final class HTMLTemplateProcessor { tmr.put("docRoot", new SimpleScalar(docRoot)); tmr.put("now", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - tmr.put("actionRoot", new SimpleScalar(actionRoot)); + tmr.put("actionRoot", new SimpleScalar(actionRoot+session)); tmr.put("openAction", new SimpleScalar(openAction)); tmr.put("productionHost", new SimpleScalar(productionHost)); tmr.put("videoHost", new SimpleScalar(videoHost)); @@ -205,7 +206,6 @@ public final class HTMLTemplateProcessor { tmr.put("imageHost", new SimpleScalar(imageHost)); tmr.put("config", configHash); - tmr.put("utility",utilityHash); tmpl.process(tmr, out); } diff --git a/source/mir/servlet/AbstractServlet.java b/source/mir/servlet/AbstractServlet.java index 67a6a828..a52e2121 100755 --- a/source/mir/servlet/AbstractServlet.java +++ b/source/mir/servlet/AbstractServlet.java @@ -45,7 +45,7 @@ public abstract class AbstractServlet extends HttpServlet { * Get the session-binded language */ protected String getLanguage(HttpServletRequest req){ - HttpSession session = req.getSession(); + HttpSession session = req.getSession(true); String lang = (String)session.getAttribute("Language"); if(lang==null || lang==""){ return getAcceptLanguage(req); @@ -72,4 +72,4 @@ public abstract class AbstractServlet extends HttpServlet { theLog.printDebugInfo("Language: " + lang); return lang; } -} \ No newline at end of file +} diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index 0ac4a6cb..d276b78f 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -46,7 +46,7 @@ public abstract class ServletModule { * get the session binded language */ public String getLanguage(HttpServletRequest req){ - HttpSession session = req.getSession(); + HttpSession session = req.getSession(true); String language = (String)session.getAttribute("Language"); if(language==null){ language=Configuration.getProperty("StandardLanguage"); @@ -89,7 +89,7 @@ public abstract class ServletModule { theList = mainModule.getByWhereClause(null, offset); //theList = mainModule.getByWhereClause((String)null, offset); if (theList == null || theList.getCount() == 0 || theList.getCount()>1){ - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, theList, out); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, theList, out); } else { deliver(req, res, theList.elementAt(0), templateObjektString); } @@ -268,7 +268,7 @@ public abstract class ServletModule { try { //PrintWriter out = new LineFilterWriter(res.getWriter()); PrintWriter out = res.getWriter(); - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateFilename, rtm , out); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out); out.close(); } catch (HTMLParseException e) { throw new ServletModuleException(e.toString()); @@ -301,9 +301,9 @@ public abstract class ServletModule { * @param tmpl Name des Templates * @exception ServletModuleException */ - private void deliver(HttpServletRequest req, PrintWriter out, TemplateModelRoot rtm, String templateFilename) + private void deliver(HttpServletResponse res,HttpServletRequest req, PrintWriter out, TemplateModelRoot rtm, String templateFilename) throws HTMLParseException { - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateFilename, rtm , out); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out); } /** diff --git a/source/mircoders/entity/EntityContent.java b/source/mircoders/entity/EntityContent.java index e08494ed..693afd86 100755 --- a/source/mircoders/entity/EntityContent.java +++ b/source/mircoders/entity/EntityContent.java @@ -61,10 +61,10 @@ public class EntityContent extends AbstractEntity implements Entity String value = (yesno) ? "1":"0"; String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'"; try { - con = theStorageObject.getPooledCon(); - /** @todo should be preparedStatement: faster!! */ - stmt = con.createStatement(); - theStorageObject.executeUpdate(stmt,sql); + con = theStorageObject.getPooledCon(); + /** @todo should be preparedStatement: faster!! */ + stmt = con.createStatement(); + theStorageObject.executeUpdate(stmt,sql); } catch (StorageObjectException e) { theLog.printDebugInfo(e.toString() + "\n -- set produced failed"); } catch (SQLException e) { @@ -96,15 +96,16 @@ public class EntityContent extends AbstractEntity implements Entity * dettach from media */ - public void dettach() + public void dettach(String cid,String mid) { - String sql = "update content set to_media=null, is_produced='0' where id='" + getId()+"'"; - try { - theStorageObject.executeUpdate(sql); - } catch (StorageObjectException e) { - theLog.printError(e.toString() + "dettach failed"); - } catch (SQLException e) { - theLog.printError(e.toString() + "dettach failed"); + if (mid!=null){ + try{ + DatabaseContentToMedia.getInstance().delete(cid,mid); + } catch (Exception e){ + theLog.printError("failed to get instance"); + } + //set Content to unproduced + setProduced(false); } } @@ -115,17 +116,17 @@ public class EntityContent extends AbstractEntity implements Entity public void attach(String mid) { if (mid!=null) { - String sql = "update content set to_media='" + mid + "', is_produced='0' where id='" + getId()+"'"; - try { - theStorageObject.executeUpdate(sql); - } catch (StorageObjectException e) { - theLog.printError(e.toString() + "attach failed"); - } catch (SQLException e) { - theLog.printError(e.toString() + "attach failed"); + //write media-id mid and content-id in table content_x_media + try{ + DatabaseContentToMedia.getInstance().addMedia(getId(),mid); + } catch(StorageObjectException e){ + theLog.printError("attach: could not get the instance"); } - } - else + //set Content to unproduced + setProduced(false); + } else { theLog.printError("EntityContent: attach without mid"); + } } /** diff --git a/source/mircoders/module/ModuleContent.java b/source/mircoders/module/ModuleContent.java index b71dc56c..fd0dd25f 100755 --- a/source/mircoders/module/ModuleContent.java +++ b/source/mircoders/module/ModuleContent.java @@ -13,6 +13,7 @@ import mir.misc.*; import mir.storage.*; import mircoders.entity.*; +import mircoders.storage.*; /* * ContentObjekt - @@ -164,7 +165,7 @@ public class ModuleContent extends AbstractModule } if(whereClause.equals("media")) { - whereClause="to_media > 0"; orderBy="webdb_lastchange desc"; + return DatabaseContentToMedia.getInstance().getContent(); } } return theStorage.selectByWhereClause(whereClause, orderBy, offset); diff --git a/source/mircoders/producer/Producer.java b/source/mircoders/producer/Producer.java index e5df0038..74c30bb8 100755 --- a/source/mircoders/producer/Producer.java +++ b/source/mircoders/producer/Producer.java @@ -70,7 +70,7 @@ abstract public class Producer { outStream = new PrintWriter(outputFile); } - HTMLTemplateProcessor.process(template, model, outStream); + HTMLTemplateProcessor.process(null,template, model, outStream); outputFile.close(); outStream.close(); diff --git a/source/mircoders/producer/ProducerContent.java b/source/mircoders/producer/ProducerContent.java index 4581b4f4..96517878 100755 --- a/source/mircoders/producer/ProducerContent.java +++ b/source/mircoders/producer/ProducerContent.java @@ -131,12 +131,18 @@ public class ProducerContent extends Producer { SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues); // get the images + EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(currentContent); + if (currentMedia!=null && currentMedia.getCount()>=1) { + SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia); + mergeData.put("to_media", mediaList); + } + /** currentMediaId = currentContent.getValue("to_media"); if (currentMediaId!=null && !currentMediaId.equals("")) { imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId))); } mergeData.put("images", imageHash); - + */ // get the comments for the article mergeData.put("comments", currentContent.getComments()); diff --git a/source/mircoders/producer/ProducerList.java b/source/mircoders/producer/ProducerList.java index af8bc7de..f13b7756 100755 --- a/source/mircoders/producer/ProducerList.java +++ b/source/mircoders/producer/ProducerList.java @@ -89,9 +89,10 @@ abstract public class ProducerList extends Producer { for (int k=0; k < list.size();k++) { currentContent = (EntityContent)list.elementAt(k); //images to content - currentMediaId = currentContent.getValue("to_media"); - if (currentMediaId!=null && !currentMediaId.equals("")) { - imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId))); + EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(currentContent); + if (currentMedia!=null && currentMedia.getCount()>=1) { + SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia); + mergeData.put("to_media", mediaList); } //content to html if(currentContent.getValue("is_html").equals("0")){ @@ -157,4 +158,4 @@ abstract public class ProducerList extends Producer { } //end handle abstract public void setAdditional(String key, TemplateModel value); -} \ No newline at end of file +} diff --git a/source/mircoders/servlet/ServletModuleBreaking.java b/source/mircoders/servlet/ServletModuleBreaking.java index d8015dcf..83638edf 100755 --- a/source/mircoders/servlet/ServletModuleBreaking.java +++ b/source/mircoders/servlet/ServletModuleBreaking.java @@ -68,7 +68,7 @@ public class ServletModuleBreaking extends ServletModule mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString()); // raus damit - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); } catch (ModuleException e) {throw new ServletModuleException(e.toString());} catch (IOException e) {throw new ServletModuleException(e.toString());} diff --git a/source/mircoders/servlet/ServletModuleComment.java b/source/mircoders/servlet/ServletModuleComment.java index 319ba100..3f9c1a6a 100755 --- a/source/mircoders/servlet/ServletModuleComment.java +++ b/source/mircoders/servlet/ServletModuleComment.java @@ -117,7 +117,7 @@ public class ServletModuleComment extends ServletModule } } // raus damit - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); } catch (ModuleException e) {throw new ServletModuleException(e.toString());} catch (IOException e) {throw new ServletModuleException(e.toString());} diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index 6797d153..9d543499 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -262,37 +262,24 @@ public class ServletModuleContent extends ServletModule catch(ModuleException e) { theLog.printError("smod content :: attach :: could not get entityContent"); } - - try{ - DatabaseContentToMedia.getInstance().setMedia(idParam,mediaIdParam); - } catch(Exception e){ - theLog.printError("set media failed"); - } _showObject(idParam, req, res); } public void dettach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { - String idParam = req.getParameter("cid"); - if (idParam == null) throw new ServletModuleException("smod content :: dettach :: cid missing"); + String cidParam = req.getParameter("cid"); + String midParam = req.getParameter("mid"); + if (cidParam == null) throw new ServletModuleException("smod content :: dettach :: cid missing"); + if (midParam == null) throw new ServletModuleException("smod content :: dettach :: mid missing"); - //1-1-relation - //schould be deleted soon try { - EntityContent entContent = (EntityContent)mainModule.getById(idParam); - entContent.dettach(); + EntityContent entContent = (EntityContent)mainModule.getById(cidParam); + entContent.dettach(cidParam,midParam); } catch(ModuleException e) { theLog.printError("smod content :: dettach :: could not get entityContent"); } - - //1-n-relation - try{ - DatabaseContentToMedia.getInstance().deleteByContentId(idParam); - } catch(Exception e){ - theLog.printError("remove media failed"); - } - _showObject(idParam, req, res); + _showObject(cidParam, req, res); } public void newswire(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException @@ -389,11 +376,10 @@ public class ServletModuleContent extends ServletModule theLog.printError("language-popup could not be fetched."); } // get the images - String currentMediaId = entContent.getValue("to_media"); - SimpleHash imageHash = new SimpleHash(); - if (currentMediaId!=null && !currentMediaId.equals("")) { - imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId))); - mergeData.put("images", imageHash); + EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(entContent); + if (currentMedia!=null && currentMedia.getCount()>=1) { + SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia); + mergeData.put("to_media", mediaList); } diff --git a/source/mircoders/servlet/ServletModuleImages.java b/source/mircoders/servlet/ServletModuleImages.java index 0f063807..834dd461 100755 --- a/source/mircoders/servlet/ServletModuleImages.java +++ b/source/mircoders/servlet/ServletModuleImages.java @@ -241,7 +241,7 @@ public class ServletModuleImages extends mir.servlet.ServletModule } } // raus damit - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); } catch (ModuleException e) {throw new ServletModuleException(e.toString());} catch (IOException e) {throw new ServletModuleException(e.toString());} diff --git a/source/mircoders/servlet/ServletModuleMessage.java b/source/mircoders/servlet/ServletModuleMessage.java index 512e3918..30ba6b63 100755 --- a/source/mircoders/servlet/ServletModuleMessage.java +++ b/source/mircoders/servlet/ServletModuleMessage.java @@ -68,7 +68,7 @@ public class ServletModuleMessage extends ServletModule mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString()); // raus damit - HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); } catch (ModuleException e) {throw new ServletModuleException(e.toString());} diff --git a/source/mircoders/storage/DatabaseContentToMedia.java b/source/mircoders/storage/DatabaseContentToMedia.java index 9a475751..e154fcb6 100755 --- a/source/mircoders/storage/DatabaseContentToMedia.java +++ b/source/mircoders/storage/DatabaseContentToMedia.java @@ -90,7 +90,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ con = getPooledCon(); // should be a preparedStatement because is faster stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); + int rs = executeUpdate(stmt,sql); } catch (Exception e) { theLog.printDebugInfo("-- set topics failed -- insert"); } finally { @@ -99,7 +99,28 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ } } - + public void addMedia(String contentId, String mediaId) { + if (contentId == null && mediaId == null) { + return; + } + + Connection con=null;Statement stmt=null; + //now insert + + String sql = "insert into "+ theTable +" (content_id,media_id) values (" + + contentId + "," + mediaId + ")"; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt,sql); + } catch (Exception e) { + theLog.printDebugInfo("-- add media failed -- insert"); + } finally { + freeConnection(con,stmt); + } + } + public void setMedia(String contentId, String mediaId) { if (contentId == null && mediaId == null) { return; @@ -149,7 +170,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ con = getPooledCon(); // should be a preparedStatement because is faster stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); + int rs = executeUpdate(stmt,sql); } catch (Exception e) { //theLog.printDebugInfo("-- delete topics failed "); } finally { @@ -163,14 +184,14 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ return; } //delete all row with content_id=contentId - String sql = "delete from "+ theTable +" where topic_id=" + mediaId; + String sql = "delete from "+ theTable +" where media_id=" + mediaId; Connection con=null;Statement stmt=null; try { con = getPooledCon(); // should be a preparedStatement because is faster stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); + int rs = executeUpdate(stmt,sql); theLog.printDebugInfo("-- delete media success "); } catch (Exception e) { theLog.printDebugInfo("-- delete media failed "); @@ -178,6 +199,28 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ freeConnection(con,stmt); } } + + public void delete(String contentId, String mediaId) { + if (mediaId == null || contentId==null) { + theLog.printDebugInfo("-- delete media failed -- missing parameter"); + return; + } + //delete all row with content_id=contentId and media_id=mediaId + String sql = "delete from "+ theTable +" where media_id=" + mediaId + " and content_id= "+contentId; + + Connection con=null;Statement stmt=null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt,sql); + theLog.printDebugInfo("-- delete content_x_media success "); + } catch (Exception e) { + theLog.printDebugInfo("-- delete content_x_media failed "); + } finally { + freeConnection(con,stmt); + } + } public EntityList getContent(EntityMedia media) { @@ -211,5 +254,39 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ } return returnList; } + +/** + * Returns a EntityList with all content-objects having a relation to a media + */ + +public EntityList getContent() { + EntityList returnList=null; + + String select = "select distinct content_id from " + theTable; + // execute select statement + Connection con=null;Statement stmt=null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + ResultSet rs = executeSql(stmt,select); + if (rs!=null) { + String mediaSelect= "id IN ("; + boolean first=true; + while (rs.next()) { + if (first==false) mediaSelect+=","; + mediaSelect += rs.getString(1); + first=false; + } + mediaSelect+=")"; + if (first==false) + returnList = DatabaseContent.getInstance().selectByWhereClause(mediaSelect,"webdb_lastchange desc"); + } + } + catch (Exception e) {theLog.printDebugInfo("-- get content failed");} + finally { freeConnection(con,stmt);} + + return returnList; + } } diff --git a/templates-dist/de/content.template b/templates-dist/de/content.template index 760c0484..31631b5a 100755 --- a/templates-dist/de/content.template +++ b/templates-dist/de/content.template @@ -217,17 +217,17 @@ p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} Attachments - - + + Bilder:
- edit image - entfernen + edit image + entfernen - +
Medien:
@@ -235,8 +235,6 @@ p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} bild hinzufügen -
- diff --git a/templates-dist/de/start_admin.template b/templates-dist/de/start_admin.template index aea62da5..25eff838 100755 --- a/templates-dist/de/start_admin.template +++ b/templates-dist/de/start_admin.template @@ -15,7 +15,7 @@ OPENPOSTINGS

- + bearbeiten

diff --git a/templates-dist/en/content.template b/templates-dist/en/content.template index 2a66f3b8..50f6fb21 100755 --- a/templates-dist/en/content.template +++ b/templates-dist/en/content.template @@ -218,24 +218,23 @@ p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} Attachments - - - - Bilder:
- - edit image - entfernen - - - - - - media:
- - add picture - - -
+ + + + Images:
+ + edit image + delete + + +
+ + + Medien:
+ + add image + + diff --git a/templates-dist/producer/content.template b/templates-dist/producer/content.template index 8ea22809..664facfc 100755 --- a/templates-dist/producer/content.template +++ b/templates-dist/producer/content.template @@ -76,10 +76,12 @@

${title}

-

${description}

- - ${images[to_media][
-
+

${description}

+ + + ${m[
+
+

${content_data} -- 2.11.0