org.dspace.app.bulkedit
Class DSpaceCSV

java.lang.Object
  extended by org.dspace.app.bulkedit.DSpaceCSV

public class DSpaceCSV
extends Object

Utility class to read and write CSV files

Author:
Stuart Lewis

Field Summary
protected static String escapedFieldSeparator
          The field separator in an escaped form for using in regexs
protected static String escpaedValueSeparator
          The value separator in an escaped form for using in regexs
protected static String fieldSeparator
          The field separator (defaults to comma)
protected static String valueSeparator
          The value separator (defaults to double pipe '||')
 
Constructor Summary
DSpaceCSV(boolean exportAll)
          Create a new instance of a CSV line holder
DSpaceCSV(File f)
          Create a new instance, reading the lines in from file
 
Method Summary
 void addItem(Item i)
          Add a DSpace item to the CSV file
 void addItem(String line)
          Add an item to the CSV file, from a CSV line of elements
 ArrayList<DSpaceCSVLine> getCSVLines()
          Get the lines in CSV holders
 String[] getCSVLinesAsStringArray()
          Get the CSV lines as an array of CSV formatted strings
static void main(String[] args)
          Test main method to check the marshalling and unmarshalling of strings in and out of CSV format
 void save(String filename)
          Save the CSV file to the given filename
 String toString()
          Return the csv file as one long formatted string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

valueSeparator

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


escpaedValueSeparator

protected static String escpaedValueSeparator
The value separator in an escaped form for using in regexs


fieldSeparator

protected static String fieldSeparator
The field separator (defaults to comma)


escapedFieldSeparator

protected static String escapedFieldSeparator
The field separator in an escaped form for using in regexs

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)
          throws Exception
Create a new instance, reading the lines in from file

Parameters:
f - The file to read from
Throws:
Exception - thrown if there is an error reading or processing the file
Method Detail

addItem

public 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 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 ArrayList<DSpaceCSVLine> getCSVLines()
Get the lines in CSV holders

Returns:
The lines

getCSVLinesAsStringArray

public String[] getCSVLinesAsStringArray()
Get the CSV lines as an array of CSV formatted strings

Returns:
the array of CSV formatted Strings

save

public 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

toString

public String toString()
Return the csv file as one long formatted string

Overrides:
toString in class Object
Returns:
The formatted String as a csv

main

public static void main(String[] args)
                 throws Exception
Test main method to check the marshalling and unmarshalling of strings in and out of CSV format

Parameters:
args - Not used
Throws:
Exception - Thrown if something goes wrong


Copyright © 2010 DuraSpace. All Rights Reserved.