mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
[DS-753] Fix CSV parsing that got broken by refactoring
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5864 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -578,6 +578,16 @@ public class DSpaceCSV implements Serializable
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headings used in this CSV file
|
||||
*
|
||||
* @return The headings
|
||||
*/
|
||||
public List<String> getHeadings()
|
||||
{
|
||||
return headings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the csv file as one long formatted string
|
||||
*
|
||||
|
@@ -143,7 +143,7 @@ public class DSpaceCSVLine
|
||||
* @param values The values to create the string from
|
||||
* @return The line as a CSV formatted String
|
||||
*/
|
||||
private String valueToCSV(List<String> values)
|
||||
protected String valueToCSV(List<String> values)
|
||||
{
|
||||
// Check there is some content
|
||||
if (values == null)
|
||||
@@ -152,26 +152,30 @@ public class DSpaceCSVLine
|
||||
}
|
||||
|
||||
// Get on with the work
|
||||
String s = "";
|
||||
if (values.size() == 1)
|
||||
{
|
||||
return values.get(0);
|
||||
s = values.get(0);
|
||||
}
|
||||
|
||||
// Concatenate any fields together
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
Iterator i = values.iterator();
|
||||
while (i.hasNext())
|
||||
else
|
||||
{
|
||||
str.append(i.next());
|
||||
if (i.hasNext())
|
||||
// Concatenate any fields together
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
Iterator i = values.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
str.append(DSpaceCSV.valueSeparator);
|
||||
str.append(i.next());
|
||||
if (i.hasNext())
|
||||
{
|
||||
str.append(DSpaceCSV.valueSeparator);
|
||||
}
|
||||
}
|
||||
s = str.toString();
|
||||
}
|
||||
|
||||
// Replace internal quotes with two sets of quotes
|
||||
return "\"" + str.toString().replaceAll("\"", "\"\"") + "\"";
|
||||
return "\"" + s.replaceAll("\"", "\"\"") + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,8 @@
|
||||
package org.dspace.app.bulkedit;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.dspace.core.Context;
|
||||
@@ -88,7 +90,14 @@ public class DSpaceCSVTest extends AbstractUnitTest
|
||||
DSpaceCSV dcsv = new DSpaceCSV(new File(filename), c);
|
||||
String[] lines = dcsv.getCSVLinesAsStringArray();
|
||||
assertThat("testDSpaceCSV Good CSV", lines.length, equalTo(7));
|
||||
|
||||
|
||||
// Check the new lines are OK
|
||||
List<DSpaceCSVLine> csvLines = dcsv.getCSVLines();
|
||||
DSpaceCSVLine line = csvLines.get(5);
|
||||
List<String> value = new ArrayList<String>();
|
||||
value.add("Abstract with\ntwo\nnew lines");
|
||||
assertThat("testDSpaceCSV New lines", line.valueToCSV(value),
|
||||
equalTo("\"Abstract with\ntwo\nnew lines\""));
|
||||
|
||||
// Test the CSV parsing with a bad heading element value
|
||||
csv[0] = "id,collection,\"dc.title[en]\",dc.contributor.foobar[en-US],dc.description.abstract";
|
||||
|
Reference in New Issue
Block a user