misc. maintenance
authorzapata <zapata>
Mon, 2 Dec 2002 12:33:22 +0000 (12:33 +0000)
committerzapata <zapata>
Mon, 2 Dec 2002 12:33:22 +0000 (12:33 +0000)
12 files changed:
source/mir/entity/Entity.java
source/mir/misc/HTMLTemplateProcessor.java
source/mir/misc/StringUtil.java
source/mir/util/GeneratorHTMLFunctions.java
source/mir/util/GeneratorIntegerFunctions.java [new file with mode: 0755]
source/mir/util/GeneratorStringFunctions.java
source/mir/util/StringRoutines.java
source/mircoders/entity/EntityComment.java
source/mircoders/entity/EntityContent.java
source/mircoders/entity/EntityFeature.java
source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java
source/mircoders/servlet/ServletModuleContent.java

index 8dca5b1..c633b67 100755 (executable)
@@ -50,7 +50,7 @@ import mir.misc.*;
  * Base Class of Entities
  * Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant
  *
- * @version $Id: Entity.java,v 1.10 2002/11/04 04:35:21 mh Exp $
+ * @version $Id: Entity.java,v 1.11 2002/12/02 12:33:22 zapata Exp $
  * @author rk
  *
  */
@@ -126,7 +126,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot
    * @return String Id
    */
   public String getId () {
-    return  (String)getValue(theStorageObject.getIdName());
+    return  (String) getValue(theStorageObject.getIdName());
   }
 
   /**
@@ -156,11 +156,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot
         if (hasValueForField("webdb_lastchange"))
           returnValue=StringUtil.dateToReadableDate(getValue("webdb_lastchange"));
       }
-      else if (field.equals("webdb_create_dc"))
-      {
-        if (hasValueForField("webdb_create"))
-          returnValue=StringUtil.webdbdateToDCDate(getValue("webdb_create"));
-      }
       else
         returnValue = (String)theValuesHash.get(field);
     }
@@ -292,21 +287,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot
     throw  new StorageObjectException("Storage Object Exception in entity" +e.toString());
   }
 
-  /**
-   * Frees an instance
-   */
-  /*public void finalize () {
-    instances--;
-    Integer i = new Integer(instances);
-    System.err.println("Removing abstract entity instance: "+i.toString());
-    try {
-      super.finalize();
-    } catch (Throwable t) {
-      System.err.println(t.toString());
-    }
-  }*/
-
-
   // Now implements freemarkers TemplateHashModel
   // two methods have to be overridden:
   // 1. public boolean isEmpty() throws TemplateModelException
@@ -319,10 +299,10 @@ public class Entity implements TemplateHashModel, TemplateModelRoot
 
   public TemplateModel get(java.lang.String key) throws TemplateModelException
   {
-               return new SimpleScalar(getValue(key));
+                return new SimpleScalar(getValue(key));
   }
