mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 21:13:19 +00:00
[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:
@@ -141,9 +141,11 @@ public class DSpaceCSVLine
|
|||||||
*/
|
*/
|
||||||
protected String toCSV(ArrayList<String> headings)
|
protected String toCSV(ArrayList<String> headings)
|
||||||
{
|
{
|
||||||
|
StringBuilder bits = new StringBuilder();
|
||||||
|
|
||||||
// Add the id
|
// Add the id
|
||||||
String bits = "\"" + id + "\"" + DSpaceCSV.fieldSeparator;
|
bits.append("\"").append(id).append("\"").append(DSpaceCSV.fieldSeparator);
|
||||||
bits += valueToCSV(items.get("collection")) + DSpaceCSV.fieldSeparator;
|
bits.append(valueToCSV(items.get("collection"))).append(DSpaceCSV.fieldSeparator);
|
||||||
|
|
||||||
// Add the rest of the elements
|
// Add the rest of the elements
|
||||||
Iterator<String> i = headings.iterator();
|
Iterator<String> i = headings.iterator();
|
||||||
@@ -153,15 +155,15 @@ public class DSpaceCSVLine
|
|||||||
key = i.next();
|
key = i.next();
|
||||||
if ((items.get(key) != null) && (!"collection".equals(key)))
|
if ((items.get(key) != null) && (!"collection".equals(key)))
|
||||||
{
|
{
|
||||||
bits = bits + valueToCSV(items.get(key));
|
bits.append(valueToCSV(items.get(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i.hasNext())
|
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)
|
private String valueToCSV(ArrayList<String> values)
|
||||||
{
|
{
|
||||||
// Concatenate any fields together
|
|
||||||
String s = "";
|
|
||||||
|
|
||||||
// Check there is some content
|
// Check there is some content
|
||||||
if (values == null)
|
if (values == null)
|
||||||
{
|
{
|
||||||
return s;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get on with the work
|
// Get on with the work
|
||||||
if (values.size() == 1)
|
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();
|
Iterator i = values.iterator();
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
{
|
{
|
||||||
s = s + i.next();
|
str.append(i.next());
|
||||||
if (i.hasNext())
|
if (i.hasNext())
|
||||||
{
|
{
|
||||||
s = s + DSpaceCSV.valueSeparator;
|
str.append(DSpaceCSV.valueSeparator);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace internal quotes with two sets of quotes
|
// Replace internal quotes with two sets of quotes
|
||||||
s = s.replaceAll("\"", "\"\"");
|
return "\"" + str.toString().replaceAll("\"", "\"\"") + "\"";
|
||||||
|
|
||||||
// Wrap in quotes
|
|
||||||
s = "\"" + s + "\"";
|
|
||||||
|
|
||||||
// Return the csv formatted string
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -263,17 +263,18 @@ public class InstallItem
|
|||||||
Bitstream[] bitstreams = myitem.getNonInternalBitstreams();
|
Bitstream[] bitstreams = myitem.getNonInternalBitstreams();
|
||||||
|
|
||||||
// Create provenance description
|
// 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
|
// Add sizes and checksums of bitstreams
|
||||||
for (int j = 0; j < bitstreams.length; j++)
|
for (int j = 0; j < bitstreams.length; j++)
|
||||||
{
|
{
|
||||||
mymessage = mymessage + bitstreams[j].getName() + ": "
|
myMessage.append(bitstreams[j].getName()).append(": ")
|
||||||
+ bitstreams[j].getSize() + " bytes, checksum: "
|
.append(bitstreams[j].getSize()).append(" bytes, checksum: ")
|
||||||
+ bitstreams[j].getChecksum() + " ("
|
.append(bitstreams[j].getChecksum()).append(" (")
|
||||||
+ bitstreams[j].getChecksumAlgorithm() + ")\n";
|
.append(bitstreams[j].getChecksumAlgorithm()).append(")\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return mymessage;
|
return myMessage.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1781,20 +1781,28 @@ public class Item extends DSpaceObject
|
|||||||
*/
|
*/
|
||||||
public void withdraw() throws SQLException, AuthorizeException, IOException
|
public void withdraw() throws SQLException, AuthorizeException, IOException
|
||||||
{
|
{
|
||||||
String timestamp = DCDate.getCurrent().toString();
|
|
||||||
|
|
||||||
// Check permission. User either has to have REMOVE on owning collection
|
// Check permission. User either has to have REMOVE on owning collection
|
||||||
// or be COLLECTION_EDITOR of owning collection
|
// or be COLLECTION_EDITOR of owning collection
|
||||||
AuthorizeUtil.authorizeWithdrawItem(ourContext, this);
|
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.
|
// 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();
|
Collection[] colls = getCollections();
|
||||||
|
|
||||||
for (int i = 0; i < colls.length; i++)
|
for (int i = 0; i < colls.length; i++)
|
||||||
{
|
{
|
||||||
collectionProv = collectionProv + colls[i].getMetadata("name")
|
prov.append(colls[i].getMetadata("name")).append(" (ID: ").append(colls[i].getID()).append(")\n");
|
||||||
+ " (ID: " + colls[i].getID() + ")\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set withdrawn flag. timestamp will be set; last_modified in update()
|
// 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
|
// in_archive flag is now false
|
||||||
itemRow.setColumn("in_archive", false);
|
itemRow.setColumn("in_archive", false);
|
||||||
|
|
||||||
// Add suitable provenance - includes user, date, collections +
|
prov.append(InstallItem.getBitstreamProvenanceMessage(this));
|
||||||
// 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);
|
|
||||||
|
|
||||||
addDC("description", "provenance", "en", prov);
|
addDC("description", "provenance", "en", prov.toString());
|
||||||
|
|
||||||
// Update item in DB
|
// Update item in DB
|
||||||
update();
|
update();
|
||||||
@@ -1837,20 +1839,26 @@ public class Item extends DSpaceObject
|
|||||||
public void reinstate() throws SQLException, AuthorizeException,
|
public void reinstate() throws SQLException, AuthorizeException,
|
||||||
IOException
|
IOException
|
||||||
{
|
{
|
||||||
|
// check authorization
|
||||||
|
AuthorizeUtil.authorizeReinstateItem(ourContext, this);
|
||||||
|
|
||||||
String timestamp = DCDate.getCurrent().toString();
|
String timestamp = DCDate.getCurrent().toString();
|
||||||
|
|
||||||
// Check permission. User must have ADD on all collections.
|
// Check permission. User must have ADD on all collections.
|
||||||
// Build some provenance data while we're at it.
|
// Build some provenance data while we're at it.
|
||||||
String collectionProv = "";
|
|
||||||
Collection[] colls = getCollections();
|
Collection[] colls = getCollections();
|
||||||
|
|
||||||
// check authorization
|
// Add suitable provenance - includes user, date, collections +
|
||||||
AuthorizeUtil.authorizeReinstateItem(ourContext, this);
|
// 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++)
|
for (int i = 0; i < colls.length; i++)
|
||||||
{
|
{
|
||||||
collectionProv = collectionProv + colls[i].getMetadata("name")
|
prov.append(colls[i].getMetadata("name")).append(" (ID: ").append(colls[i].getID()).append(")\n");
|
||||||
+ " (ID: " + colls[i].getID() + ")\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear withdrawn flag
|
// Clear withdrawn flag
|
||||||
@@ -1861,13 +1869,9 @@ public class Item extends DSpaceObject
|
|||||||
|
|
||||||
// Add suitable provenance - includes user, date, collections +
|
// Add suitable provenance - includes user, date, collections +
|
||||||
// bitstream checksums
|
// bitstream checksums
|
||||||
EPerson e = ourContext.getCurrentUser();
|
prov.append(InstallItem.getBitstreamProvenanceMessage(this));
|
||||||
String prov = "Item reinstated by " + e.getFullName() + " ("
|
|
||||||
+ e.getEmail() + ") on " + timestamp + "\n"
|
|
||||||
+ "Item was in collections:\n" + collectionProv
|
|
||||||
+ InstallItem.getBitstreamProvenanceMessage(this);
|
|
||||||
|
|
||||||
addDC("description", "provenance", "en", prov);
|
addDC("description", "provenance", "en", prov.toString());
|
||||||
|
|
||||||
// Update item in DB
|
// Update item in DB
|
||||||
update();
|
update();
|
||||||
|
@@ -475,7 +475,7 @@ public class ConfigurationManager
|
|||||||
|
|
||||||
fileName += newsFile;
|
fileName += newsFile;
|
||||||
|
|
||||||
String text = "";
|
StringBuilder text = new StringBuilder();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -488,7 +488,7 @@ public class ConfigurationManager
|
|||||||
|
|
||||||
while ((lineIn = br.readLine()) != null)
|
while ((lineIn = br.readLine()) != null)
|
||||||
{
|
{
|
||||||
text += lineIn;
|
text.append(lineIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
@@ -498,7 +498,7 @@ public class ConfigurationManager
|
|||||||
warn("news_read: " + e.getLocalizedMessage());
|
warn("news_read: " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -493,7 +493,8 @@ public class Group extends DSpaceObject
|
|||||||
// yes, I know this could have been done as one big query and a union,
|
// 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!
|
// 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();
|
Iterator<Integer> i = groupIDs.iterator();
|
||||||
|
|
||||||
@@ -506,16 +507,16 @@ public class Group extends DSpaceObject
|
|||||||
|
|
||||||
parameters[idx++] = new Integer(groupID);
|
parameters[idx++] = new Integer(groupID);
|
||||||
|
|
||||||
groupQuery += "child_id= ? ";
|
groupQuery.append("child_id= ? ");
|
||||||
if (i.hasNext())
|
if (i.hasNext())
|
||||||
groupQuery += " OR ";
|
groupQuery.append(" OR ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// was member of at least one group
|
// was member of at least one group
|
||||||
// NOTE: even through the query is built dynamically, all data is
|
// NOTE: even through the query is built dynamically, all data is
|
||||||
// separated into the parameters array.
|
// separated into the parameters array.
|
||||||
TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
|
TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
|
||||||
"SELECT * FROM group2groupcache WHERE " + groupQuery,
|
groupQuery.toString(),
|
||||||
parameters);
|
parameters);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -622,25 +623,29 @@ public class Group extends DSpaceObject
|
|||||||
|
|
||||||
// don't forget to add the current group to this query!
|
// don't forget to add the current group to this query!
|
||||||
parameters[idx++] = new Integer(g.getID());
|
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())
|
if (i.hasNext())
|
||||||
epersonQuery += " OR ";
|
epersonQuery.append(" OR ");
|
||||||
|
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
{
|
{
|
||||||
int groupID = (i.next()).intValue();
|
int groupID = (i.next()).intValue();
|
||||||
parameters[idx++] = new Integer(groupID);
|
parameters[idx++] = new Integer(groupID);
|
||||||
|
|
||||||
epersonQuery += "eperson_group_id= ? ";
|
epersonQuery.append("eperson_group_id= ? ");
|
||||||
if (i.hasNext())
|
if (i.hasNext())
|
||||||
epersonQuery += " OR ";
|
epersonQuery.append(" OR ");
|
||||||
}
|
}
|
||||||
|
|
||||||
//get all the EPerson IDs
|
//get all the EPerson IDs
|
||||||
// Note: even through the query is dynamically built all data is separated
|
// Note: even through the query is dynamically built all data is separated
|
||||||
// into the parameters array.
|
// into the parameters array.
|
||||||
tri = DatabaseManager.queryTable(c, "epersongroup2eperson",
|
tri = DatabaseManager.queryTable(c, "epersongroup2eperson",
|
||||||
"SELECT * FROM epersongroup2eperson WHERE " + epersonQuery,
|
epersonQuery.toString(),
|
||||||
parameters);
|
parameters);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
Reference in New Issue
Block a user