[Cosmo-dev] Re: [commits-cosmo] (br) [2474] making save work.

Brian Moseley bcm at osafoundation.org
Tue Sep 12 18:05:14 PDT 2006


On 9/12/06, svncheckin at osafoundation.org <svncheckin at osafoundation.org> wrote:

> + private String findAvailableName(String calendarPath, VEvent vevent)
> throws RPCException{
> + char[] chars = {'0', '1', '2', '3', '4', '5', '6', '6', '8', '9'};
> + StringBuffer baseName = new StringBuffer(vevent.getUid().getValue())
> + .append(".ics");
> + int index = baseName.length() - 4;
> + int count = 0;
> + boolean foundAGoodName = false;
> +
> + while (!foundAGoodName && count < 10) {
> + if (count == 1){
> + baseName.insert(index, '0');
> + } else if (count > 1){
> + baseName.setCharAt(index, chars[count]);
> + }
> + if (contentService.findItemByPath(getAbsolutePath(calendarPath
> + + "/" + baseName.toString())) == null) {
> + foundAGoodName = true;
> + }
> + count++;
> + }
> +
> + if (!foundAGoodName){
> + throw new RPCException("Could not find a suitable name for event!");
> + }
> +
> + return baseName.toString();
> + }

not a big fan of this method. ContentService.findItemByPath is
expensive, because we have to resolve the path by walking the tree of
items in the database.

you're generating an icalendar uid for the event somewhere, right?
that's guaranteed to be unique within the calendar collection (and
depending on how you generate the uid, unique in the universe). why
not make the name of the item <uid>.ics? this mirrors what chandler
and likely many other clients do.


More information about the cosmo-dev mailing list