@Test public void testDSpaceCSV() { try { String[] csv = {"id,collection,\"dc.title[en]\",dc.contributor.author,dc.description.abstract", "1,2,Easy line,\"Lewis, Stuart\",A nice short abstract", "2,2,Two authors,\"Lewis, Stuart||Bloggs, Joe\",Two people wrote this item", "3,2,Three authors,\"Lewis, Stuart||Bloggs, Joe||Loaf, Meat\",Three people wrote this item", "4,2,\"Two line\ntitle\",\"Lewis, Stuart\",abstract", "5,2,\"\"\"Embedded quotes\"\" here\",\"Lewis, Stuart\",\"Abstract with\ntwo\nnew lines\"", "6,2,\"\"\"Unbalanced embedded\"\" quotes\"\" here\",\"Lewis, Stuart\",\"Abstract with\ntwo\nnew lines\"",}; String filename = "test.csv"; BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(filename), "UTF-8")); for (String csvLine : csv) { out.write(csvLine + "\n"); } out.flush(); out.close(); Context c = new Context(); DSpaceCSV dcsv = new DSpaceCSV(new File(filename), c); String[] lines = dcsv.getCSVLinesAsStringArray(); assertThat("testDSpaceCSV Good CSV", lines.length, equalTo(7)); 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\"")); csv[0] = "id,collection,\"dc.title[en]\",dc.contributor.foobar[en-US],dc.description.abstract"; filename = "test.csv"; out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(filename), "UTF-8")); for (String csvLine : csv) { out.write(csvLine + "\n"); } out.flush(); out.close(); try { dcsv = new DSpaceCSV(new File(filename), c); lines = dcsv.getCSVLinesAsStringArray(); fail("An exception should have been thrown due to bad CSV"); } catch (Exception e) { assertThat("testDSpaceCSV Bad heading CSV", e.getMessage(), equalTo("Unknown metadata element in row 4: dc.contributor.foobar")); } lines = dcsv.getCSVLinesAsStringArray(); assertThat("testDSpaceCSV Good CSV", lines.length, equalTo(7)); csv[0] = "id,collection,\"dcdc.title[en]\",dc.contributor[en-US],dc.description.abstract"; filename = "test.csv"; out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(filename), "UTF-8")); for (String csvLine : csv) { out.write(csvLine + "\n"); } out.flush(); out.close(); try { dcsv = new DSpaceCSV(new File(filename), c); lines = dcsv.getCSVLinesAsStringArray(); fail("An exception should have been thrown due to bad CSV"); } catch (Exception e) { assertThat("testDSpaceCSV Bad heading CSV", e.getMessage(), equalTo("Unknown metadata schema in row 3: dcdc.title")); } File toDelete = new File(filename); toDelete.delete(); } catch (Exception ex) { log.error("IO Error while creating test CSV file", ex); fail("IO Error while creating test CSV file"); } }
public DSpaceCSV(boolean exportAll) { init(); this.exportAll = exportAll; }
DSpaceCSV implements Serializable { public DSpaceCSV(boolean exportAll) { init(); this.exportAll = exportAll; } }
DSpaceCSV implements Serializable { public DSpaceCSV(boolean exportAll) { init(); this.exportAll = exportAll; } DSpaceCSV(boolean exportAll);  DSpaceCSV(File f, Context c); }
DSpaceCSV implements Serializable { public DSpaceCSV(boolean exportAll) { init(); this.exportAll = exportAll; } DSpaceCSV(boolean exportAll);  DSpaceCSV(File f, Context c); boolean hasActions(); final void addItem(Item i); final void addItem(String line); final List<DSpaceCSVLine> getCSVLines(); final String[] getCSVLinesAsStringArray(); final void save(String filename); List<String> getHeadings(); final String toString(); }
DSpaceCSV implements Serializable { public DSpaceCSV(boolean exportAll) { init(); this.exportAll = exportAll; } DSpaceCSV(boolean exportAll);  DSpaceCSV(File f, Context c); boolean hasActions(); final void addItem(Item i); final void addItem(String line); final List<DSpaceCSVLine> getCSVLines(); final String[] getCSVLinesAsStringArray(); final void save(String filename); List<String> getHeadings(); final String toString();  }