while (tok.hasMoreTokens()) { temp = tok.nextToken(); path = path + "/" + temp; if (current.hasSubcollection(temp)) current = getCollection(path); else { if (!current.getPermissions().validate(user, Permission.WRITE)) throw new PermissionDeniedException("not allowed to write to collection"); LOG.debug("creating collection " + path); sub = new Collection(this, path); sub.getPermissions().setOwner(user); sub.getPermissions().setGroup(user.getPrimaryGroup()); sub.setId(getNextCollectionId()); current.addCollection(temp); saveCollection(current); current = sub; } } } catch (ReadOnlyException e) { LOG.debug("database read-only"); return null;
return current;
	public Collection getOrCreateCollection(User user, String name)		throws PermissionDeniedException {		name = normalizeCollectionName(name);		if (name.length() > 0 && name.charAt(0) != '/')			name = "/" + name;		if (!name.startsWith("/db"))			name = "/db" + name;		if (name.endsWith("/") && name.length() > 1)			name = name.substring(0, name.length() - 1);		Collection current;		try {			StringTokenizer tok = new StringTokenizer(name, "/");			String temp = tok.nextToken();			String path = "/db";			Collection sub;			current = getCollection("/db");			if (current == null) {				LOG.debug("creating root collection /db");				current = new Collection(this, "/db");				current.getPermissions().setPermissions(0777);				current.getPermissions().setOwner(user);				current.getPermissions().setGroup(user.getPrimaryGroup());				current.setId(getNextCollectionId());				saveCollection(current);			}			while (tok.hasMoreTokens()) {				temp = tok.nextToken();				path = path + "/" + temp;				if (current.hasSubcollection(temp))					current = getCollection(path);				else {					if (!current.getPermissions().validate(user, Permission.WRITE))						throw new PermissionDeniedException("not allowed to write to collection");					LOG.debug("creating collection " + path);					sub = new Collection(this, path);					sub.getPermissions().setOwner(user);					sub.getPermissions().setGroup(user.getPrimaryGroup());					sub.setId(getNextCollectionId());					current.addCollection(temp);					saveCollection(current);					current = sub;				}			}		} catch (ReadOnlyException e) {			LOG.debug("database read-only");			return null;		}		return current;	}