Added support for selection of topic/theme directly by open posters.
authormh <mh>
Thu, 20 Sep 2001 17:51:54 +0000 (17:51 +0000)
committermh <mh>
Thu, 20 Sep 2001 17:51:54 +0000 (17:51 +0000)
Note: you must update the posting.template from template-dist for this to work..
(en/open/posting.template and de/open/posting.template.)

source/mir/misc/WebdbMultipartRequest.java
source/mircoders/servlet/ServletModuleOpenIndy.java
templates-dist/de/open/posting.template
templates-dist/en/open/posting.template

index 8e61acd..6fca055 100755 (executable)
@@ -19,7 +19,7 @@ import com.oreilly.servlet.*;
 public class WebdbMultipartRequest
 {
   HttpServletRequest    req=null;
-  HashMap               parameters = new HashMap();
+  Hashtable             parameters = new Hashtable();
   MultipartParser       mp=null;
   public static ArrayList requestList;
 
@@ -32,10 +32,64 @@ public class WebdbMultipartRequest
   }
 
 
+  /**
+   * The following comment and some code was adapted from the Oreilley cos.jar 
+   * package. -mh 2001.09.20
+   *
+   * Returns all the parameters as a HashMap of Strings, any parameter 
+   * that sent without a value will be null.  A value 
+   * is guaranteed to be in its normal, decoded form.  If A parameter 
+   * has multiple values, only the last one is returned (for backward 
+   * compatibility).  For parameters with multiple values, it's possible
+   * the last "value" may be null.
+   *
+   * @return A HashMap of String representations of the  parameter values.
+   */
   public HashMap getParameters(){
-    return parameters;
+    HashMap pHash = new HashMap();
+    String value = new String();
+
+    Enumeration Keys = parameters.keys();
+    while(Keys.hasMoreElements()) {
+      String KeyNm = (String)Keys.nextElement();
+      Vector values = (Vector)parameters.get(KeyNm);
+      if (values == null || values.size() == 0) {
+        value = null;
+      } else {
+        value = (String)values.elementAt(values.size() - 1);
+      } //endif
+      pHash.put(KeyNm, value);
+    } // end while
+    return pHash;
   }
 
+  /**
+   * The following code and comment stolen from oreilley cos.jar.
+   * -mh. 2001.09.20
+   *
+   * Returns the values of the named parameter as a String array, or null if 
+   * the parameter was not sent.  The array has one entry for each parameter 
+   * field sent.  If any field was sent without a value that entry is stored 
+   * in the array as a null.  The values are guaranteed to be in their 
+   * normal, decoded form.  A single value is returned as a one-element array.
+   *
+   * @param name the parameter name.
+   * @return the parameter values.
+   */
+  public String[] getParameterValues(String name) {
+    try {
+      Vector values = (Vector)parameters.get(name);
+      if (values == null || values.size() == 0) {
+        return null;
+      }
+      String[] valuesArray = new String[values.size()];
+      values.copyInto(valuesArray);
+      return valuesArray;
+    }
+    catch (Exception e) {
+      return null;
+    }
+  }
 
   private void _evaluateRequest() throws IOException{
 
@@ -47,7 +101,12 @@ public class WebdbMultipartRequest
         // It's a parameter part, add it to the vector of values
         ParamPart paramPart = (ParamPart) part;
         String value = paramPart.getStringValue();
-        parameters.put(name,value);
+        Vector existingValues = (Vector)parameters.get(name);
+        if (existingValues == null) {
+          existingValues = new Vector();
+          parameters.put(name, existingValues);
+        }
+        existingValues.addElement(value);
       }
       else if (part.isFile()) {
         // nur das erste uploadfile beruecksichtigen
index cc4e926..4d0052e 100755 (executable)
@@ -37,6 +37,7 @@ public class ServletModuleOpenIndy extends ServletModule
   private String          postingFormTemplate, postingFormDoneTemplate;
   private ModuleContent   contentModule;
   private ModuleImages    imageModule;
+  private ModuleTopics         themenModule;
   private String          directOp ="yes";
 
   // Singelton / Kontruktor
@@ -53,6 +54,7 @@ public class ServletModuleOpenIndy extends ServletModule
       directOp = MirConfig.getProp("DirectOpenposting").toLowerCase();
       mainModule = new ModuleComment(DatabaseComment.getInstance());
       contentModule = new ModuleContent(DatabaseContent.getInstance());
+      themenModule = new ModuleTopics(DatabaseTopics.getInstance());
       imageModule = new ModuleImages(DatabaseImages.getInstance());
       defaultAction="addposting";
     }