-       
-       public void put(java.lang.String key, TemplateModel model)
+
+        public void put(java.lang.String key, TemplateModel model)
   {
     // putting should only take place via setValue and is limited to the
     // database fields associated with the entity. no additional freemarker
index b86fd25..7b4cef9 100755 (executable)
@@ -158,22 +158,6 @@ public final class HTMLTemplateProcessor {
     }
 
     /**
-     * Wandelt HashMap <code>mergeData</code> in freemarker-Struktur und mischt diese mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param mergeData - a HashMap with mergeData to be converted in SimpleHash
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(HttpServletResponse res, String templateFilename,
-                               HashMap mergeData, PrintWriter out, Locale locale)
-            throws HTMLParseException {
-        process(res, templateFilename, makeSimpleHash(mergeData), out, locale);
-    }
-
-    /**
      * Gibt Template <code>templateFilename</code> an den PrintWriter
      * <code>out</code>
      *
@@ -254,6 +238,8 @@ public final class HTMLTemplateProcessor {
           utilityHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace());
           utilityHash.put("encodeURI", FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.encodeURIGeneratorFunction()));
           utilityHash.put("encodeHTML", FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction()));
+          utilityHash.put("isOdd", FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.isOddFunction()));
+          utilityHash.put("increment", FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.incrementFunction()));
         }
         catch (Throwable t) {
           throw new HTMLParseException(t.getMessage());
@@ -321,24 +307,6 @@ public final class HTMLTemplateProcessor {
     }
 
     /**
-     *  Konvertiert ein Entity in ein freemarker.template.SimpleHash-Modell
-     *  @param entity ist die Entity
-     *  @return SimpleHash mit den entsprechenden freemarker Daten
-     *
-     *  @deprecated This method is deprecated and will be deleted in the next
-     *  release. Entity interfaces freemarker.template.TemplateHashModel now
-     *  and can be used in the same way as SimpleHash. It is not necessary any
-     *  more to make a SimpleHash from an Entity
-     */
-    public static SimpleHash makeSimpleHash(Entity entity) {
-        if (entity != null) {
-            theLog.printWarning("## using deprecated makeSimpleHash(entity) - a waste of resources");
-            return makeSimpleHash(entity.getValues());
-        } else
-            return null;
-    }
-
-    /**
      *  Konvertiert ein Hashtable mit den keys und values als String
      *  in ein freemarker.template.SimpleHash-Modell
      *  @param mergeData der HashMap mit den String / String Daten
index 5203fe9..ac55361 100755 (executable)
@@ -40,35 +40,35 @@ import  gnu.regexp.*;
 /**
  * Statische Hilfsmethoden zur Stringbehandlung
  *
- * @version $Id: StringUtil.java,v 1.28 2002/11/27 08:21:02 mh Exp $
+ * @version $Id: StringUtil.java,v 1.29 2002/12/02 12:33:23 zapata Exp $
  * @author mir-coders group
  *
  */
 public final class StringUtil {
 
-        private static RE   re_newline2br, re_brbr2p, re_mail, re_url, re_tags;
+  private static RE   re_newline2br, re_brbr2p, re_mail, re_url, re_tags;
 
-        private StringUtil() { }  // this avoids contruction
+  private StringUtil() { }  // this avoids contruction
 
-        static {
-                try {
-                        //precompile regex
-                        re_newline2br = new RE("(\r?\n){1}");
-                        re_brbr2p     = new RE("(<br>\r?\n<br>){1,}");
-                        re_mail       = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)");
-                        re_url        = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])");
-                        re_tags       = new RE("<[^>]*>",RE.REG_ICASE);
-                }
-                catch (REException e){
-                        System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());
-                }
-        }
+  static {
+    try {
+      //precompile regex
+      re_newline2br = new RE("(\r?\n){1}");
+      re_brbr2p     = new RE("(<br>\r?\n<br>){1,}");
+      re_mail       = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)");
+      re_url        = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])");
+      re_tags       = new RE("<[^>]*>",RE.REG_ICASE);
+    }
+    catch (REException e){
+      System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());
+    }
+  }
 
   /**
    * Formats a number with the specified minimum and maximum number of digits.
    **/
   public static synchronized String zeroPaddingNumber(long value, int minDigits,
-                                                      int maxDigits)
+      int maxDigits)
   {
     NumberFormat numberFormat = NumberFormat.getInstance();
     numberFormat.setMinimumIntegerDigits(minDigits);
@@ -76,828 +76,741 @@ public final class StringUtil {
     return numberFormat.format(value);
   }
 
-        /**
-         * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd)
-         * @param theDate
-         * @return 8-ziffriger String (yyyymmdd)
-         */
-
-        public static final String date2webdbDate (GregorianCalendar theDate) {
-                StringBuffer webdbDate = new StringBuffer();
-                webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
-                webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
-                webdbDate.append(pad2(theDate.get(Calendar.DATE)));
-                return  webdbDate.toString();
-        }
-
-        /**
-         * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)
-         * @param theDate
-         * @return 12-ziffriger String (yyyymmdd)
-         */
-
-        public static final String date2webdbDateTime (GregorianCalendar theDate) {
-                StringBuffer webdbDate = new StringBuffer();
-                webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
-                webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
-                webdbDate.append(pad2(theDate.get(Calendar.DATE)));
-                webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
-                webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
-                return  webdbDate.toString();
-        }
-
-        /**
-         * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)
-         * @param theDate
-         * @return w3approved datetime
-         */
-
-        public static final String date2w3DateTime (GregorianCalendar theDate) {
-                StringBuffer webdbDate = new StringBuffer();
-                webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
-                webdbDate.append("-");
-                webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
-                webdbDate.append("-");
-                webdbDate.append(pad2(theDate.get(Calendar.DATE)));
-                webdbDate.append("T");
-                webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
-                webdbDate.append(":");
-                webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
-                webdbDate.append(":");
-                webdbDate.append(pad2(theDate.get(Calendar.SECOND)));
-                //assumes you are an hour-multiple away from UTC....
-                int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));
-                if (offset < 0){
-                webdbDate.append("-");
-                }
-                else{
-                webdbDate.append("+");
-                }
-                webdbDate.append(pad2(Math.abs(offset)));
-                webdbDate.append(":00");
-                return  webdbDate.toString();
-        }
-
-        /**
-         * wandelt Calendar in dd.mm.yyyy / hh.mm um
-         * @param theDate
-         * @return String mit (dd.mm.yyyy / hh.mm um)
-         */
-        public static String date2readableDateTime (GregorianCalendar theDate) {
-                String readable = "";
-                int hour;
-                readable += pad2(theDate.get(Calendar.DATE));
-                readable += "." + pad2(theDate.get(Calendar.MONTH) + 1);
-                readable += "." + String.valueOf(theDate.get(Calendar.YEAR));
-                hour = theDate.get(Calendar.HOUR);
-                if (theDate.get(Calendar.AM_PM) == Calendar.PM)
-                        hour += 12;
-                readable += " / " + pad2(hour);
-                readable += ":" + pad2(theDate.get(Calendar.MINUTE));
-                return  readable;
-        }
-
-        /**
-         * wandelt eine Datum in einen 8-buchstabigen String, der durch <code>/</code>
-         * getrennt ist.
-         *
-         * @param webdbDate
-         * @return String mit <code>/yyyy/mm/dd</code>
-         */
-        public static final String webdbDate2path (String webdbDate) {
-                StringBuffer path = new StringBuffer();
-                path.append("/").append(webdbDate.substring(0, 4));
-                path.append("/").append(webdbDate.substring(4, 6));
-                path.append("/");
-                //who did this?
-                //path.append("/").append(webdbDate.substring(6, 8));
-                return  path.toString();
-        }
-
-        /**
-         * wandelt Calendar in dd.mm.yyyy um
-         *
-         * @param theDate
-         * @return String mit  <code>yyyy.mm.dd</code>
-         */
-        public static final String webdbDate2readableDate (String webdbDate) {
-                String date = "";
-                date += webdbDate.substring(0, 4);
-                date += "-" + webdbDate.substring(5, 7);
-                date += "-"+webdbDate.substring(8, 10);
-                return  date;
-        }
-
-
-        /**
-         * converts string from format: yyyy-mm-dd__hh:mm:ss.d
-         * to dd.mm.yyyy hh:mm
-         */
-        public static String dateToReadableDate(String date) {
-                StringBuffer returnDate = new StringBuffer();
-                if (date!=null) {
-
-                        returnDate.append(date.substring(8,10)).append('.');
-                        returnDate.append(date.substring(5,7)).append('.');
-                        returnDate.append(date.substring(0,4)).append(' ');
-                        returnDate.append(date.substring(11,16));
-                }
-                return returnDate.toString();
-        }
-
-  /**
-         * converts string from format: yyyy-mm-dd__hh:mm:ss.dddddd+TZ
-         * to yyyy-mm-ddThh:mm:ss+TZ:00 (w3 format for Dublin Core)
-         */
-        public static String webdbdateToDCDate(String date) {
-                StringBuffer returnDate = new StringBuffer();
-                if (date!=null) {
-      returnDate.append(date.substring(0,10));
-      returnDate.append("T");
-      returnDate.append(date.substring(11,19));
-      //String tzInfo=date.substring(26,29);
-      //if (tzInfo.equals("+00")){
-      //UTC gets a special code in w3 dates
-      //    returnDate.append("Z");
-      //}
-      //else{
-      //need to see what a newfoundland postgres
-      //timestamp looks like before making this robust
-      //    returnDate.append(tzInfo);
-      //    returnDate.append(":00");
-      //}
-
-                }
-                return returnDate.toString();
-        }
-
-
-        /**
-         * converts string from format: yyyy-mm-dd__hh:mm:ss.d
-         * to yyyy
-         */
-        public static String dateToYear (String date) {
-                StringBuffer returnDate = new StringBuffer();
-                if (date!=null) {
-
-                        returnDate.append(date.substring(0,4));
-                }
-                return returnDate.toString();
-        }
-
-        /**
-         * converts string from format: yyyy-mm-dd__hh:mm:ss.d
-         * to [m]m
-         */
-        public static String dateToMonth (String date) {
-                StringBuffer returnDate = new StringBuffer();
-                if (date!=null) {
-                        if (!date.substring(5,6).equalsIgnoreCase("0")) returnDate.append(date.substring(5,7));
-                        else returnDate.append(date.substring(6,7));
-                }
-                return returnDate.toString();
-        }
-
-        /**
-         * converts string from format: yyyy-mm-dd__hh:mm:ss.d
-         * to [d]d
-         */
-        public static String dateToDayOfMonth (String date) {
-                StringBuffer returnDate = new StringBuffer();
-                if (date!=null) {
-                        if (!date.substring(8,9).equalsIgnoreCase("0")) returnDate.append(date.substring(8,10));
-                        else returnDate.append(date.substring(9,10));
-                }
-                return returnDate.toString();
-        }
-
-        /**
-         * converts string from format: yyyy-mm-dd__hh:mm:ss.d
-         * to hh:mm
-         */
-        public static String dateToTime (String date) {
-                StringBuffer returnDate = new StringBuffer();
-                if (date!=null) {
-                        returnDate.append(date.substring(11,16));
-                }
-                return returnDate.toString();
-        }
-
-    /**
-     * Splits the provided CSV text into a list. stolen wholesale from
-     * from Jakarta Turbine StrinUtils.java -mh
-     *
-     * @param text      The CSV list of values to split apart.
-     * @param separator The separator character.
-     * @return          The list of values.
-     */
-    public static String[] split(String text, String separator)
+  /**
+   * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd)
+   * @param theDate
+   * @return 8-ziffriger String (yyyymmdd)
+   */
+
+  public static final String date2webdbDate (GregorianCalendar theDate) {
+    StringBuffer webdbDate = new StringBuffer();
+    webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
+    webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
+    webdbDate.append(pad2(theDate.get(Calendar.DATE)));
+    return  webdbDate.toString();
+  }
+
+  /**
+   * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)
+   * @param theDate
+   * @return 12-ziffriger String (yyyymmdd)
+   */
+
+  public static final String date2webdbDateTime (GregorianCalendar theDate) {
+    StringBuffer webdbDate = new StringBuffer();
+    webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
+    webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
+    webdbDate.append(pad2(theDate.get(Calendar.DATE)));
+    webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
+    webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
+    return  webdbDate.toString();
+  }
+
+  /**
+   * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)
+   * @param theDate
+   * @return w3approved datetime
+   */
+
+  public static final String date2w3DateTime (GregorianCalendar theDate) {
+    StringBuffer webdbDate = new StringBuffer();
+    webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
+    webdbDate.append("-");
+    webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
+    webdbDate.append("-");
+    webdbDate.append(pad2(theDate.get(Calendar.DATE)));
+    webdbDate.append("T");
+    webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
+    webdbDate.append(":");
+    webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
+    webdbDate.append(":");
+    webdbDate.append(pad2(theDate.get(Calendar.SECOND)));
+    //assumes you are an hour-multiple away from UTC....
+    int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));
+    if (offset < 0){
+      webdbDate.append("-");
+    }
+    else{
+      webdbDate.append("+");
+    }
+    webdbDate.append(pad2(Math.abs(offset)));
+    webdbDate.append(":00");
+    return  webdbDate.toString();
+  }
+
+  /**
+   * wandelt Calendar in dd.mm.yyyy / hh.mm um
+   * @param theDate
+   * @return String mit (dd.mm.yyyy / hh.mm um)
+   */
+  public static String date2readableDateTime (GregorianCalendar theDate) {
+    String readable = "";
+    int hour;
+    readable += pad2(theDate.get(Calendar.DATE));
+    readable += "." + pad2(theDate.get(Calendar.MONTH) + 1);
+    readable += "." + String.valueOf(theDate.get(Calendar.YEAR));
+    hour = theDate.get(Calendar.HOUR);
+    if (theDate.get(Calendar.AM_PM) == Calendar.PM)
+      hour += 12;
+    readable += " / " + pad2(hour);
+    readable += ":" + pad2(theDate.get(Calendar.MINUTE));
+    return  readable;
+  }
+
+  /**
+  *  deleteForbiddenTags
+  *  this method deletes all <script>, <body> and <head>-tags
+  */
+  public static final String deleteForbiddenTags(String haystack) {
+    try {
+      RE regex = new RE("<[ \t\r\n](.*?)script(.*?)/script(.*?)>",RE.REG_ICASE);
+      haystack = regex.substituteAll(haystack,"");
+      regex = new RE("<head>(.*?)</head>");
+      haystack = regex.substituteAll(haystack,"");
+      regex = new RE("<[ \t\r\n/]*body(.*?)>");
+      haystack = regex.substituteAll(haystack,"");
+      return haystack;
+    } catch(REException ex){
+      return null;
+    }
+  }
+
+  /**
+   * wandelt eine Datum in einen 8-buchstabigen String, der durch <code>/</code>
+   * getrennt ist.
+   *
+   * @param webdbDate
+   * @return String mit <code>/yyyy/mm/dd</code>
+   */
+  public static final String webdbDate2path (String webdbDate) {
+    StringBuffer path = new StringBuffer();
+    path.append("/").append(webdbDate.substring(0, 4));
+    path.append("/").append(webdbDate.substring(4, 6));
+    path.append("/");
+    //who did this?
+    //path.append("/").append(webdbDate.substring(6, 8));
+    return  path.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to dd.mm.yyyy hh:mm
+   */
+  public static String dateToReadableDate(String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+
+      returnDate.append(date.substring(8,10)).append('.');
+      returnDate.append(date.substring(5,7)).append('.');
+      returnDate.append(date.substring(0,4)).append(' ');
+      returnDate.append(date.substring(11,16));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to yyyy
+   */
+  public static String dateToYear (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+
+      returnDate.append(date.substring(0,4));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to [m]m
+   */
+  public static String dateToMonth (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+      if (!date.substring(5,6).equalsIgnoreCase("0")) returnDate.append(date.substring(5,7));
+      else returnDate.append(date.substring(6,7));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to [d]d
+   */
+  public static String dateToDayOfMonth (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+      if (!date.substring(8,9).equalsIgnoreCase("0")) returnDate.append(date.substring(8,10));
+      else returnDate.append(date.substring(9,10));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to hh:mm
+   */
+  public static String dateToTime (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+      returnDate.append(date.substring(11,16));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * Splits the provided CSV text into a list. stolen wholesale from
+   * from Jakarta Turbine StrinUtils.java -mh
+   *
+   * @param text      The CSV list of values to split apart.
+   * @param separator The separator character.
+   * @return          The list of values.
+   */
+  public static String[] split(String text, String separator)
+  {
+    StringTokenizer st = new StringTokenizer(text, separator);
+    String[] values = new String[st.countTokens()];
+    int pos = 0;
+    while (st.hasMoreTokens())
     {
-        StringTokenizer st = new StringTokenizer(text, separator);
-        String[] values = new String[st.countTokens()];
-        int pos = 0;
-        while (st.hasMoreTokens())
-        {
-            values[pos++] = st.nextToken();
-        }
-        return values;
+      values[pos++] = st.nextToken();
     }
+    return values;
+  }
 
-    /**
-     * Joins the elements of the provided array into a single string
-     * containing a list of CSV elements. Stolen wholesale from Jakarta
-     * Turbine StringUtils.java. -mh
-     *
-     * @param list      The list of values to join together.
-     * @param separator The separator character.
-     * @return          The CSV text.
-     */
-    public static String join(String[] list, String separator)
+  /**
+   * Joins the elements of the provided array into a single string
+   * containing a list of CSV elements. Stolen wholesale from Jakarta
+   * Turbine StringUtils.java. -mh
+   *
+   * @param list      The list of values to join together.
+   * @param separator The separator character.
+   * @return          The CSV text.
+   */
+  public static String join(String[] list, String separator)
+  {
+    StringBuffer csv = new StringBuffer();
+    for (int i = 0; i < list.length; i++)
     {
-        StringBuffer csv = new StringBuffer();
-        for (int i = 0; i < list.length; i++)
-        {
-            if (i > 0)
-            {
-                csv.append(separator);
-            }
-            csv.append(list[i]);
-        }
-        return csv.toString();
+      if (i > 0)
+      {
+      csv.append(separator);
+    }
+    csv.append(list[i]);
     }
+    return csv.toString();
+  }
 
 
-        /**
-         * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält
-         *
-         * @return gequoteter String
-         */
-         public static String quoteIfNecessary(String s) {
-                for (int i = 0; i < s.length(); i++)
-                        if (!(Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == '.'))
-                                return quote(s, '"');
-                return s;
-        }
-
-         /**
-         * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
-         * "gefährliche" Zeichen innerhalb des Strings
-         * Quotes special SQL-characters in <code>s</code>
-         *
-         * @return geqoteter String
-         */
-        public static String quote(String s)
-        {
-                //String s2 = quote(s, '\'');
-                //Quickhack    ÃŠÃŠ ÃŠ ÃŠ ÃŠ ÃŠ ÃŠ ÃŠ
-                //Because of '?-Bug in Postgresql-JDBC-Driver
-                StringBuffer temp = new StringBuffer();
-                for(int i=0;i<s.length();i++){
-                        if(s.charAt(i)=='\''){
-                                temp.append("&#39;");
-                        } else {
-                                temp.append(s.charAt(i));
-                        }
-                }
-                String s2 = temp.toString();
-                //end Quickhack
-
-                s2 = quote(s2, '\"');
-                return s2;
-        }
-
-        /**
-         * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
-         * "gefährliche" Zeichen innerhalb des Strings
-         *
-         * @param s String, der gequoted werden soll
-         * @param quoteChar zu quotendes Zeichen
-         * @return gequoteter String
-         */
-        public static String quote(String s, char quoteChar)
-        {
-                StringBuffer buf = new StringBuffer(s.length());
-                int pos = 0;
-                while (pos < s.length()) {
-                        int i = s.indexOf(quoteChar, pos);
-                        if (i < 0) i = s.length();
-                        buf.append(s.substring(pos, i));
-                        pos = i;
-                        if (pos < s.length()) {
-                                buf.append('\\');
-                                buf.append(quoteChar);
-                                pos++;
-                        }
-                }
-                return buf.toString();
-        }
-
-        /**
-         * replaces dangerous characters in <code>s</code>
-         *
-         */
-
-        public static String unquote(String s)
-        {
-                char quoteChar='\'';
-                StringBuffer buf = new StringBuffer(s.length());
-                int pos = 0;
-                String searchString = "\\"+quoteChar;
-                while (pos < s.length()) {
-                        int i = s.indexOf(searchString, pos);
-                        if (i < 0) i = s.length();
-                        buf.append(s.substring(pos, i));
-                        pos = i+1;
-                }
-                return buf.toString();
-        }
-
-        /**
-         * Wandelet String in byte[] um.
-         * @param s
-         * @return byte[] des String
-         */
-
-        public static byte[] stringToBytes(String s) {
-                String crlf = System.getProperty("line.separator");
-                if (!crlf.equals("\n"))
-                        s = replace(s, "\n", crlf);
-                // byte[] buf = new byte[s.length()];
-                byte[] buf = s.getBytes();
-                return buf;
-        }
-
-                /**
-         * Ersetzt in String <code>s</code> das <code>pattern</code> durch <code>substitute</code>
-         * @param s
-         * @param pattern
-         * @param substitute
-         * @return String mit den Ersetzungen
-         */
-        public static String replace(String s, String pattern, String substitute) {
-                int i = 0, pLen = pattern.length(), sLen = substitute.length();
-                StringBuffer buf = new StringBuffer(s.length());
-                while (true) {
-                        int j = s.indexOf(pattern, i);
-                        if (j < 0) {
-                                buf.append(s.substring(i));
-                                break;
-                        } else {
-                                buf.append(s.substring(i, j));
-                                buf.append(substitute);
-                                i = j+pLen;
-                        }
-                }
-                return buf.toString();
-        }
-
-        /**
-         * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
-         * @param s
-         * @param pattern
-         * @param substitute
-         * @return String mit den Ersetzungen
-         */
-        public static String regexpReplace(String haystack, String pattern, String substitute) {
-                try {
-                        RE regex = new RE(pattern);
-                        return regex.substituteAll(haystack,substitute);
-                } catch(REException ex){
-                        return null;
-                }
-        }
-
-
-
-
-        /**
-         * Fügt einen Separator an den Pfad an
-         * @param path
-         * @return Pfad mit Separator am Ende
-         */
-        public static final String addSeparator (String path) {
-                return  path.length() == 0 || path.endsWith(File.separator) ? path : path
-                                + File.separatorChar;
-        }
-
-        /**
-         * Fügt ein <code>/</code> ans ende des Strings and
-         * @param path
-         * @return Pfad mit <code>/</code> am Ende
-         */
-        public static final String addSlash (String path) {
-                return  path.length() == 0 || path.endsWith("/") ? path : path + '/';
-        }
-
-        /**
-         * Löscht <code>/</code> am Ende des Strings, falls vorhanden
-         * @param path
-         * @return String ohne <code>/</code> am Ende
-         */
-        public static final String removeSlash (String path) {
-                return  path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()
-                                - 1) : path;
-        }
-
-        /**
-         * Checks to see if the path is absolute by looking for a leading file
-         * separater
-         * @param path
-         * @return
-         */
-        public static boolean isAbsolutePath (String path) {
-                return  path.startsWith(File.separator);
-        }
-
-        /**
-         * Löscht Slash am Anfang des Strings
-         * @param path
-         * @return
-         */
-        public static String removeFirstSlash (String path) {
-                return  path.startsWith("/") ? path.substring(1) : path;
-        }
-
-        /**
-         * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05)
-         * @return zwistellige Zahl
-         */
-        public static String pad2 (int number) {
-                return  number < 10 ? "0" + number : String.valueOf(number);
-        }
-
-        /**
-         * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007)
-         *
-         * @return 3-stellige Zahl
-         */
-        public static String pad3 (int number) {
-                return  number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number);
-        }
-
-        /**
-         * Konvertiert Unix-Linefeeds in Win-Linefeeds
-         * @param s
-         * @return Konvertierter String
-         */
-        public static String unixLineFeedsToWin(String s) {
-                int i = -1;
-                while (true) {
-                        i = s.indexOf('\n', i+1);
-                        if (i < 0) break;
-                        if ((i == 0 || s.charAt(i-1) != '\r') &&
-                                (i == s.length()-1 || s.charAt(i+1) != '\r')) {
-                                s = s.substring(0, i)+'\r'+s.substring(i);
-                                i++;
-                        }
-                }
-                return s;
-        }
-
-        public static String replaceQuot(String s) {
-                StringBuffer buffer = new StringBuffer();
-                for(int j = 0; j < s.length();j++){
-                        if(s.charAt(j)=='&'){
-                                if(s.indexOf( "&quot;",j) == j) {
-                                        buffer.append( "\"" );
-                                        j += 5;
-                                }//if
-                        } else {
-                                buffer.append(s.charAt(j));
-                        }//else
-                }//for
-                return buffer.toString();
-        }
-
-        /** wandelt Quotes in Sonderzeichen um
-         */
-        /**
-        public static String decodeHtml(String s) {
-                StringBuffer buf = new StringBuffer();
-                for(int i=0;i < s.length(); i++ ) {
-                        if( s.indexOf( "&ouml;", i ) == i ) {
-                                buf.append( "ö" ); i += 5;
-                                continue;
-                        }
-                        if( s.indexOf( "&auml;", i ) == i ) {
-                                buf.append( "ä" ); i += 5;
-                                continue;
-                        }
-                        if( s.indexOf( "&uuml;", i ) == i ) {
-                                buf.append( "ü" ); i += 5;
-                                continue;
-                        }
-                        if( s.indexOf( "&Ouml;", i ) == i ) {
-                                buf.append( "Ö" ); i += 5;
-                                continue;
-                        }
-                        if( s.indexOf( "&Auml;", i ) == i ) {
-                                buf.append( "Ä" ); i += 5;
-                                continue;
-                        }
-                        if( s.indexOf( "&Uuml;", i ) == i ) {
-                                buf.append( "Ãœ" ); i += 5;
-                                continue;
-                        }
-                        if( s.indexOf( "&szlig;", i ) == i ) {
-                                buf.append( "ß" ); i += 6;
-                                continue;
-                        }
-                        if( s.indexOf( "&quot;", i ) == i ) {
-                                buf.append( "\"" ); i += 5;
-                                continue;
-                        }
-                        buf.append( s.charAt(i) );
-                }
-                return buf.toString();
-        }
-         */
-
-        /**
-         * schnellere Variante der String.toLowerCase()-Routine
-         *
-         * @return String in Kleinbuchsten
-         */
-        public static String toLowerCase(String s) {
-                int l = s.length();
-                char[] a = new char[l];
-                for (int i = 0; i < l; i++)
-                        a[i] = Character.toLowerCase(s.charAt(i));
-                return new String(a);
-        }
-
-                /**
-         * Findet <code>element</code> im String-Array <code>array</code>
-         * @param array
-         * @param element
-         * @return Fundstelle als int oder -1
-         */
-        public static int indexOf(String[] array, String element) {
-                if (array != null)
-                        for (int i = 0; i < array.length; i++)
-                                if (array[i].equals(element))
-                                        return i;
-                return -1;
-        }
-
-        /**
-         * Testet auf Vorkommen von <code>element</code> in <code>array</code>
-         * @param array String-Array
-         * @param element
-         * @return true wenn <code>element</code> vorkommt, sonst false
-         */
-        public static boolean contains(String[] array, String element) {
-                return indexOf(array, element) >= 0;
-        }
-
-                /**
-         * Ermittelt CRC-Prüfsumme von String <code>s</code>
-         * @param s
-         * @return CRC-Prüfsumme
-         */
-        public static int getCRC(String s) {
-                int h = 0;
-                char val[] = s.toCharArray();
-                int len = val.length;
-
-                for (int i = 0 ; i < len; i++) {
-                        h &= 0x7fffffff;
-                        h = (((h >> 30) | (h << 1)) ^ (val[i]+i));
-                }
-
-                return (h << 8) | (len & 0xff);
-        }
-
-                /**
-         * Liefert Default-Wert def zurück, wenn String <code>s</code>
-         * kein Integer ist.
-         *
-         * @param s
-         * @param def
-         * @return geparster int aus s oder def
-         */
-        public static int parseInt(String s, int def) {
-                if (s == null) return def;
-                try {
-                        return Integer.parseInt(s);
-                } catch (NumberFormatException e) {
-                        return def;
-                }
-        }
-
-        /**
-         * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann.
-         * @param s
-         * @param def
-         * @return geparster float oder def
-         */
-        public static float parseFloat(String s, float def) {
-                if (s == null) return def;
-                try {
-                        return new Float(s).floatValue();
-                } catch (NumberFormatException e) {
-                        return def;
-                }
-        }
-
-                /**
-         * Findet Ende eines Satzes in String <code>text</code>
-         * @param text
-         * @param startIndex
-         * @return index des Satzendes, oder -1
-         */
-        public static int findEndOfSentence(String text, int startIndex) {
-                 while (true) {
-                         int i = text.indexOf('.', startIndex);
-                         if (i < 0) return -1;
-                         if (i > 0 && !Character.isDigit(text.charAt(i-1)) &&
-                                        (i+1 >= text.length()
-                                        || text.charAt(i+1) == ' '
-                                        || text.charAt(i+1) == '\n'
-                                        || text.charAt(i+1) == '\t'))
-                                        return i+1;
-                         startIndex = i+1;
-                 }
-        }
-
-                /**
-         * Findet Wortende in String <code>text</code> ab <code>startIndex</code>
-         * @param text
-         * @param startIndex
-         * @return Index des Wortendes, oder -1
-         */
-        public static int findEndOfWord(String text, int startIndex) {
-                int i = text.indexOf(' ', startIndex),
-                        j = text.indexOf('\n', startIndex);
-                if (i < 0) i = text.length();
-                if (j < 0) j = text.length();
-                return Math.min(i, j);
-        }
-
-
-        /**
-         *  convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n)
-         *  in den html-tag <p>
-         *  nur sinnvoll, wenn text nicht im html-format eingegeben
-         */
-        public static String convertNewline2P(String haystack) {
-                        return re_brbr2p.substituteAll(haystack,"\n</p><p>");
-        }
-
-        /**
-         *  convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n)
-         *  in den html-tag <br>
-         *  nur sinnvoll, wenn text nicht im html-format eingegeben
-         */
-        public static String convertNewline2Break(String haystack) {
-                return re_newline2br.substituteAll(haystack,"$0<br />");
-        }
-
-        /**
-         *  createMailLinks wandelt text im email-adressenformat
-         *  in einen klickbaren link um
-         *  nur sinnvoll, wenn text nicht im html-format eingegeben
-         */
-        public static String createMailLinks(String haystack) {
-                        return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");
-        }
-
-
-        /**
-         *  createMailLinks wandelt text im email-adressenformat
-         *  in einen klickbaren link um
-         *  nur sinnvoll, wenn text nicht im html-format eingegeben
-         */
-        public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
-                return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/>&#160;<a href=\"mailto:$0\">$0</a>");
-        }
-
-
-        /**
-         *  createURLLinks wandelt text im url-format
-         *  in einen klickbaren link um
-         *  nur sinnvoll, wenn text nicht im html-format eingegeben
-         */
-        public static String createURLLinks(String haystack) {
-                return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");
-        }
-
-        /**
-         * this routine takes text in url format and makes
-         * a clickaeble "<href>" link removing any "illegal" html tags
-         * @param haystack, the url
-         * @param title, the href link text
-         * @param imagRoot, the place to find icons
-         * @param extImage, the url of the icon to show next to the link
-         * @return a String containing the url
-         */
-        public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
-                if (title == null) {
-                        return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
-                } else {
-                        title = removeHTMLTags(title);
-                        return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">"+title+"</a>");
-                }
-        }
-
-        /**
-         * this routine takes text in url format and makes
-         * a clickaeble "<href>" link removing any "illegal" html tags
-         * @param haystack, the url
-         * @param imageRoot, the place to find icons
-         * @param extImage, the url of the icon to show next to the link
-         * @param intImage, unused
-         * @return a String containing the url
-         */
-        public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
-                return createURLLinks(haystack, title, imageRoot, extImage);
-        }
-
-         /**
-         *  deleteForbiddenTags
-         *  this method deletes all <script>, <body> and <head>-tags
-         */
-        public static final String deleteForbiddenTags(String haystack) {
-                try {
-                        RE regex = new RE("<[ \t\r\n](.*?)script(.*?)/script(.*?)>",RE.REG_ICASE);
-                        haystack = regex.substituteAll(haystack,"");
-                        regex = new RE("<head>(.*?)</head>");
-                        haystack = regex.substituteAll(haystack,"");
-                        regex = new RE("<[ \t\r\n/]*body(.*?)>");
-                        haystack = regex.substituteAll(haystack,"");
-                        return haystack;
-                } catch(REException ex){
-                        return null;
-                }
-        }
-
-        /**
-         * this method deletes all html tags
-         */
-        public static final String removeHTMLTags(String haystack){
-                        return re_tags.substituteAll(haystack,"");
-        }
-
-
-        /**
-         * this method deletes all but the approved tags html tags
-         * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all
-         */
-        public static String approveHTMLTags(String haystack){
-                try {
-                        String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
-                        String badAttributes="onAbort|onBlur|onChange|onClick|onDblClick|onDragDrop|onError|onFocus|onKeyDown|onKeyPress|onKeyUp|onLoad|onMouseDown|onMouseMove|onMouseOut|onMouseOver|onMouseUp|onMove|onReset|onResize|onSelect|onSubmit|onUnload";
-                        String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
-
-                        // kill all the bad tags that have attributes
-                        String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
-                        RE regex = new RE(s,RE.REG_ICASE);
-                        haystack = regex.substituteAll(haystack,"");
-
-                        // kill all the bad tags that are attributeless
-                        regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
-                        haystack = regex.substituteAll(haystack,"");
-
-                        // kill all the tags which have a javascript attribute like onLoad
-                        regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
-                        haystack = regex.substituteAll(haystack,"");
-
-                        // kill all the tags which include a url to an unacceptable protocol
-                        regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
-                        haystack = regex.substituteAll(haystack,"");
-
-                        return haystack;
-                } catch(REException ex){
-                        ex.printStackTrace();
-                        return null;
-                }
-        }
-
-
-        /**
-         *  createHTML ruft alle regex-methoden zum unwandeln eines nicht
-         *  htmlcodierten string auf und returnt einen htmlcodierten String
-         */
-        public static String createHTML(String content){
-                content=convertNewline2Break(content);
-                content=convertNewline2P(content);
-                content=createMailLinks(content);
-                content=createURLLinks(content);
-                return content;
-        }
-
-
-        /**
-         *  createHTML ruft alle regex-methoden zum unwandeln eines nicht
-         *  htmlcodierten string auf und returnt einen htmlcodierten String
-         */
-        public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){
-                content=convertNewline2Break(content);
-                content=convertNewline2P(content);
-                content=createMailLinks(content,producerDocRoot,mailImage);
-                content=createURLLinks(content,null,producerDocRoot,extImage,intImage);
-                return content;
-        }
+  /**
+   * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält
+   *
+   * @return gequoteter String
+   */
+  public static String quoteIfNecessary(String s) {
+    for (int i = 0; i < s.length(); i++)
+      if (!(Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == '.'))
+        return quote(s, '"');
+    return s;
+  }
+
+  /**
+   * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
+   * "gefährliche" Zeichen innerhalb des Strings
+   * Quotes special SQL-characters in <code>s</code>
+   *
+   * @return geqoteter String
+   */
+  public static String quote(String s)
+  {
+    //String s2 = quote(s, '\'');
+    //Quickhack        ÃŠÃŠ ÃŠ ÃŠ ÃŠ ÃŠ ÃŠ ÃŠ
+    //Because of '?-Bug in Postgresql-JDBC-Driver
+    StringBuffer temp = new StringBuffer();
+    for(int i=0;i<s.length();i++){
+      if(s.charAt(i)=='\''){
+        temp.append("&#39;");
+      } else {
+        temp.append(s.charAt(i));
+      }
+    }
+    String s2 = temp.toString();
+    //end Quickhack
+
+    s2 = quote(s2, '\"');
+    return s2;
+  }
+
+  /**
+   * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
+   * "gefährliche" Zeichen innerhalb des Strings
+   *
+   * @param s String, der gequoted werden soll
+   * @param quoteChar zu quotendes Zeichen
+   * @return gequoteter String
+   */
+  public static String quote(String s, char quoteChar)
+  {
+    StringBuffer buf = new StringBuffer(s.length());
+    int pos = 0;
+    while (pos < s.length()) {
+      int i = s.indexOf(quoteChar, pos);
+      if (i < 0) i = s.length();
+      buf.append(s.substring(pos, i));
+      pos = i;
+      if (pos < s.length()) {
+        buf.append('\\');
+        buf.append(quoteChar);
+        pos++;
+      }
+    }
+    return buf.toString();
+  }
+
+  /**
+   * replaces dangerous characters in <code>s</code>
+   *
+   */
+
+  public static String unquote(String s)
+  {
+    char quoteChar='\'';
+    StringBuffer buf = new StringBuffer(s.length());
+    int pos = 0;
+    String searchString = "\\"+quoteChar;
+    while (pos < s.length()) {
+      int i = s.indexOf(searchString, pos);
+      if (i < 0) i = s.length();
+      buf.append(s.substring(pos, i));
+      pos = i+1;
+    }
+    return buf.toString();
+  }
+
+  /**
+   * Wandelet String in byte[] um.
+   * @param s
+   * @return byte[] des String
+   */
+
+  public static byte[] stringToBytes(String s) {
+    String crlf = System.getProperty("line.separator");
+    if (!crlf.equals("\n"))
+      s = replace(s, "\n", crlf);
+    // byte[] buf = new byte[s.length()];
+    byte[] buf = s.getBytes();
+    return buf;
+  }
+
+  /**
+   * Ersetzt in String <code>s</code> das <code>pattern</code> durch <code>substitute</code>
+   * @param s
+   * @param pattern
+   * @param substitute
+   * @return String mit den Ersetzungen
+   */
+  public static String replace(String s, String pattern, String substitute) {
+    int i = 0, pLen = pattern.length(), sLen = substitute.length();
+    StringBuffer buf = new StringBuffer(s.length());
+    while (true) {
+      int j = s.indexOf(pattern, i);
+      if (j < 0) {
+        buf.append(s.substring(i));
+        break;
+      } else {
+        buf.append(s.substring(i, j));
+        buf.append(substitute);
+        i = j+pLen;
+      }
+    }
+    return buf.toString();
+  }
+
+  /**
+   * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
+   * @param s
+   * @param pattern
+   * @param substitute
+   * @return String mit den Ersetzungen
+   */
+  public static String regexpReplace(String haystack, String pattern, String substitute) {
+    try {
+      RE regex = new RE(pattern);
+      return regex.substituteAll(haystack,substitute);
+    } catch(REException ex){
+      return null;
+    }
+  }
+
+
+
+
+  /**
+   * Fügt einen Separator an den Pfad an
+   * @param path
+   * @return Pfad mit Separator am Ende
+   */
+  public static final String addSeparator (String path) {
+    return  path.length() == 0 || path.endsWith(File.separator) ? path : path
+                          + File.separatorChar;
+  }
+
+  /**
+   * Fügt ein <code>/</code> ans ende des Strings and
+   * @param path
+   * @return Pfad mit <code>/</code> am Ende
+   */
+  public static final String addSlash (String path) {
+    return  path.length() == 0 || path.endsWith("/") ? path : path + '/';
+  }
+
+  /**
+   * Löscht <code>/</code> am Ende des Strings, falls vorhanden
+   * @param path
+   * @return String ohne <code>/</code> am Ende
+   */
+  public static final String removeSlash (String path) {
+    return  path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()
+        - 1) : path;
+  }
+
+  /**
+   * Checks to see if the path is absolute by looking for a leading file
+   * separater
+   * @param path
+   * @return
+   */
+  public static boolean isAbsolutePath (String path) {
+    return  path.startsWith(File.separator);
+  }
+
+  /**
+   * Löscht Slash am Anfang des Strings
+   * @param path
+   * @return
+   */
+  public static String removeFirstSlash (String path) {
+    return  path.startsWith("/") ? path.substring(1) : path;
+  }
+
+  /**
+   * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05)
+   * @return zwistellige Zahl
+   */
+  public static String pad2 (int number) {
+    return  number < 10 ? "0" + number : String.valueOf(number);
+  }
+
+  /**
+   * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007)
+   *
+   * @return 3-stellige Zahl
+   */
+  public static String pad3 (int number) {
+    return  number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number);
+  }
+
+  /**
+   * Konvertiert Unix-Linefeeds in Win-Linefeeds
+   * @param s
+   * @return Konvertierter String
+   */
+  public static String unixLineFeedsToWin(String s) {
+    int i = -1;
+    while (true) {
+      i = s.indexOf('\n', i+1);
+      if (i < 0) break;
+      if ((i == 0 || s.charAt(i-1) != '\r') &&
+          (i == s.length()-1 || s.charAt(i+1) != '\r')) {
+        s = s.substring(0, i)+'\r'+s.substring(i);
+        i++;
+      }
+    }
+    return s;
+  }
+
+  public static String replaceQuot(String s) {
+    StringBuffer buffer = new StringBuffer();
+    for(int j = 0; j < s.length();j++){
+      if(s.charAt(j)=='&'){
+        if(s.indexOf( "&quot;",j) == j) {
+          buffer.append( "\"" );
+          j += 5;
+        }//if
+      } else {
+        buffer.append(s.charAt(j));
+      }//else
+    }//for
+    return buffer.toString();
+  }
+
+ /**
+  * schnellere Variante der String.toLowerCase()-Routine
+  *
+  * @return String in Kleinbuchsten
+  */
+  public static String toLowerCase(String s) {
+    int l = s.length();
+    char[] a = new char[l];
+    for (int i = 0; i < l; i++)
+      a[i] = Character.toLowerCase(s.charAt(i));
+    return new String(a);
+  }
+
+  /**
+   * Findet <code>element</code> im String-Array <code>array</code>
+   * @param array
+   * @param element
+   * @return Fundstelle als int oder -1
+   */
+  public static int indexOf(String[] array, String element) {
+    if (array != null)
+      for (int i = 0; i < array.length; i++)
+        if (array[i].equals(element))
+          return i;
+    return -1;
+  }
+
+  /**
+   * Testet auf Vorkommen von <code>element</code> in <code>array</code>
+   * @param array String-Array
+   * @param element
+   * @return true wenn <code>element</code> vorkommt, sonst false
+   */
+  public static boolean contains(String[] array, String element) {
+    return indexOf(array, element) >= 0;
+  }
+
+  /**
+   * Ermittelt CRC-Prüfsumme von String <code>s</code>
+   * @param s
+   * @return CRC-Prüfsumme
+   */
+  public static int getCRC(String s) {
+    int h = 0;
+    char val[] = s.toCharArray();
+    int len = val.length;
+
+    for (int i = 0 ; i < len; i++) {
+      h &= 0x7fffffff;
+      h = (((h >> 30) | (h << 1)) ^ (val[i]+i));
+    }
+
+    return (h << 8) | (len & 0xff);
+  }
+
+  /**
+   * Liefert Default-Wert def zurück, wenn String <code>s</code>
+   * kein Integer ist.
+   *
+   * @param s
+   * @param def
+   * @return geparster int aus s oder def
+   */
+  public static int parseInt(String s, int def) {
+    if (s == null) return def;
+    try {
+      return Integer.parseInt(s);
+    } catch (NumberFormatException e) {
+      return def;
+    }
+  }
+
+  /**
+   * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann.
+   * @param s
+   * @param def
+   * @return geparster float oder def
+   */
+  public static float parseFloat(String s, float def) {
+    if (s == null) return def;
+    try {
+      return new Float(s).floatValue();
+    } catch (NumberFormatException e) {
+      return def;
+    }
+  }
+
+  /**
+   * Findet Ende eines Satzes in String <code>text</code>
+   * @param text
+   * @param startIndex
+   * @return index des Satzendes, oder -1
+   */
+  public static int findEndOfSentence(String text, int startIndex) {
+    while (true) {
+      int i = text.indexOf('.', startIndex);
+      if (i < 0) return -1;
+      if (i > 0 && !Character.isDigit(text.charAt(i-1)) &&
+          (i+1 >= text.length()
+          || text.charAt(i+1) == ' '
+          || text.charAt(i+1) == '\n'
+          || text.charAt(i+1) == '\t'))
+        return i+1;
+      startIndex = i+1;
+    }
+  }
+
+  /**
+   * Findet Wortende in String <code>text</code> ab <code>startIndex</code>
+   * @param text
+   * @param startIndex
+   * @return Index des Wortendes, oder -1
+   */
+  public static int findEndOfWord(String text, int startIndex) {
+    int i = text.indexOf(' ', startIndex),
+    j = text.indexOf('\n', startIndex);
+    if (i < 0) i = text.length();
+    if (j < 0) j = text.length();
+    return Math.min(i, j);
+  }
+
+
+  /**
+   *  convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n)
+   *  in den html-tag <p>
+   *  nur sinnvoll, wenn text nicht im html-format eingegeben
+   */
+  public static String convertNewline2P(String haystack) {
+    return re_brbr2p.substituteAll(haystack,"\n</p><p>");
+  }
+
+  /**
+   *  convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n)
+   *  in den html-tag <br>
+   *  nur sinnvoll, wenn text nicht im html-format eingegeben
+   */
+  public static String convertNewline2Break(String haystack) {
+    return re_newline2br.substituteAll(haystack,"$0<br />");
+  }
+
+  /**
+   *  createMailLinks wandelt text im email-adressenformat
+   *  in einen klickbaren link um
+   *  nur sinnvoll, wenn text nicht im html-format eingegeben
+   */
+  public static String createMailLinks(String haystack) {
+    return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");
+  }
+
+
+  /**
+   *  createMailLinks wandelt text im email-adressenformat
+   *  in einen klickbaren link um
+   *  nur sinnvoll, wenn text nicht im html-format eingegeben
+   */
+  public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
+    return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/>&#160;<a href=\"mailto:$0\">$0</a>");
+  }
+
+
+  /**
+   *  createURLLinks wandelt text im url-format
+   *  in einen klickbaren link um
+   *  nur sinnvoll, wenn text nicht im html-format eingegeben
+   */
+  public static String createURLLinks(String haystack) {
+    return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");
+  }
+
+  /**
+   * this routine takes text in url format and makes
+   * a clickaeble "<href>" link removing any "illegal" html tags
+   * @param haystack, the url
+   * @param title, the href link text
+   * @param imagRoot, the place to find icons
+   * @param extImage, the url of the icon to show next to the link
+   * @return a String containing the url
+   */
+  public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
+    if (title == null) {
+      return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
+    } else {
+      title = removeHTMLTags(title);
+      return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">"+title+"</a>");
+    }
+  }
+
+  /**
+   * this routine takes text in url format and makes
+   * a clickaeble "<href>" link removing any "illegal" html tags
+   * @param haystack, the url
+   * @param imageRoot, the place to find icons
+   * @param extImage, the url of the icon to show next to the link
+   * @param intImage, unused
+   * @return a String containing the url
+   */
+  public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
+    return createURLLinks(haystack, title, imageRoot, extImage);
+  }
+
+  /**
+   * this method deletes all html tags
+   */
+  public static final String removeHTMLTags(String haystack){
+    return re_tags.substituteAll(haystack,"");
+  }
+
+  /**
+   * this method deletes all but the approved tags html tags
+   * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all
+   */
+  public static String approveHTMLTags(String haystack){
+    try {
+      String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
+      String badAttributes="onAbort|onBlur|onChange|onClick|onDblClick|onDragDrop|onError|onFocus|onKeyDown|onKeyPress|onKeyUp|onLoad|onMouseDown|onMouseMove|onMouseOut|onMouseOver|onMouseUp|onMove|onReset|onResize|onSelect|onSubmit|onUnload";
+      String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
+
+      // kill all the bad tags that have attributes
+      String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
+      RE regex = new RE(s,RE.REG_ICASE);
+      haystack = regex.substituteAll(haystack,"");
+
+      // kill all the bad tags that are attributeless
+      regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
+      haystack = regex.substituteAll(haystack,"");
+
+      // kill all the tags which have a javascript attribute like onLoad
+      regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
+      haystack = regex.substituteAll(haystack,"");
+
+      // kill all the tags which include a url to an unacceptable protocol
+      regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
+      haystack = regex.substituteAll(haystack,"");
+
+      return haystack;
+    } catch(REException ex){
+      ex.printStackTrace();
+      return null;
+    }
+  }
+
+
+  /**
+   *  createHTML ruft alle regex-methoden zum unwandeln eines nicht
+   *  htmlcodierten string auf und returnt einen htmlcodierten String
+   */
+  public static String createHTML(String content){
+    content=convertNewline2Break(content);
+    content=convertNewline2P(content);
+    content=createMailLinks(content);
+    content=createURLLinks(content);
+    return content;
+  }
+
+
+  /**
+   *  createHTML ruft alle regex-methoden zum unwandeln eines nicht
+   *  htmlcodierten string auf und returnt einen htmlcodierten String
+   */
+  public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){
+    content=convertNewline2Break(content);
+    content=convertNewline2P(content);
+    content=createMailLinks(content,producerDocRoot,mailImage);
+    content=createURLLinks(content,null,producerDocRoot,extImage,intImage);
+    return content;
+  }
 
 }
 
