Package org.dspace.app.bulkedit
Class DSpaceCSV
java.lang.Object
org.dspace.app.bulkedit.DSpaceCSV
- All Implemented Interfaces:
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe authority separator (defaults to double colon '::')protected final AuthorityValueServiceprotected intA counter of how many CSV lines this object holdsprotected StringThe authority separator in an escaped form for using in regexesprotected StringThe field separator in an escaped form for using in regexesprotected StringThe value separator in an escaped form for using in regexesprotected booleanWhether to export all metadata such as handles and provenance informationprotected StringThe field separator (defaults to comma)The headings of the CSV fileA list of metadata elements to ignoreprotected final ItemServiceprotected List<DSpaceCSVLine>An array list of CSV linesprotected final MetadataFieldServiceprotected final MetadataSchemaServiceprotected StringThe value separator (defaults to double pipe '||') -
Constructor Summary
ConstructorsConstructorDescriptionDSpaceCSV(boolean exportAll) Create a new instance of a CSV line holderDSpaceCSV(InputStream inputStream, Context c) Create a new instance, reading the lines in from file -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd an item to the CSV file, from a CSV line of elementsfinal voidAdd a DSpace item to the CSV filefinal List<DSpaceCSVLine>Get the lines in CSV holdersfinal String[]Get the CSV lines as an array of CSV formatted stringsGet the headings used in this CSV fileCreates and returns an InputStream from the CSV Lines in this DSpaceCSVbooleanDecide if this CSV file has an 'action' (case-dependent!)protected voidinit()Initialise this class with values from dspace.cfgprotected booleanIs it okay to export this value?final StringtoString()Return the csv file as one long formatted string
-
Field Details
-
headings
The headings of the CSV file -
lines
An array list of CSV lines -
counter
protected int counterA counter of how many CSV lines this object holds -
valueSeparator
The value separator (defaults to double pipe '||') -
escapedValueSeparator
The value separator in an escaped form for using in regexes -
fieldSeparator
The field separator (defaults to comma) -
escapedFieldSeparator
The field separator in an escaped form for using in regexes -
authoritySeparator
The authority separator (defaults to double colon '::') -
escapedAuthoritySeparator
The authority separator in an escaped form for using in regexes -
itemService
-
metadataSchemaService
-
metadataFieldService
-
authorityValueService
-
exportAll
protected boolean exportAllWhether to export all metadata such as handles and provenance information -
ignore
A list of metadata elements to ignore
-
-
Constructor Details
-
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
Create a new instance, reading the lines in from file- Parameters:
inputStream- the input stream to read fromc- The DSpace Context- Throws:
Exception- thrown if there is an error reading or processing the file
-
-
Method Details
-
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
Add a DSpace item to the CSV file- Parameters:
i- The DSpace item- Throws:
Exception- if something goes wrong with adding the Item
-
addItem
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
Get the lines in CSV holders- Returns:
- The lines
-
getCSVLinesAsStringArray
Get the CSV lines as an array of CSV formatted strings- Returns:
- the array of CSV formatted Strings
-
getInputStream
Creates and returns an InputStream from the CSV Lines in this DSpaceCSV- Returns:
- The InputStream created from the CSVLines in this DSpaceCSV
-
okToExport
Is it okay 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 inbulkedit.cfg.- Parameters:
md- The MetadataField to examine- Returns:
- Whether or not it is OK to export this element
-
getHeadings
Get the headings used in this CSV file- Returns:
- The headings
-
toString
Return the csv file as one long formatted string -
getAuthoritySeparator
-
getEscapedAuthoritySeparator
-