public RollerAtomService(User user, String atomURL) throws WebloggerException, AtomException {
Weblogger roller = WebloggerFactory.getWeblogger();
List perms = null;
if (!WebloggerRuntimeConfig.getBooleanProperty("webservices.enableAtomPub")) {
throw new AtomException("AtomPub not enabled for this Roller installation");
}
try {
perms = roller.getUserManager().getWeblogPermissions(user);
} catch (WebloggerException re) {
throw new AtomException("Getting user's weblogs", re);
}
List uploadAccepts = new ArrayList();
try {
uploadAccepts = getAcceptedContentTypeRange();
} catch (WebloggerException re) {
throw new AtomException("Getting site's accept range", re);
}
if (perms != null) {
for (Iterator iter = perms.iterator(); iter.hasNext();) {
WeblogPermission perm = (WeblogPermission) iter.next();
Weblog weblog = perm.getWeblog();
Workspace workspace = null;
try {
// Create workspace to represent weblog
workspace = new Workspace(Utilities.removeHTML(perm.getWeblog().getName()), "text");
addWorkspace(workspace);
// Create collection for entries within that workspace
Collection entryCol = new Collection("Weblog Entries", "text", atomURL + "/" + weblog.getHandle() + "/entries");
entryCol.addAccept("application/atom+xml;type=entry");
// Add fixed categories using scheme that points to
// weblog because categories are weblog specific
weblog = perm.getWeblog();
Categories cats = new Categories();
cats.setFixed(true);
cats.setScheme(getWeblogCategoryScheme(weblog));
List rollerCats = roller.getWeblogEntryManager().getWeblogCategories(weblog, false);
for (Iterator it = rollerCats.iterator(); it.hasNext();) {
WeblogCategory rollerCat = (WeblogCategory) it.next();
Category cat = new Category();
cat.setTerm(rollerCat.getPath().substring(1));
cat.setLabel(rollerCat.getName());
cats.addCategory(cat);
}
entryCol.addCategories(cats);
// Add tags as free-form categories using scheme that points
// to site because tags can be considered site-wide
Categories tags = new Categories();
tags.setFixed(false);
entryCol.addCategories(tags);
workspace.addCollection(entryCol);
} catch (Exception e) {
throw new AtomException("Creating weblog entry collection for service doc", e);
}
// And add one media collection for each of weblog's upload directories
try {
MediaFileManager mgr = roller.getMediaFileManager();
List<MediaFileDirectory> dirs = mgr.getMediaFileDirectories(weblog);
for (MediaFileDirectory dir : dirs) {
Collection uploadSubCol = new Collection(
"Media Files: " + dir.getPath(), "text",
atomURL + "/" + weblog.getHandle() + "/resources/" + dir.getPath());
uploadSubCol.setAccepts(uploadAccepts);
workspace.addCollection(uploadSubCol);
}
} catch (Exception e) {
throw new AtomException("Creating weblog entry collection for service doc", e);
}
}
}
}