index 394522d..7d156d2 100755 (executable)
@@ -40,29 +40,36 @@ public class GeneratorHTMLFunctions {
   private GeneratorHTMLFunctions() {}
 
   public static class encodeURIGeneratorFunction implements Generator.GeneratorFunction {
-    public Object perform(List aParameters) throws GeneratorExc {
-      if (aParameters.size()!=1)
-        throw new GeneratorExc("encodeURIGeneratorFunction: only 1 parameter expected");
-      if (aParameters.get(0)==null)
-        return "";
-      if (!(aParameters.get(0) instanceof String))
-        throw new GeneratorExc("encodeURIGeneratorFunction: parameter must be a string (not a "+aParameters.get(0).getClass().getName()+")");
+    public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+      try {
+        if (aParameters.size()!=1)
+          throw new GeneratorExc("encodeURIGeneratorFunction: only 1 parameter expected");
 
-      return HTMLRoutines.encodeURL((String) aParameters.get(0));
+        return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aParameters.get(0)));
+      }
+      catch (GeneratorExc e) {
+        throw e;
+      }
+      catch (Throwable t) {
+        throw new GeneratorFailure("encodeURIGeneratorFunction: " + t.getMessage(), t);
+      }
     };
   }
 
   public static class encodeHTMLGeneratorFunction implements Generator.GeneratorFunction {
     public Object perform(List aParameters) throws GeneratorExc {
-      if (aParameters.size()!=1)
-        throw new GeneratorExc("encodeHTMLGeneratorFunction: only 1 parameter expected");
-      if (aParameters.get(0)==null)
-        return "";
-      if (!(aParameters.get(0) instanceof String))
-        throw new GeneratorExc("encodeHTMLGeneratorFunction: parameter must be a string (not a "+aParameters.get(0).getClass().getName()+")");
-
+      try {
+        if (aParameters.size()!=1)
+          throw new GeneratorExc("encodeHTMLGeneratorFunction: only 1 parameter expected");
 
-      return HTMLRoutines.encodeHTML((String) aParameters.get(0));
+        return HTMLRoutines.encodeHTML(StringRoutines.interpretAsString(aParameters.get(0)));
+      }
+      catch (GeneratorExc e) {
+        throw e;
+      }
+      catch (Throwable t) {
+        throw new GeneratorFailure("encodeHTMLGeneratorFunction: " + t.getMessage(), t);
+      }
     };
   }
 }
