Skip to content

Commit

Permalink
SAK-18086: Error clicking on item imported from iCal feed
Browse files Browse the repository at this point in the history
git-svn-id: https://source.sakaiproject.org/svn/calendar/trunk@80794 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
nfgrilo committed Aug 4, 2010
1 parent 9bfd705 commit 5946181
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -1142,13 +1144,37 @@ protected String getUniqueIdBasedOnFields(String displayName, String description
boolean unique = false;
while (!unique)
{
byte[] encoded = CommonsCodecBase64.encodeBase64(key.getBytes());
key += n++;
id = new String(encoded);
byte[] bytes = key.getBytes();
try{
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.update(bytes);
bytes = digest.digest();
id = getHexStringFromBytes(bytes);
}catch(NoSuchAlgorithmException e){
// fall back to Base64
byte[] encoded = CommonsCodecBase64.encodeBase64(bytes);
id = new String(encoded);
}
if (!m_storage.containsKey(id)) unique = true;
else key += n++;
}
return id;
}

protected String getHexStringFromBytes(byte[] raw)
{
final String HEXES = "0123456789ABCDEF";
if(raw == null)
{
return null;
}
final StringBuilder hex = new StringBuilder(2 * raw.length);
for(final byte b : raw)
{
hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
}
return hex.toString();
}

/**
* Filter the events to only those in the time range.
Expand Down

0 comments on commit 5946181

Please sign in to comment.