[DS-707] String concatenation

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5499 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Graham Triggs
2010-10-20 21:38:52 +00:00
parent 703944d4bf
commit c17cbc0029
5 changed files with 73 additions and 69 deletions

View File

@@ -141,9 +141,11 @@ public class DSpaceCSVLine
*/
protected String toCSV(ArrayList<String> headings)
{
StringBuilder bits = new StringBuilder();
// Add the id
String bits = "\"" + id + "\"" + DSpaceCSV.fieldSeparator;
bits += valueToCSV(items.get("collection")) + DSpaceCSV.fieldSeparator;
bits.append("\"").append(id).append("\"").append(DSpaceCSV.fieldSeparator);
bits.append(valueToCSV(items.get("collection"))).append(DSpaceCSV.fieldSeparator);
// Add the rest of the elements
Iterator<String> i = headings.iterator();
@@ -153,15 +155,15 @@ public class DSpaceCSVLine
key = i.next();
if ((items.get(key) != null) && (!"collection".equals(key)))
{
bits = bits + valueToCSV(items.get(key));
bits.append(valueToCSV(items.get(key)));
}
if (i.hasNext())
{
bits = bits + DSpaceCSV.fieldSeparator;
bits.append(DSpaceCSV.fieldSeparator);
}
}
return bits;
return bits.toString();
}
/**
@@ -172,41 +174,33 @@ public class DSpaceCSVLine
*/
private String valueToCSV(ArrayList<String> values)
{
// Concatenate any fields together
String s = "";
// Check there is some content
if (values == null)
{
return s;
return "";
}
// Get on with the work
if (values.size() == 1)
{
s = values.get(0);
return values.get(0);
}
else
{
// Concatenate any fields together
StringBuilder str = new StringBuilder();
Iterator i = values.iterator();
while (i.hasNext())
{
s = s + i.next();
str.append(i.next());
if (i.hasNext())
{
s = s + DSpaceCSV.valueSeparator;
}
str.append(DSpaceCSV.valueSeparator);
}
}
// Replace internal quotes with two sets of quotes
s = s.replaceAll("\"", "\"\"");
// Wrap in quotes
s = "\"" + s + "\"";
// Return the csv formatted string
return s;
return "\"" + str.toString().replaceAll("\"", "\"\"") + "\"";
}
}

View File

@@ -263,17 +263,18 @@ public class InstallItem
Bitstream[] bitstreams = myitem.getNonInternalBitstreams();
// Create provenance description
String mymessage = "No. of bitstreams: " + bitstreams.length + "\n";
StringBuilder myMessage = new StringBuilder();
myMessage.append("No. of bitstreams: ").append(bitstreams.length).append("\n");
// Add sizes and checksums of bitstreams
for (int j = 0; j < bitstreams.length; j++)
{
mymessage = mymessage + bitstreams[j].getName() + ": "
+ bitstreams[j].getSize() + " bytes, checksum: "
+ bitstreams[j].getChecksum() + " ("
+ bitstreams[j].getChecksumAlgorithm() + ")\n";
myMessage.append(bitstreams[j].getName()).append(": ")
.append(bitstreams[j].getSize()).append(" bytes, checksum: ")
.append(bitstreams[j].getChecksum()).append(" (")
.append(bitstreams[j].getChecksumAlgorithm()).append(")\n");
}
return mymessage;
return myMessage.toString();
}
}

View File