diff --git a/source/mir/util/GeneratorIntegerFunctions.java b/source/mir/util/GeneratorIntegerFunctions.java
new file mode 100755 (executable)
index 0000000..5a36749
--- /dev/null
@@ -0,0 +1,48 @@
+package mir.util;
+
+import java.util.*;
+import mir.generator.*;
+
+public class GeneratorIntegerFunctions {
+
+  private GeneratorIntegerFunctions() {}
+
+  public static class incrementFunction implements Generator.GeneratorFunction {
+    public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+      int incrementValue = 1;
+
+      try {
+        if (aParameters.size()>2 || aParameters.size()<1)
+          throw new GeneratorExc("incrementFunction: 1 or 2 parameters expected: value [increment value]");
+
+        if (aParameters.size()>1)
+          incrementValue = StringRoutines.interpretAsInteger(aParameters.get(1));
+
+        return new Integer(StringRoutines.interpretAsInteger(aParameters.get(0)) + incrementValue);
+      }
+      catch (GeneratorExc e) {
+        throw e;
+      }
+      catch (Throwable t) {
+        throw new GeneratorFailure("incrementFunction: " + t.getMessage(), t);
+      }
+    };
+  }
+
+  public static class isOddFunction implements Generator.GeneratorFunction {
+    public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+      try {
+        if (aParameters.size()!=1)
+          throw new GeneratorExc("isOddFunction: 1 parameters expected: value");
+
+        return new Boolean((StringRoutines.interpretAsInteger(aParameters.get(0)) & 1) == 1);
+      }
+      catch (GeneratorExc e) {
+        throw e;
+      }
+      catch (Throwable t) {
+        throw new GeneratorFailure("isOddFunction: " + t.getMessage(), t);
+      }
+    };
+  }
+}
\ No newline at end of file
index 66f7533..b46101d 100755 (executable)
@@ -38,32 +38,19 @@ public class GeneratorStringFunctions {
 
   private GeneratorStringFunctions() {}
 
-  public static String interpretAsString(Object aValue) throws GeneratorExc {
-    if (aValue instanceof String)
-      return (String) aValue;
-
-    if (aValue instanceof Integer)
-      return ((Integer) aValue).toString();
-
-    throw new GeneratorExc("String expected, "+aValue+" found");
-  }
-
   public static class subStringFunction implements Generator.GeneratorFunction {
     public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
       try {
         if (aParameters.size()>3 || aParameters.size()<2)
           throw new GeneratorExc("subStringFunction: 2 or 3 parameters expected: string from [length]");
 
-        if (aParameters.get(0)==null)
-          return "";
-
         if (aParameters.size()==3) {
-          return interpretAsString(aParameters.get(0)).substring(
+          return StringRoutines.interpretAsString(aParameters.get(0)).substring(
               StringRoutines.interpretAsInteger(aParameters.get(1)),
               StringRoutines.interpretAsInteger(aParameters.get(2)));
         }
         else {
-          return interpretAsString(aParameters.get(0)).substring(
+          return StringRoutines.interpretAsString(aParameters.get(0)).substring(
               StringRoutines.interpretAsInteger(aParameters.get(1)));
         }
       }
index 0edc27f..e25df14 100755 (executable)
@@ -55,6 +55,19 @@ public class StringRoutines {
     return result;
   }
 
+  public static String interpretAsString(Object aValue) throws Exception {
+    if (aValue instanceof String)
+      return (String) aValue;
+
+    if (aValue instanceof Integer)
+      return ((Integer) aValue).toString();
+
+    if (aValue == null)
+      return "";
+
+    throw new Exception("String expected, "+aValue+" found");
+  }
+
   public static int interpretAsInteger(Object aValue) throws Exception {
     if (aValue instanceof Integer)
       return ((Integer) aValue).intValue();
index 30bee5d..bfdbd2e 100755 (executable)
@@ -46,7 +46,7 @@ import mir.storage.*;
  * This class maps one line of the comment-table to a java-object.
  *
  * @author $Author: zapata $
- * @version $Revision: 1.11 $ $Date: 2002/12/01 22:13:37 $
+ * @version $Revision: 1.12 $ $Date: 2002/12/02 12:33:23 $
  */
 
 
@@ -87,33 +87,4 @@ public class EntityComment extends Entity
     }
     super.setValues(theStringValues);
   }
-
-  /**
-   * overridden method getValue to include formatted date into every
-   * entityContent
-   */
-
-  public String getValue(String field)
-  {
-    String returnField = null;
-    if (field!=null)
-    {
-      if (field.equals("date_formatted") || field.equals("webdb_create_short"))
-      {
-        if (hasValueForField("webdb_create"))
-          returnField = StringUtil.dateToReadableDate(getValue("webdb_create"));
-      }
-      else if (field.equals("description_parsed")) {
-        /** @todo the config stuff should be moved to StringUtil */
-        String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
-        String intLinkName = MirConfig.getProp("Producer.IntLinkName");
-        String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
-        String imageRoot = MirConfig.getProp("Producer.ImageRoot");
-        returnField = StringUtil.createHTML(getValue("description"),imageRoot,mailLinkName,extLinkName,intLinkName);
-      }
-      else
-        return super.getValue(field);
-    }
-    return returnField;
-  }
 }
index b824a71..7935b53 100755 (executable)
@@ -50,7 +50,7 @@ import mircoders.storage.*;
  * this class implements mapping of one line of the database table content
  * to a java object
  *
- * @version $Id: EntityContent.java,v 1.12 2002/11/27 08:20:14 mh Exp $
+ * @version $Id: EntityContent.java,v 1.13 2002/12/02 12:33:23 zapata Exp $
  * @author mir-coders group
  *
  */
@@ -70,129 +70,112 @@ public class EntityContent extends Entity
   HashMap _entCache = new HashMap();
   Boolean _hasMedia = null;
 
-       // constructors
+  // constructors
 
-       public EntityContent()
-       {
-               super();
+  public EntityContent()
+  {
+    super();
     //content_data is now filed-type "text"
-               //streamedInput = new ArrayList();
-               //streamedInput.add("content_data");
-       }
+    //streamedInput = new ArrayList();
+    //streamedInput.add("content_data");
+  }
 
-       public EntityContent(StorageObject theStorage) {
-               this();
-               setStorage(theStorage);
-       }
+  public EntityContent(StorageObject theStorage) {
+    this();
+    setStorage(theStorage);
+  }
 
-       //
-       // methods
+  //
+  // methods
 
- /**
-       * set is_produced flag for the article
-       */
 /**
+   * set is_produced flag for the article
+   */
 
-       public void setProduced(boolean yesno) throws StorageObjectException
-       {
-               String value = (yesno) ? "1":"0";
-               if (value.equals( getValue("is_produced") )) return;
+  public void setProduced(boolean yesno) throws StorageObjectException
+  {
+    String value = (yesno) ? "1":"0";
+    if (value.equals( getValue("is_produced") )) return;
 
     Connection con=null;Statement stmt=null;
     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);
-               } catch (StorageObjectException e) {
-            throwStorageObjectException(e, "\n -- set produced failed");
-               } catch (SQLException e) {
-            throwStorageObjectException(e, "\n -- set produced failed");
-               } finally {
-                       theStorageObject.freeConnection(con,stmt);
-               }
-       }
-
-
- /**
-       * make openposting to newswire
-       */
-
-       public void newswire() throws StorageObjectException
-       {
-               String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
-               try {
-                               theStorageObject.executeUpdate(sql);
-               } catch (StorageObjectException e) {
-            throwStorageObjectException(e, "\n -- newswire failed");
-               } catch (SQLException e) {
-            throwStorageObjectException(e, "\n -- newswire failed");
-               }
-       }
-
-
- /**
-       * dettach from media
-       */
-       public void dettach(String cid,String mid) throws StorageObjectException
-       {
-               if (mid!=null){
-                       try{
-                               DatabaseContentToMedia.getInstance().delete(cid,mid);
-                       } catch (Exception e){
-                throwStorageObjectException(e, "\n -- failed to get instance");
-                       }
-                       //set Content to unproduced
-                       setProduced(false);
-               }
-       }
-
- /**
-       * attach to media
-       */
-
-       public void attach(String mid) throws StorageObjectException
-       {
-               if (mid!=null) {
-                       //write media-id mid and content-id in table content_x_media
-                       try{
-                               DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
-                       } catch(StorageObjectException e){
-                               throwStorageObjectException(e, "attach: could not get the instance");
-                       }
-                       //set Content to unproduced
-                       setProduced(false);
-               }       else {
-                       theLog.printError("EntityContent: attach without mid");
-               }
-       }
-
-       /**
-        * overridden method getValue to include formatted date into every
-        * entityContent
-        */
-
-       public String getValue(String field)
+    try {
+      con = theStorageObject.getPooledCon();
+      /** @todo should be preparedStatement: faster!! */
+      stmt = con.createStatement();
+      theStorageObject.executeUpdate(stmt,sql);
+    }
+    catch (StorageObjectException e) {
+      throwStorageObjectException(e, "\n -- set produced failed");
+    }
+    catch (SQLException e) {
+      throwStorageObjectException(e, "\n -- set produced failed");
+    }
+    finally {
+      theStorageObject.freeConnection(con,stmt);
+    }
+  }
+
+
+  /**
+   * make openposting to newswire
+   */
+
+  public void newswire() throws StorageObjectException
+  {
+    String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
+    try {
+      theStorageObject.executeUpdate(sql);
+    } catch (StorageObjectException e) {
+      throwStorageObjectException(e, "\n -- newswire failed");
+    } catch (SQLException e) {
+      throwStorageObjectException(e, "\n -- newswire failed");
+    }
+  }
+
+
+  /**
+   * dettach from media
+   */
+  public void dettach(String cid,String mid) throws StorageObjectException
   {
-    String returnField = null;
-    if (field!=null)
-    {
-      if (field.equals("date_formatted") || field.equals("webdb_create_short") )
-      {
-                 if (hasValueForField("date"))
-       returnField = StringUtil.webdbDate2readableDate(getValue("webdb_create"));
-               }
-      else if (field.equals("description_parsed"))
-        returnField = getDescriptionParsed();
-      else if (field.equals("description_sentence"))
-        returnField = getDescriptionSentence();
-      else if (field.equals("content_data_parsed"))
-        returnField = getContentDataParsed();
-      else
-        return super.getValue(field);
+    if (mid!=null){
+      try{
+        DatabaseContentToMedia.getInstance().delete(cid,mid);
+      }
+      catch (Exception e){
+        throwStorageObjectException(e, "\n -- failed to get instance");
+      }
+
+      //set Content to unproduced
+      setProduced(false);
     }
-    return returnField;
-       }
+  }
+
+  /**
+   * attach to media
+   */
+
+  public void attach(String mid) throws StorageObjectException
+  {
+    if (mid!=null) {
+      //write media-id mid and content-id in table content_x_media
+      try{
+        DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
+      } catch(StorageObjectException e){
+        throwStorageObjectException(e, "attach: could not get the instance");
+      }
+      //set Content to unproduced
+      setProduced(false);
+    }  else {
+      theLog.printError("EntityContent: attach without mid");
+    }
+  }
+
+  /**
+   * overridden method getValue to include formatted date into every
+   * entityContent
+   */
 
   public TemplateModel get(java.lang.String key) throws TemplateModelException
   {
@@ -204,8 +187,10 @@ public class EntityContent extends Entity
         try {
           _entCache.put(key, getComments());
           return (TemplateModel)_entCache.get(key);
-        } catch (Exception ex) {
+        }
+        catch (Exception ex) {
           theLog.printWarning("-- getComments: could not fetch data " + ex.toString());
+
           throw new TemplateModelException(ex.toString());
         }
       }
