List availableWorkspaces = new ArrayList();
try {
TreeSet workspaceIds = new TreeSet(UIServices.lookup().getWorkspacesManager().getAllWorkspacesIdentifiers());
for (Iterator it = workspaceIds.iterator(); it.hasNext();) {
String workspaceId = (String) it.next();
Workspace workspace = UIServices.lookup().getWorkspacesManager().getWorkspace(workspaceId);
Permission perm = WorkspacePermission.newInstance(workspace, actions);
if (UserStatus.lookup().hasPermission(perm)) {
availableWorkspaces.add(workspace);
}
}
} catch (Exception e) {
log.error("Error:", e);
renderFragment("error");
throw new FormatterException("Error in formatter: ", e);
}
if (availableWorkspaces.isEmpty()) {
renderFragment("empty");
} else {
renderFragment("outputStart");
for (int i = 0; i < availableWorkspaces.size(); i++) {
Workspace workspace = (Workspace) availableWorkspaces.get(i);
setAttribute("index", i);
setAttribute("count", i + 1);
setAttribute("workspace", workspace);
setAttribute("workspaceId", workspace.getId());
setAttribute("workspaceName", StringEscapeUtils.escapeHtml((String) LocaleManager.lookup().localize(workspace.getName())));
setAttribute("current", workspace.getId().equals(navigationManager.getCurrentWorkspaceId()));
renderFragment("output");
}
renderFragment("outputEnd");
}
}