package es.tid.bdp.kpicalculation.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Class used to format the date string received in log data allowing to get the
 * date and time in the wanted format
 *
 * @author javierb
 */
public final class KpiCalculationDateFormatter {
    private static boolean isInitialized = false;
    private static SimpleDateFormat inputFormat = null;
    private static SimpleDateFormat dateFormat = null;
    private static Calendar calendar = null;

    private KpiCalculationDateFormatter() {
    }

    /**
     * Method that initializes the formatters
     */
    public static void init(String delimiter) {
        if (isInitialized) {
            // Avoid unnecessary re-initializations.
            return;
        }

        inputFormat = new SimpleDateFormat("ddMMMyyyyhhmmss", Locale.ENGLISH);
        dateFormat = new SimpleDateFormat("dd" + delimiter + "MM" + delimiter
                + "yyyy");
        calendar = Calendar.getInstance();
        isInitialized = true;
    }

    /**
     * Method that provides the formatted date string corresponding to the input
     *
     * @param inputDate
*            String date to format
     * @return the formatted date
     */
    public static String getValue(String inputDate) throws ParseException {
        if (!isInitialized) {
            throw new IllegalStateException(
                    "Date formatter is not initialized");
        }

        Date date = inputFormat.parse(inputDate);
        calendar.setTime(date);
        return dateFormat.format(calendar.getTime());
    }
}

@@ -439,24 +439,76 @@
 d = false;%0D%0A
+    private static String currentDelimiter = null;%0D%0A
     private 
@@ -544,32 +544,32 @@
 Format = null;%0D%0A
-
     private stat
@@ -841,32 +841,65 @@
 f (isInitialized
+ && currentDelimiter == delimiter
 ) %7B%0D%0A           
@@ -967,32 +967,71 @@
 ;%0D%0A        %7D%0D%0A%0D%0A
+        currentDelimiter = delimiter;%0D%0A
         inputFor
@@ -1139,25 +1139,32 @@
 rmat(%22dd%22 + 
-d
+currentD
 elimiter + %22
@@ -1170,20 +1170,8 @@
 %22MM%22
- + delimiter
 %0D%0A  
@@ -1185,16 +1185,35 @@
        +
+ currentDelimiter +
  %22yyyy%22)

Allow specifying different delimiters in KpiCalculationDateFormatter.