@@ -249,19 +234,9 @@ public class EntityContent extends Entity
           throw new TemplateModelException(ex.toString());
         }
       }
-      else if (key.equals("to_media_icon")) {
-        try {
-          _entCache.put(key, getUploadedMediaForNewswire());
-          return (TemplateModel)_entCache.get(key);
-        }
-        catch (Exception ex) {
-          theLog.printWarning("-- getUploadedMediaForNewswire: could not fetch data " + ex.toString());
-          throw new TemplateModelException(ex.toString());
-        }
-      }
       else if (key.equals("to_topics")) {
         try {
-          _entCache.put(key, 
+          _entCache.put(key,
                         DatabaseContentToTopics.getInstance().getTopics(this));
           return (TemplateModel)_entCache.get(key);
         }
@@ -278,133 +253,37 @@ public class EntityContent extends Entity
     return null;
   }
 
-
-
-
-       /**
-        * overridden method setValues to patch creator_main_url
-        */
-       public void setValues(HashMap theStringValues) {
-               if (theStringValues != null) {
-                       if (theStringValues.containsKey("creator_main_url")){
-                               if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
-                                       theStringValues.remove("creator_main_url");
-        } else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
+  /**
+   * overridden method setValues to patch creator_main_url
+   */
+  public void setValues(HashMap theStringValues) {
+    if (theStringValues != null) {
+      if (theStringValues.containsKey("creator_main_url")){
+        if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
+          theStringValues.remove("creator_main_url");
+        }
+        else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
           theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
         }
       }
-               }
-               super.setValues(theStringValues);
-       }
-
-
-  private String getContentDataParsed() {
-    String returnField = getValue("content_data");
-    if ((returnField!=null) && (returnField.length()>0) ) {
-      returnField=StringUtil.deleteForbiddenTags(returnField);
-      //create http-links and email-links
-      if (getValue("is_html").equals("0")) {
-        returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
-                                            mirconf_mailLinkName,mirconf_extLinkName,
-                                            mirconf_intLinkName);
-      }
     }
-    return returnField;
+    super.setValues(theStringValues);
   }
 
-  private String getDescriptionSentence() {
-    String returnField = getValue("description");
-    if (returnField != null && returnField.length()>0) {
-       returnField = StringUtil.removeHTMLTags(returnField);
-       int endOfFirstSentence=StringUtil.findEndOfSentence(returnField,0);
-       if (endOfFirstSentence > 0){
-        returnField = returnField.substring(0,endOfFirstSentence);
-       }
-    }
-    return returnField;
-  }
-
-  private String getDescriptionParsed() {
-    String returnField = getValue("description");
-    if (returnField != null && returnField.length()>0) {
-      returnField = StringUtil.deleteForbiddenTags(returnField);
-      if (getValue("is_html").equals("0")) {
-        returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
-                                            mirconf_mailLinkName,mirconf_extLinkName,
-                                            mirconf_intLinkName);
-      }
-    }
-    return returnField;
-  }
-
-       /**
-        * fetches all the comments belonging to an article
-        *
-        * @return freemarker.template.SimpleList
-        */
-       private EntityList getComments() throws StorageObjectException {
-               return ((DatabaseContent)theStorageObject).getComments(this);
-       }
-
-  // @todo this needs to optimized. expensive SQL
-  private SimpleHash getUploadedMediaForNewswire()
-    throws StorageObjectException, TemplateModelException
-  {
-    // fetching/setting the images
-    // return to_media_icons
-    String        tinyIcon = null, iconAlt = null;
-    MirMedia      mediaHandler = null;
-    EntityUploadedMedia uploadedMedia;
-    Entity        mediaType;
-    SimpleHash    returnHash = new SimpleHash();
-
-    EntityList upMediaEntityList =
-                    DatabaseContentToMedia.getInstance().getUploadedMedia(this);
-    if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) {
-
-      for (int n=0; n < upMediaEntityList.size();n++) {
-        uploadedMedia = (EntityUploadedMedia)upMediaEntityList.elementAt(n);
-        mediaType = uploadedMedia.getMediaType();
-        try {
-          mediaHandler = MediaHelper.getHandler( mediaType );
-        } catch (MirMediaException ex) {
-          throw new TemplateModelException(ex.toString());
-        }
-        //the "best" media type to show
-        if (mediaHandler.isVideo()) {
-          tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo");
-          iconAlt = "Video";
-          break;
-        } else if (mediaHandler.isAudio()) {
-          tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio");
-          iconAlt = "Audio";
-        } else if (tinyIcon == null && !mediaHandler.isImage()) {
-          tinyIcon = mediaHandler.getTinyIconName();
-          iconAlt = mediaHandler.getIconAltName();
-        }
-
-      }
-      //it only has image(s)
-      if (tinyIcon == null) {
-        tinyIcon = MirConfig.getProp("Producer.Icon.TinyImage");
-        iconAlt = "Image";
-      }
-    // uploadedMedia Entity list is empty.
-    // we only have text
-    } else {
-      tinyIcon = MirConfig.getProp("Producer.Icon.TinyText");
-      iconAlt = "Text";
-    }
-    returnHash.put("tiny_icon", mirconf_imageRoot+"/"+tinyIcon);
-    returnHash.put("icon_alt", iconAlt);
-    return returnHash;
+  /**
+   * fetches all the comments belonging to an article
+   *
+   * @return freemarker.template.SimpleList
+   */
+  private EntityList getComments() throws StorageObjectException {
+    return ((DatabaseContent)theStorageObject).getComments(this);
   }
 
   private boolean hasMedia() throws StorageObjectException
   {
     if (_hasMedia == null) {
       _hasMedia =
-        new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
+          new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
     }
     return _hasMedia.booleanValue();
   }
