no message
authorfh <fh>
Thu, 4 Oct 2001 12:06:49 +0000 (12:06 +0000)
committerfh <fh>
Thu, 4 Oct 2001 12:06:49 +0000 (12:06 +0000)
source/mircoders/servlet/ServletModuleLinksImcs.java
source/mircoders/storage/DatabaseLinksImcs.java
templates-dist/de/linksimcs.template
templates-dist/de/linksimcslist.template

index 6f89bfc..9ea67a9 100755 (executable)
@@ -13,7 +13,7 @@ import mir.module.*;
 import mir.misc.*;
 import mir.entity.*;
 import mir.storage.*;
-import  mir.servlet.ServletModuleException;
+import mir.servlet.ServletModuleException;
 
 import mircoders.entity.*;
 import mircoders.storage.*;
@@ -56,7 +56,7 @@ public class ServletModuleLinksImcs extends ServletModule
 
       theList = mainModule.getByWhereClause("to_parent_id=NULL", offset);
       modelRoot.put("new", "1");
-      modelRoot.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList));
+      modelRoot.put("imcsparentlist",HTMLTemplateProcessor.makeSimpleList(theList));
 
       if (theList == null || theList.getCount() == 0 || theList.getCount()>1){
         HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateObjektString, modelRoot, res.getWriter());
@@ -74,8 +74,80 @@ public class ServletModuleLinksImcs extends ServletModule
     } catch(StorageObjectException e) {
       throw new ServletModuleException(e.toString());
     }
+  }
+
+  public void list(HttpServletRequest req, HttpServletResponse res)
+    throws ServletModuleException {
+    try {
+
+      theLog.printDebugInfo("-- links_imcs_list: list");
+      EntityList   theList;
+      SimpleHash modelRoot = new SimpleHash();
+      String       offsetParam = req.getParameter("offset");
+      int          offset=0;
+      PrintWriter out = res.getWriter();
 
+      // hier offsetcode bearbeiten
+      if (offsetParam != null && !offsetParam.equals("")){
+        offset = Integer.parseInt(offsetParam);
+      }
+      if (req.getParameter("next") != null){
+          offset=Integer.parseInt(req.getParameter("nextoffset"));
+      } else {
+          if (req.getParameter("prev") != null){
+            offset = Integer.parseInt(req.getParameter("prevoffset"));
+          }
+      }
+      theList = mainModule.getByWhereClause(null, offset);
+      modelRoot.put("imcsparentlist",HTMLTemplateProcessor.makeSimpleList(theList));
+      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, modelRoot, res.getWriter());
 
+      } catch (Exception e) {
+      throw new ServletModuleException(e.toString());
+    }
   }
+
+  public void edit(HttpServletRequest req, HttpServletResponse res)
+    throws ServletModuleException {
+    try {
+      SimpleHash modelRoot = new SimpleHash();
+      EntityList   theList;
+      int offset = 0;
+      String idParam = req.getParameter("id");
+
+      theList = mainModule.getByWhereClause("to_parent_id=NULL", offset);
+
+      modelRoot.put("imcsparentlist",HTMLTemplateProcessor.makeSimpleList(theList));
+      deliver(req, res, mainModule.getById(idParam), modelRoot, templateObjektString);
+
+    } catch(ModuleException e) {
+      throw new ServletModuleException(e.toString());
+    } catch(StorageObjectException e) {
+      throw new ServletModuleException(e.toString());
+    }
+  }
+
+  public void update(HttpServletRequest req, HttpServletResponse res)
+    throws ServletModuleException {
+    try {
+      String idParam = req.getParameter("id");
+      HashMap withValues = getIntersectingValues(req, mainModule.getStorageObject());
+      String id = mainModule.set(withValues);
+      //theLog.printInfo("Showing Entity with id: " + id);
+      //edit(req,res);
+      String whereParam = req.getParameter("where");
+      String orderParam = req.getParameter("order");
+      if ((whereParam!=null && !whereParam.equals("")) || (orderParam!=null && !orderParam.equals(""))){
+        //theLog.printDebugInfo("update to list");
+        list(req,res);
+      } else {
+        edit(req, res);
+      }
+      //list(req,res);
+    } catch (Exception e) {
+      throw new ServletModuleException(e.toString());
+    }
+  }
+
 }
 
index c330296..63f6c68 100755 (executable)
@@ -1,9 +1,3 @@
-/*
- * put your module comment here
- * formatted with JxBeauty (c) johann.langhofer@nextra.at
- */
-
-
 package  mircoders.storage;
 
 import  java.lang.*;
@@ -54,6 +48,156 @@ public class DatabaseLinksImcs extends Database
     }
   }
 