@@ -137,6 +139,7 @@ public class ServletModuleOpenIndy extends ServletModule
     }
     mergeData.put("medianum",numOfMedia);
     mergeData.put("mediafields",mediaFields);
+    mergeData.put("themenPopupData", themenModule.getTopicsAsSimpleList());
     
     
     /** @todo popups missing */
@@ -178,7 +181,17 @@ public class ServletModuleOpenIndy extends ServletModule
 
       // inserting  content into database
       String cid = contentModule.add(withValues);
-      
+
+      String[] to_topicsArr = mp.getParameterValues("to_topic"); 
+      if (to_topicsArr != null && to_topicsArr.length > 0) {
+        try{
+          DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr);
+          theLog.printError("setting content_x_topic success");
+        } catch (Exception e) {
+          theLog.printError("setting content_x_topic failed");
+        } //end try
+      } //end if
+        
       // if op contains uploaddata
       String mediaId=null;
       int i=1;
@@ -222,9 +235,9 @@ public class ServletModuleOpenIndy extends ServletModule
               // inserting content and media id in table content_x_media
               try{
                 DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
-                theLog.printError("setting content_x_topic success");
+                theLog.printError("setting content_x_media success");
               } catch (Exception e) {
-                theLog.printError("setting content_x_topic failed");
+                theLog.printError("setting content_x_media failed");
               }
               
               // producing new page
@@ -254,7 +267,8 @@ public class ServletModuleOpenIndy extends ServletModule
     }
     catch (IOException e) { throw new ServletModuleException("IOException: "+ e.toString());}
     catch (StorageObjectException e) { throw new ServletModuleException("StorageObjectException" + e.toString());}
-    catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.toString());}
+    //catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.toString());}
+    catch (ModuleException e) { throw new ServletModuleException("ModuleException");}
 
     deliver(req, res, mergeData, postingFormDoneTemplate);
   }
index 3b44d53..b61959c 100755 (executable)
                        <input type="text" name="title" size="45" maxlength="45" value=""> <font size="-1" color="white"><br>(muss ausgef&uuml;llt werden)</font>
                </td>
        </tr>
+    <tr>
+        <td valign="top">
+            <b>Thema</b> Von Deinem Beitrag:
+        </td>
+       <td colspan="2">
+       <select name="to_topic" size="3" multiple>
+       <list themenPopupData as t>
+       <option value="${t.key}" <list to_topic as to><if (t.key == to)>selected</if></list>>${t.value}</option>            
+       </list>
+       </select>
+       <font size="-1">(<i>optional</i>)</font>
+       </td>
+    </tr>
        <tr>
                <td valign="top">
                        <b>AutorIn</b> des Beitrags:
index 3b44d53..b61959c 100755 (executable)
                        <input type="text" name="title" size="45" maxlength="45" value=""> <font size="-1" color="white"><br>(muss ausgef&uuml;llt werden)</font>
                </td>
        </tr>
+    <tr>
+        <td valign="top">
+            <b>Thema</b> Von Deinem Beitrag:
+        </td>
+       <td colspan="2">
+       <select name="to_topic" size="3" multiple>
+       <list themenPopupData as t>
+       <option value="${t.key}" <list to_topic as to><if (t.key == to)>selected</if></list>>${t.value}</option>            
+       </list>
+       </select>
+       <font size="-1">(<i>optional</i>)</font>
+       </td>
+    </tr>
        <tr>
                <td valign="top">
                        <b>AutorIn</b> des Beitrags: