1-n-content-media, tomcat-session-tracking without cookies, and more
authoridfx <idfx>
Mon, 10 Sep 2001 09:54:45 +0000 (09:54 +0000)
committeridfx <idfx>
Mon, 10 Sep 2001 09:54:45 +0000 (09:54 +0000)
21 files changed:
build.sh
source/Mir.java
source/OpenMir.java
source/mir/misc/HTMLTemplateProcessor.java
source/mir/servlet/AbstractServlet.java
source/mir/servlet/ServletModule.java
source/mircoders/entity/EntityContent.java
source/mircoders/module/ModuleContent.java
source/mircoders/producer/Producer.java
source/mircoders/producer/ProducerContent.java
source/mircoders/producer/ProducerList.java
source/mircoders/servlet/ServletModuleBreaking.java
source/mircoders/servlet/ServletModuleComment.java
source/mircoders/servlet/ServletModuleContent.java
source/mircoders/servlet/ServletModuleImages.java
source/mircoders/servlet/ServletModuleMessage.java
source/mircoders/storage/DatabaseContentToMedia.java
templates-dist/de/content.template
templates-dist/de/start_admin.template
templates-dist/en/content.template
templates-dist/producer/content.template

index d26f900..b15c31e 100755 (executable)
--- 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
index 88183f4..3778913 100755 (executable)
@@ -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)
                     + "\"></head><body>going " + target + "</body></html>";
           }
-          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());
     }
   }
 
index 9219855..cf4854e 100755 (executable)
@@ -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) {
index 70ec150..1a61330 100755 (executable)
@@ -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);
 
                }