@@ -412,7 +291,7 @@ public class EntityContent extends Entity
   //######## @todo all of the following getBlahForContent should have
   // and optimized version where LIMIT=1 sql for list view.
   private EntityList getImagesForContent()
-    throws StorageObjectException, TemplateModelException
+      throws StorageObjectException, TemplateModelException
   {
     if (hasMedia())
       return DatabaseContentToMedia.getInstance().getImages(this);
@@ -421,7 +300,7 @@ public class EntityContent extends Entity
   }
 
   private EntityList getAudioForContent()
-    throws StorageObjectException, TemplateModelException
+      throws StorageObjectException, TemplateModelException
   {
     if (hasMedia())
       return DatabaseContentToMedia.getInstance().getAudio(this) ;
@@ -430,7 +309,7 @@ public class EntityContent extends Entity
   }
 
   private EntityList getVideoForContent()
-    throws StorageObjectException, TemplateModelException
+      throws StorageObjectException, TemplateModelException
   {
     if (hasMedia())
       return DatabaseContentToMedia.getInstance().getVideo(this) ;
@@ -439,7 +318,7 @@ public class EntityContent extends Entity
   }
 
   private EntityList getOtherMediaForContent()
-    throws StorageObjectException, TemplateModelException
+      throws StorageObjectException, TemplateModelException
   {
     if (hasMedia())
       return DatabaseContentToMedia.getInstance().getOther(this);
index e82424e..d6d116d 100755 (executable)
@@ -51,21 +51,19 @@ import mircoders.storage.*;
 
 public class EntityFeature extends Entity
 {
+  public EntityFeature()
+  {
+    super();
+  }
 
-               public EntityFeature()
-               {
-       super();
-               }
-
-               public EntityFeature(StorageObject theStorage) {
-                       this();
-       setStorage(theStorage);
-               }
-
-       public void update() throws StorageObjectException{
-               super.update();
-               DatabaseContent dbContent = DatabaseContent.getInstance();
-               dbContent.setUnproduced("to_feature="+getId());
-       }
+  public EntityFeature(StorageObject theStorage) {
+    this();
+    setStorage(theStorage);
+  }
 
+  public void update() throws StorageObjectException{
+    super.update();
+    DatabaseContent dbContent = DatabaseContent.getInstance();
+    dbContent.setUnproduced("to_feature="+getId());
+  }
 }
index 431c666..617e848 100755 (executable)
@@ -75,6 +75,8 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL
     utilityMap.put("encodeURI", new GeneratorHTMLFunctions.encodeURIGeneratorFunction());
     utilityMap.put("subString", new GeneratorStringFunctions.subStringFunction());
     utilityMap.put("subList", new GeneratorListFunctions.subListFunction());
+    utilityMap.put("isOdd", new GeneratorIntegerFunctions.isOddFunction());
+    utilityMap.put("increment", new GeneratorIntegerFunctions.incrementFunction());
 
 
     aValueSet.put("config", configMap);
index dd63e3f..3ccd7cc 100755 (executable)
@@ -62,7 +62,7 @@ import mircoders.localizer.*;
  *  ServletModuleContent -
  *  deliver html for the article admin form.
  *
- * @version $Id: ServletModuleContent.java,v 1.25 2002/12/01 22:13:37 zapata Exp $
+ * @version $Id: ServletModuleContent.java,v 1.26 2002/12/02 12:33:24 zapata Exp $
  * @author rk, mir-coders
  *
  */
@@ -84,9 +84,9 @@ public class ServletModuleContent extends ServletModule
     logger = new LoggerWrapper("ServletModule.Content");
     try {
       templateListString = MirConfig.getProp("ServletModule.Content.ListTemplate");
-//templateOpString = MirConfig.getProp("ServletModule.Content.OpTemplate");
       templateObjektString = MirConfig.getProp("ServletModule.Content.ObjektTemplate");
       templateConfirmString = MirConfig.getProp("ServletModule.Content.ConfirmTemplate");
+
       mainModule = new ModuleContent(DatabaseContent.getInstance());
       themenModule = new ModuleTopics(DatabaseTopics.getInstance());
       schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
@@ -336,14 +336,9 @@ public class ServletModuleContent extends ServletModule
       if (!withValues.containsKey("is_html"))
         withValues.put("is_html","0");
 
-//      ML: this is not multi-language friendly and this can be done in a template
-//      if (withValues.get("creator").toString().equals(""))
-//        withValues.put("creator","Anonym");
-
-//theLog.printDebugInfo("updating. ");
       String id = mainModule.set(withValues);
       DatabaseContentToTopics.getInstance().setTopics(req.getParameter("id"),topic_id);
-//theLog.printDebugInfo("update done. ");
+
       String whereParam = req.getParameter("where");
       String orderParam = req.getParameter("order");
       if ((whereParam!=null && !whereParam.equals("")) || (orderParam!=null && !orderParam.equals(""))){