+  public String insert (Entity theEntity) throws StorageObjectException {
+               String returnId = "0";
+               Connection con = null;
+               PreparedStatement pstmt = null;
+               //cache
+               invalidatePopupCache();
+               try {
+                       HashMap theEntityValues = theEntity.getValues();
+                       ArrayList streamedInput = theEntity.streamedInput();
+                       StringBuffer f = new StringBuffer();
+                       StringBuffer v = new StringBuffer();
+                       String aField, aValue;
+                       boolean firstField = true;
+                       // make sql-string
+                       for (int i = 0; i < getFields().size(); i++) {
+                               aField = (String)getFields().get(i);
+                               if (!aField.equals(thePKeyName)) {
+                                       aValue = null;
+                                       // sonderfaelle
+                                       if (aField.equals("webdb_create")) {
+                                               aValue = "NOW()";
+                                       }
+                                       else {
+                                               if (streamedInput != null && streamedInput.contains(aField)) {
+                                                       aValue = "?";
+                                               }
+                                               else {
+                                                       if (theEntityValues.containsKey(aField)) {
+                if (aField.equals("to_parent_id")) {
+                  aValue = StringUtil.quote((String)theEntityValues.get(aField));
+                } else {
+                                                                 aValue = "'" + StringUtil.quote((String)theEntityValues.get(aField)) + "'";
+                }
+                                                       }
+                                               }
+                                       }
+                                       // wenn Wert gegeben, dann einbauen
+                                       if (aValue != null) {
+                                               if (firstField == false) {
+                                                       f.append(",");
+                                                       v.append(",");
+                                               }
+                                               else {
+                                                       firstField = false;
+                                               }
+                                               f.append(aField);
+                                               v.append(aValue);
+                                       }
+                               }
+                       }         // end for
+                       // insert into db
+                       StringBuffer sqlBuf = new StringBuffer("insert into ").append(theTable).append("(").append(f).append(") values (").append(v).append(")");
+                       String sql = sqlBuf.toString();
+                       theLog.printInfo("INSERT: " + sql);
+                       con = getPooledCon();
+                       con.setAutoCommit(false);
+                       pstmt = con.prepareStatement(sql);
+                       if (streamedInput != null) {
+                               for (int i = 0; i < streamedInput.size(); i++) {
+                                       String inputString = (String)theEntityValues.get(streamedInput.get(i));
+                                       pstmt.setBytes(i + 1, inputString.getBytes());
+                               }
+                       }
+                       pstmt.execute();
+                       pstmt = con.prepareStatement(theAdaptor.getLastInsertSQL((Database)myselfDatabase));
+                       ResultSet rs = pstmt.executeQuery();
+                       rs.next();
+                       returnId = rs.getString(1);
+                       theEntity.setId(returnId);
+               } catch (SQLException sqe) {
+                       throwSQLException(sqe, "insert");
+               } finally {
+                       try {
+                               con.setAutoCommit(true);
+                       } catch (Exception e) {
+                               ;
+                       }
+                       freeConnection(con, pstmt);
+               }
+               return  returnId;
+       }
+
+  public void update (Entity theEntity) throws StorageObjectException {
+    Connection con = null;
+    PreparedStatement pstmt = null;
+    ArrayList streamedInput = theEntity.streamedInput();
+    HashMap theEntityValues = theEntity.getValues();
+    String id = theEntity.getId();
+    String aField;
+    StringBuffer fv = new StringBuffer();
+    boolean firstField = true;
+    //cache
+    invalidatePopupCache();
+    // build sql statement
+    for (int i = 0; i < getFields().size(); i++) {
+      aField = (String)metadataFields.get(i);
+      // only normal cases
+      if (!(aField.equals(thePKeyName) || aField.equals("webdb_create") ||
+          aField.equals("webdb_lastchange") || (streamedInput != null && streamedInput.contains(aField)))) {
+        if (theEntityValues.containsKey(aField)) {
+          if (firstField == false) {
+            fv.append(", ");
+          }
+          else {
+            firstField = false;
+          }
+          if (aField.equals("to_parent_id")) {
+            fv.append(aField).append("=").append(StringUtil.quote((String)theEntityValues.get(aField)));
+          } else {
+            fv.append(aField).append("='").append(StringUtil.quote((String)theEntityValues.get(aField))).append("'");
+          }
+        }
+      }
+    }
+    StringBuffer sql = new StringBuffer("update ").append(theTable).append(" set ").append(fv);
+    // exceptions
+    if (metadataFields.contains("webdb_lastchange")) {
+      sql.append(",webdb_lastchange=NOW()");
+    }
+    if (streamedInput != null) {
+      for (int i = 0; i < streamedInput.size(); i++) {
+        sql.append(",").append(streamedInput.get(i)).append("=?");
+      }
+    }
+    sql.append(" where id=").append(id);
+    theLog.printInfo("UPDATE: " + sql);
+    // execute sql
+    try {
+      con = getPooledCon();
+      con.setAutoCommit(false);
+      pstmt = con.prepareStatement(sql.toString());
+      if (streamedInput != null) {
+        for (int i = 0; i < streamedInput.size(); i++) {
+          String inputString = (String)theEntityValues.get(streamedInput.get(i));
+          pstmt.setBytes(i + 1, inputString.getBytes());
+        }
+      }
+      pstmt.executeUpdate();
+    } catch (SQLException sqe) {
+      throwSQLException(sqe, "update");
+    } finally {
+      try {
+        con.setAutoCommit(true);
+      } catch (Exception e) {
+        ;
+      }
+      freeConnection(con, pstmt);
+    }
+  }
+
   /**
    * put your documentation comment here
    * @return
index 30a3a6e..233820e 100755 (executable)
@@ -9,7 +9,7 @@
 <include "head.template">
 <form action="${actionRoot}" method="post">
        <input type=hidden name=module value=LinksImcs>
-       <input type="hidden" name="id" value="${id}">
+       <input type="hidden" name="id" value=<if entity>"${entity.id}"<else>"${id}"</if>>
        <if new><input type="hidden" name="do" value="insert">
        <else><input type="hidden" name="do" value="update"></if>
 <table border="0">
     <td align="right" bgcolor="#006600"><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
                <B>Name:</B></font></td>
     <td>
-      <input type="text" size="40" name="title" value="${title}">
+       <input type="text" size="40" name="title" value=<if entity>"${entity.title}"<else>"${title}"</if>>
     </td>
   </tr>
   <tr>
     <td align="right" bgcolor="#006600"><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
                <B>Kontinent:</B></font></td>
     <td>
-               <if contentlist>
+               <if imcsparentlist>
        <select name="to_parent_id" size="1">
-                       <option value=""> Neuen Oberbegriff anlegen
-                       <list contentlist as entry>
-                       <option value="${entry.id}"> ${entry.title}
-                       </list>
+                       <option value=NULL> Neuen Oberbegriff anlegen
+                       <list imcsparentlist as entry><option value="${entry.id}"> ${entry.title}</list>
                </select>
                </if>
     </td>
   <tr>
     <td align="right" bgcolor="#006600"><font color="#ffffff"><B>URL:</B></font></td>
     <td>
-      <input type="text" size="40" name="url" value="${url}">
+      <input type="text" size="40" name="url" value=<if entity>"${entity.url}"<else>"${url}"</if>>
     </td>
   </tr>
   <tr>
     <td align="right" bgcolor="#006600"><font color="#ffffff"><B>Sortierkriteríum:</B></font></td>
     <td>
       <select name="sortpriority" size="1">
-               <option value="1"> 1 
-               <option value="2"> 2 
-               <option value="3"> 3
+               <option value="1"<if entity.sortpriority == 1> selected</if>> 1 
+               <option value="2"<if entity.sortpriority == 2> selected</if>> 2 
+               <option value="3"<if entity.sortpriority == 3> selected</if>> 3
                </select>
     </td>
   </tr>
@@ -54,8 +52,8 @@
     <td align="right" bgcolor="#006600"><font color="#ffffff"><B>Sprache:</B></font></td>
     <td>
       <select name="to_language" size="1">
-               <option value="1"> deutsch 
-               <option value="2"> englisch 
+               <option value="1"<if entity.to_language == 1> selected</if>> deutsch 
+               <option value="2"<if entity.to_language == 2> selected</if>> englisch 
          </select>
     </td>
   </tr>
index 3c7b0ec..ae0d12b 100755 (executable)
@@ -4,12 +4,14 @@
 </head>
 <body bgcolor="#FFFFFF">
 <include "head.template">
-<if contentlist>
+<if imcsparentlist>
 <table border="0">
   <tr bgcolor="#006600">
     <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
                <b>Name</b></font></td>
     <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
+               <b>Parent</b></font></td>
+       <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
                <b>Url</b></font></td>
        <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
                <b>Sortierpriorit&auml;t</b></font></td>
        <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
                <b>&nbsp;</b></font></td>
   </tr>
-  <list contentlist as entry>
+  <list imcsparentlist as entry>
   <tr <if grey=="1"><assign grey="0">bgcolor="#dddddd" <else><assign grey="1"> </if>>
        <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">${entry.title}&nbsp;</font></td>
-       <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">${entry.url}</font></td>
+       <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">${entry.to_parent_id}</font></td>
+       <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">${entry.url}</font></td>
        <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">${entry.sortpriority}</font></td>
        <td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">${entry.to_language}</font></td>
        <td><font size="1">&nbsp;<a href="${actionRoot}?module=LinksImcs&do=delete&id=${entry.id}">delete</a>
@@ -30,7 +33,7 @@
   </tr>
   </list>
   <tr>
-  <td colspan="5" bgcolor="#006600"><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
+  <td colspan="6" bgcolor="#006600"><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#ffffff">
        ${count} datens&auml;tze / anzeige von ${from} bis ${to}</font></td>
   <td>&nbsp;</td>
   </tr>