index 67a6a82..a52e212 100755 (executable)
@@ -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
+}
index 0ac4a6c..d276b78 100755 (executable)
@@ -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);
   }
 
   /**
index e08494e..693afd8 100755 (executable)
@@ -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");
+               }
        }
 
        /**
index b71dc56..fd0dd25 100755 (executable)
@@ -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);
index e5df003..74c30bb 100755 (executable)
@@ -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();
 
index 4581b4f..9651787 100755 (executable)
@@ -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());
 
index af8bc7d..f13b775 100755 (executable)
@@ -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
+}
index d8015dc..83638ed 100755 (executable)
@@ -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());}
index 319ba10..3f9c1a6 100755 (executable)
@@ -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());}
index 6797d15..9d54349 100755 (executable)
@@ -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);
       }
 
 
index 0f06380..834dd46 100755 (executable)
@@ -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());}
index 512e391..30ba6b6 100755 (executable)
@@ -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());}
index 9a47575..e154fcb 100755 (executable)
@@ -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;
+  }
 
 }
index 760c048..31631b5 100755 (executable)
@@ -217,17 +217,17 @@ p {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt}
 </tr>
 
 <tr><td bgcolor="Pink" colspan="5">Attachments</td></tr>
-<!-- image stuff -->
-<if images[to_media] && images[to_media]["is_published"]=="1">
+<!-- image stuff --> 
+<list to_media as m>
 <tr>
        <td align=right valign=top bgcolor="#aaaaaa">
                <B><font color="#ffffff">Bilder:</B><br></td>
        <td colspan="4" align="left" valign="top">
-               <a href="${actionRoot}?module=Images&do=edit&id=${images[to_media]["id"]}"><img src="${actionRoot}?module=Images&do=showicon&id=${images[to_media]["id"]}" alt="edit image" border="0"></a>
-               <a href="${actionRoot}?module=Content&do=dettach&cid=${id}">entfernen</a>
+               <a href="${actionRoot}?module=Images&do=edit&id=${m["id"]}"><img src="${actionRoot}?module=Images&do=showicon&id=${m["id"]}" alt="edit image" border="0"></a>
+               <a href="${actionRoot}?module=Content&do=dettach&cid=${id}&mid=${m["id"]}">entfernen</a>
        </td>
 </tr>
-<else>
+</list>
 <tr>
        <td align=right valign=top bgcolor="#aaaaaa">
                <B><font color="#ffffff">Medien:</B><br></td>
@@ -235,8 +235,6 @@ p {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt}
                <a href="${actionRoot}?module=Images&do=list&cid=${id}">bild hinzuf&uuml;gen</a>
        </td>
 </tr>
-</if>
-
 </table>
 </form>
 <include "foot.template">
index aea62da..25eff83 100755 (executable)
@@ -15,7 +15,7 @@
                <b>OPENPOSTINGS</b></font>
 
         <p>
-               <a href="${actionRoot}?module=Content&do=listop&order=webdb_create+desc">
+               <a href="${actionRoot}${session}?module=Content&do=listop&order=webdb_create+desc">
                <img src="${docRoot}/img/pointgris.gif" border=0>bearbeiten</a>
 
                <p>
index 2a66f3b..50f6fb2 100755 (executable)
@@ -218,24 +218,23 @@ p {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt}
 \r
 <tr><td bgcolor="Pink" colspan="5">Attachments</td></tr>\r
 <!-- image stuff -->\r
-<if images[to_media] && images[to_media]["is_published"]=="1">\r
-<tr>\r
-       <td align=right valign=top bgcolor="#aaaaaa">\r
-               <B><font color="#ffffff">Bilder:</B><br></td>\r
-       <td colspan="4" align="left" valign="top">\r
-               <a href="${actionRoot}?module=Images&do=edit&id=${images[to_media]["id"]}"><img src="${actionRoot}?module=Images&do=showicon&id=${images[to_media]["id"]}" alt="edit image" border="0"></a>\r
-               <a href="${actionRoot}?module=Content&do=dettach&cid=${id}">entfernen</a>\r
-       </td>\r
-</tr>\r
-<else>\r
-<tr>\r
-       <td align=right valign=top bgcolor="#aaaaaa">\r
-               <B><font color="#ffffff">media:</B><br></td>\r
-       <td colspan="4" align="left" valign="top">\r
-               <a href="${actionRoot}?module=Images&do=list&cid=${id}">add picture</a>\r
-       </td>\r
-</tr>\r
-</if>\r
+<list to_media as m>
+<tr>
+       <td align=right valign=top bgcolor="#aaaaaa">
+               <B><font color="#ffffff">Images:</B><br></td>
+       <td colspan="4" align="left" valign="top">
+               <a href="${actionRoot}?module=Images&do=edit&id=${m["id"]}"><img src="${actionRoot}?module=Images&do=showicon&id=${m["id"]}" alt="edit image" border="0"></a>
+               <a href="${actionRoot}?module=Content&do=dettach&cid=${id}&mid=${m["id"]}">delete</a>
+       </td>
+</tr>
+</list>
+<tr>
+       <td align=right valign=top bgcolor="#aaaaaa">
+               <B><font color="#ffffff">Medien:</B><br></td>
+       <td colspan="4" align="left" valign="top">
+               <a href="${actionRoot}?module=Images&do=list&cid=${id}">add image</a>
+       </td>
+</tr>
 \r
 </table>\r
 </form>\r
index 8ea2280..664facf 100755 (executable)
                           <p><font size="+1">${title}</font></p>
                           
                        
-               <p><font size="-1"><b>${description}</b></font></p>\r
-                               <if images[to_media]&&images[to_media]["is_published"]=="1">\r
-                               <img src="${imageHost}${images[to_media]["id"]}.jpg" width="${images[to_media]["img_width"]}" height="${images[to_media]["img_height"]}" alt="${images[to_media]["description"]}"><br>\r
-                               </if>\r
+               <p><font size="-1"><b>${description}</b></font></p>
+                               <list to_media as m>\r
+                               <if m&&m["is_published"]=="1">\r
+                               <img src="${imageHost}${m["id"]}.jpg" width="${m["img_width"]}" height="${m["img_height"]}" alt="${m["description"]}"><br>\r
+                               </if>
+                               </list>\r
                                \r
                                <p><font size="-1">\r
                                ${content_data}\r