public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException {
List<Workspace> availableWorkspaces = new ArrayList<Workspace>();
try {
Set<String> workspaceIds = new TreeSet<String>(UIServices.lookup().getWorkspacesManager().getAllWorkspacesIdentifiers());
for (String workspaceId : workspaceIds) {
Workspace workspace = UIServices.lookup().getWorkspacesManager().getWorkspace(workspaceId);
boolean finish = false;
int index = 0;
while (!finish && index < WorkspacePermission.LIST_OF_ACTIONS.size()) {
Permission perm = WorkspacePermission.newInstance(workspace, WorkspacePermission.LIST_OF_ACTIONS.get(index++));
if (UserStatus.lookup().hasPermission(perm)) {
availableWorkspaces.add(workspace);
finish = true;
}
}
}
} catch (Exception 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 = 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");
}
}