sets.add(communitySpec);   Collection[] colls = allComms[i].getCollections();  for (int j = 0; j < colls.length; j++) { StringBuffer collectionSpec = new StringBuffer("<set><setSpec>");  collectionSpec.append(allComms[i].getID()) .append(":") .append(colls[j].getID()) .append("</setSpec><setName>") .append(colls[j].getMetadata("name")) .append("</setName></set>");  sets.add(collectionSpec.toString()); }
sets.add(spec);
    public Map listSets()        throws NoSetHierarchyException, OAIInternalServerError    {        log.info(LogManager.getHeader(null,            "oai_request",            "verb=listSets"));        Context context = null;        // List to put results in        List sets = new LinkedList();        try        {            context = new Context();            // FIXME: This may break the OAI protocol with multiple inclusion            // FIXME: Should check perms?            Community[] allComms = Community.findAll(context);            for (int i = 0; i < allComms.length; i++)            {                // Set XML community                String communitySpec = "<set><setSpec>" + allComms[i].getID() +                    "</setSpec><setName>" + allComms[i].getMetadata("name") +                    "</setName></set>";                sets.add(communitySpec);                // Add set XML for collections                Collection[] colls = allComms[i].getCollections();                for (int j = 0; j < colls.length; j++)                {                    StringBuffer collectionSpec =                        new StringBuffer("<set><setSpec>");                                        collectionSpec.append(allComms[i].getID())                        .append(":")                        .append(colls[j].getID())                        .append("</setSpec><setName>")                        .append(colls[j].getMetadata("name"))                        .append("</setName></set>");                                        sets.add(collectionSpec.toString());                }            }        }        catch (SQLException se)        {            // Log the error            log.warn(LogManager.getHeader(context,                "database_error",                ""), se);            throw new OAIInternalServerError(se.toString());        }        finally        {            if (context != null)            {                context.abort();            }        }                // Put results in form needed to return        Map results = new HashMap();        results.put("sets", sets.iterator());        return results;    }