@@ -1781,20 +1781,28 @@ public class Item extends DSpaceObject
*/
public void withdraw() throws SQLException, AuthorizeException, IOException
{
String timestamp = DCDate.getCurrent().toString();
// Check permission. User either has to have REMOVE on owning collection
// or be COLLECTION_EDITOR of owning collection
AuthorizeUtil.authorizeWithdrawItem(ourContext, this);
String timestamp = DCDate.getCurrent().toString();
// Add suitable provenance - includes user, date, collections +
// bitstream checksums
EPerson e = ourContext.getCurrentUser();
// Build some provenance data while we're at it.
String collectionProv = "";
StringBuilder prov = new StringBuilder();
prov.append("Item withdrawn by ").append(e.getFullName()).append(" (")
.append(e.getEmail()).append(") on ").append(timestamp).append("\n")
.append("Item was in collections:\n");
Collection[] colls = getCollections();
for (int i = 0; i < colls.length; i++)
{
collectionProv = collectionProv + colls[i].getMetadata("name")
+ " (ID: " + colls[i].getID() + ")\n";
prov.append(colls[i].getMetadata("name")).append(" (ID: ").append(colls[i].getID()).append(")\n");
}
// Set withdrawn flag. timestamp will be set; last_modified in update()
@@ -1803,15 +1811,9 @@ public class Item extends DSpaceObject
// in_archive flag is now false
itemRow.setColumn("in_archive", false);
// Add suitable provenance - includes user, date, collections +
// bitstream checksums
EPerson e = ourContext.getCurrentUser();
String prov = "Item withdrawn by " + e.getFullName() + " ("
+ e.getEmail() + ") on " + timestamp + "\n"
+ "Item was in collections:\n" + collectionProv
+ InstallItem.getBitstreamProvenanceMessage(this);
prov.append(InstallItem.getBitstreamProvenanceMessage(this));
addDC("description", "provenance", "en", prov);
addDC("description", "provenance", "en", prov.toString());
// Update item in DB
update();
@@ -1837,20 +1839,26 @@ public class Item extends DSpaceObject
public void reinstate() throws SQLException, AuthorizeException,
IOException
{
// check authorization
AuthorizeUtil.authorizeReinstateItem(ourContext, this);
String timestamp = DCDate.getCurrent().toString();
// Check permission. User must have ADD on all collections.
// Build some provenance data while we're at it.
String collectionProv = "";
Collection[] colls = getCollections();
// check authorization
AuthorizeUtil.authorizeReinstateItem(ourContext, this);
// Add suitable provenance - includes user, date, collections +
// bitstream checksums
EPerson e = ourContext.getCurrentUser();
StringBuilder prov = new StringBuilder();
prov.append("Item reinstated by ").append(e.getFullName()).append(" (")
.append(e.getEmail()).append(") on ").append(timestamp).append("\n")
.append("Item was in collections:\n");
for (int i = 0; i < colls.length; i++)
{
collectionProv = collectionProv + colls[i].getMetadata("name")
+ " (ID: " + colls[i].getID() + ")\n";
prov.append(colls[i].getMetadata("name")).append(" (ID: ").append(colls[i].getID()).append(")\n");
}
// Clear withdrawn flag
@@ -1861,13 +1869,9 @@ public class Item extends DSpaceObject
// Add suitable provenance - includes user, date, collections +
// bitstream checksums
EPerson e = ourContext.getCurrentUser();
String prov = "Item reinstated by " + e.getFullName() + " ("
+ e.getEmail() + ") on " + timestamp + "\n"
+ "Item was in collections:\n" + collectionProv
+ InstallItem.getBitstreamProvenanceMessage(this);
prov.append(InstallItem.getBitstreamProvenanceMessage(this));
addDC("description", "provenance", "en", prov);
addDC("description", "provenance", "en", prov.toString());
// Update item in DB
update();

View File

@@ -475,7 +475,7 @@ public class ConfigurationManager
fileName += newsFile;
String text = "";
StringBuilder text = new StringBuilder();
try
{
@@ -488,7 +488,7 @@ public class ConfigurationManager
while ((lineIn = br.readLine()) != null)
{
text += lineIn;
text.append(lineIn);
}
br.close();
@@ -498,7 +498,7 @@ public class ConfigurationManager
warn("news_read: " + e.getLocalizedMessage());
}
return text;
return text.toString();
}
/**

View File

@@ -493,7 +493,8 @@ public class Group extends DSpaceObject
// yes, I know this could have been done as one big query and a union,
// but doing the Oracle port taught me to keep to simple SQL!
String groupQuery = "";
StringBuilder groupQuery = new StringBuilder();
groupQuery.append("SELECT * FROM group2groupcache WHERE ");
Iterator<Integer> i = groupIDs.iterator();
@@ -506,16 +507,16 @@ public class Group extends DSpaceObject
parameters[idx++] = new Integer(groupID);
groupQuery += "child_id= ? ";
groupQuery.append("child_id= ? ");
if (i.hasNext())
groupQuery += " OR ";
groupQuery.append(" OR ");
}
// was member of at least one group
// NOTE: even through the query is built dynamically, all data is
// separated into the parameters array.
TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
"SELECT * FROM group2groupcache WHERE " + groupQuery,
groupQuery.toString(),
parameters);
try
@@ -622,25 +623,29 @@ public class Group extends DSpaceObject
// don't forget to add the current group to this query!
parameters[idx++] = new Integer(g.getID());
String epersonQuery = "eperson_group_id= ? ";
StringBuilder epersonQuery = new StringBuilder();
epersonQuery.append("SELECT * FROM epersongroup2eperson WHERE ");
epersonQuery.append("eperson_group_id= ? ");
if (i.hasNext())
epersonQuery += " OR ";
epersonQuery.append(" OR ");
while (i.hasNext())
{
int groupID = (i.next()).intValue();
parameters[idx++] = new Integer(groupID);
epersonQuery += "eperson_group_id= ? ";
epersonQuery.append("eperson_group_id= ? ");
if (i.hasNext())
epersonQuery += " OR ";
epersonQuery.append(" OR ");
}
//get all the EPerson IDs
// Note: even through the query is dynamically built all data is separated
// into the parameters array.
tri = DatabaseManager.queryTable(c, "epersongroup2eperson",
"SELECT * FROM epersongroup2eperson WHERE " + epersonQuery,
epersonQuery.toString(),
parameters);
try