Class CSVTool

  • All Implemented Interfaces:
    java.io.Serializable

    public class CSVTool
    extends java.lang.Object
    implements java.io.Serializable
    CSV toolbox
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      CSVTool​(char separator, char quote)
      Constructor: CSV tool (parser, ...)
      CSVTool​(char separator, char quote, java.lang.String cr)
      Constructor: CSV tool (parser, ...)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String csvHeader​(ObjectCore obj)
      Generates CSV header for object
      static void cvsToObject​(ObjectCore obj, java.lang.String csv)
      Converts CSV message into object fields
      static void cvsToObjectFilters​(ObjectCore obj, java.lang.String csv)
      Converts CSV message into object filters
      static boolean isFormVisible​(boolean full, ObjectCore obj, ObjectField f)
      Is field visible for CSV export in a single record context
      static boolean isListVisible​(boolean full, ObjectCore obj, ObjectField f)
      Is field visible for CSV export in a multiple records context
      static java.lang.String objectListItemToCsv​(ObjectCore obj, java.lang.String[] vals)
      Converts object list into CSV
      static java.lang.String objectToCsv​(ObjectCore obj)
      Converts object fields into CSV
      static java.lang.String objectToCSV​(ObjectCore obj, java.util.List<java.lang.String[]> rows, java.lang.String mode, java.lang.String sep, java.lang.String quote, boolean tech)
      Export to CSV
      java.lang.String[] parse​(java.lang.String line)
      Parse CSV string into string array
      java.lang.String[] parse​(java.lang.String line, boolean trim)
      Parse CSV string into string array
      java.lang.String serialize​(java.lang.String[] fields)
      Serialize string array into CSV string
      java.lang.String serialize​(java.util.List<java.lang.String> fields)
      Serialize string list into CSV string
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CSVTool

        public CSVTool​(char separator,
                       char quote,
                       java.lang.String cr)
        Constructor: CSV tool (parser, ...)
        Parameters:
        separator - Separator (e.g. ,)
        quote - Quote character (e.g. ")
        cr - Carriage return substitution (e.g. "%CR%"), can be a regular expression
      • CSVTool

        public CSVTool​(char separator,
                       char quote)
        Constructor: CSV tool (parser, ...)
        Parameters:
        separator - Separator (e.g. ,)
        quote - Quote character (e.g. ")
    • Method Detail

      • parse

        public java.lang.String[] parse​(java.lang.String line)
        Parse CSV string into string array
        Parameters:
        line - Input CSV string
        Returns:
        Array of strings
      • parse

        public java.lang.String[] parse​(java.lang.String line,
                                        boolean trim)
        Parse CSV string into string array
        Parameters:
        line - Input CSV string
        trim - Trim values
        Returns:
        Array of strings
      • serialize

        public java.lang.String serialize​(java.lang.String[] fields)
        Serialize string array into CSV string
        Parameters:
        fields - String array
        Returns:
        CSV string
      • serialize

        public java.lang.String serialize​(java.util.List<java.lang.String> fields)
        Serialize string list into CSV string
        Parameters:
        fields - String list
        Returns:
        CSV string
      • csvHeader

        public static java.lang.String csvHeader​(ObjectCore obj)
        Generates CSV header for object
        Parameters:
        obj - Object
        Returns:
        CSV headers
      • objectToCsv

        public static java.lang.String objectToCsv​(ObjectCore obj)
        Converts object fields into CSV
        Parameters:
        obj - Object
        Returns:
        CSV data
      • cvsToObject

        public static void cvsToObject​(ObjectCore obj,
                                       java.lang.String csv)
        Converts CSV message into object fields
        Parameters:
        obj - Object
        csv - CSV message (header + data)
      • cvsToObjectFilters

        public static void cvsToObjectFilters​(ObjectCore obj,
                                              java.lang.String csv)
        Converts CSV message into object filters
        Parameters:
        obj - Object
        csv - CSV message (header + filter data)
      • objectListItemToCsv

        public static java.lang.String objectListItemToCsv​(ObjectCore obj,
                                                           java.lang.String[] vals)
        Converts object list into CSV
        Parameters:
        obj - Object
        vals - List item data
        Returns:
        CSV data
      • isListVisible

        public static boolean isListVisible​(boolean full,
                                            ObjectCore obj,
                                            ObjectField f)
        Is field visible for CSV export in a multiple records context
        Parameters:
        full - Full mode?
        obj - Object
        f - Field
        Returns:
        true if field is visible in a multiple records context
      • isFormVisible

        public static boolean isFormVisible​(boolean full,
                                            ObjectCore obj,
                                            ObjectField f)
        Is field visible for CSV export in a single record context
        Parameters:
        full - Full mode?
        obj - Object
        f - Field
        Returns:
        true if field is visible in a single record context
      • objectToCSV

        public static java.lang.String objectToCSV​(ObjectCore obj,
                                                   java.util.List<java.lang.String[]> rows,
                                                   java.lang.String mode,
                                                   java.lang.String sep,
                                                   java.lang.String quote,
                                                   boolean tech)
        Export to CSV
        Parameters:
        obj - Object
        rows - Records
        mode - Full or list
        sep - Columns separator (default ;)
        quote - Quote (default ")
        tech - Technical fields
        Returns:
        CSV data