Class DSpaceCSV

  • All Implemented Interfaces:
    Serializable

    public class DSpaceCSV
    extends Object
    implements Serializable
    Utility class to read and write CSV files ************** Important Note ************** This class has been made serializable, as it is stored in a Session. Is it wise to: a) be putting this into a user's session? b) holding an entire CSV upload in memory?
    Author:
    Stuart Lewis
    See Also:
    Serialized Form
    • Field Detail

      • headings

        protected List<String> headings
        The headings of the CSV file
      • counter

        protected int counter
        A counter of how many CSV lines this object holds
      • valueSeparator

        protected String valueSeparator
        The value separator (defaults to double pipe '||')
      • escapedValueSeparator

        protected String escapedValueSeparator
        The value separator in an escaped form for using in regexes
      • fieldSeparator

        protected String fieldSeparator
        The field separator (defaults to comma)
      • escapedFieldSeparator

        protected String escapedFieldSeparator
        The field separator in an escaped form for using in regexes
      • authoritySeparator

        protected String authoritySeparator
        The authority separator (defaults to double colon '::')
      • escapedAuthoritySeparator

        protected String escapedAuthoritySeparator
        The authority separator in an escaped form for using in regexes
      • itemService

        protected final transient ItemService itemService
      • exportAll

        protected boolean exportAll
        Whether to export all metadata such as handles and provenance information
      • ignore

        protected Map<String,​String> ignore
        A list of metadata elements to ignore
    • Constructor Detail

      • DSpaceCSV

        public DSpaceCSV​(boolean exportAll)
        Create a new instance of a CSV line holder
        Parameters:
        exportAll - Whether to export all metadata such as handles and provenance information
      • DSpaceCSV

        public DSpaceCSV​(File f,
                         Context c)
                  throws Exception
        Create a new instance, reading the lines in from file
        Parameters:
        f - The file to read from
        c - The DSpace Context
        Throws:
        Exception - thrown if there is an error reading or processing the file
    • Method Detail

      • init

        protected void init()
        Initialise this class with values from dspace.cfg
      • hasActions

        public boolean hasActions()
        Decide if this CSV file has an 'action' (case-dependent!) header.
        Returns:
        Whether or not there is an 'action' header
      • addItem

        public final void addItem​(Item i)
                           throws Exception
        Add a DSpace item to the CSV file
        Parameters:
        i - The DSpace item
        Throws:
        Exception - if something goes wrong with adding the Item
      • addItem

        public final void addItem​(String line)
                           throws Exception
        Add an item to the CSV file, from a CSV line of elements
        Parameters:
        line - The line of elements
        Throws:
        Exception - Thrown if an error occurs when adding the item
      • getCSVLines

        public final List<DSpaceCSVLine> getCSVLines()
        Get the lines in CSV holders
        Returns:
        The lines
      • getCSVLinesAsStringArray

        public final String[] getCSVLinesAsStringArray()
        Get the CSV lines as an array of CSV formatted strings
        Returns:
        the array of CSV formatted Strings
      • save

        public final void save​(String filename)
                        throws IOException
        Save the CSV file to the given filename
        Parameters:
        filename - The filename to save the CSV file to
        Throws:
        IOException - Thrown if an error occurs when writing the file
      • okToExport

        protected boolean okToExport​(MetadataField md)
        Is it Ok to export this value? When exportAll is set to false, we don't export some of the metadata elements. The list can be configured via the key ignore-on-export in bulkedit.cfg
        Parameters:
        md - The Metadatum to examine
        Returns:
        Whether or not it is OK to export this element
      • getHeadings

        public List<String> getHeadings()
        Get the headings used in this CSV file
        Returns:
        The headings
      • toString

        public final String toString()
        Return the csv file as one long formatted string
        Overrides:
        toString in class Object
        Returns:
        The formatted String as a csv
      • getAuthoritySeparator

        public String getAuthoritySeparator()
      • getEscapedAuthoritySeparator

        public String getEscapedAuthoritySeparator()