return null;
}
@Override
protected void doService(ToolPageContext page) throws IOException, ServletException {
Search search = new Search(page);
Query<?> query = search.toQuery(page.getSite());
DatabaseEnvironment environment = Database.Static.getDefault().getEnvironment();
ObjectType type = search.getSelectedType();
List<Display> allDisplays = new ArrayList<Display>();
allDisplays.add(new ReferencesDisplay());
allDisplays.add(new PathsDisplay());
for (String name : new String[] {
"cms.content.publishDate",
"cms.content.publishUser",
"cms.content.updateDate",
"cms.content.updateUser" }) {
allDisplays.add(new ObjectFieldDisplay(environment.getField(name)));
}
if (type != null) {
for (ObjectField field : type.getFields()) {
allDisplays.add(new ObjectFieldDisplay(field));
}
}
List<String> displayNames = page.params(String.class, FIELDS_PARAMETER);
List<Display> displays = new ArrayList<Display>();
for (Display display : allDisplays) {
if (displayNames.contains(display.getInternalName())) {
displays.add(display);
}
}
Collections.sort(allDisplays);
Collections.sort(displays);
List<UUID> ids = page.params(UUID.class, ITEMS_PARAMETER);
if (page.param(String.class, "action-download") != null) {
HttpServletResponse response = page.getResponse();
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment; filename=search-result-" + new DateTime(null, page.getUserDateTimeZone()).toString("yyyy-MM-dd-hh-mm-ss") + ".csv");
page.write('\ufeff');
page.write("\"");
writeCsvItem(page, "Type");
page.write("\",\"");
writeCsvItem(page, "Label");
page.write("\"");
for (Display display : displays) {
page.write(",\"");
writeCsvItem(page, display.getDisplayName());
page.write("\"");
}
page.write("\r\n");
Iterator<?> queryIterator = ids.isEmpty() ?
query.iterable(0).iterator() :
Query.fromAll().where("_id = ?", ids).selectAll().iterator();
try {
while (queryIterator.hasNext()) {
Object item = queryIterator.next();
State itemState = State.getInstance(item);
page.write("\"");
writeCsvItem(page, page.getTypeLabel(item));
page.write("\",\"");
writeCsvItem(page, page.getObjectLabel(item));
page.write("\"");
for (Display display : displays) {
page.write(",\"");
writeCsvItem(page, display.getCsvItem(itemState));
page.write("\"");
}
page.write("\r\n");
}
} finally {
if (queryIterator instanceof Closeable) {
((Closeable) queryIterator).close();
}
}
return;
} else if (page.param(String.class, "action-trash") != null) {
Iterator<?> queryIterator = ids.isEmpty() ?
query.iterable(0).iterator() :
Query.fromAll().where("_id = ?", ids).selectAll().iterator();
try {
while (queryIterator.hasNext()) {
page.trash(queryIterator.next());
}
} finally {
if (queryIterator instanceof Closeable) {
((Closeable) queryIterator).close();
}
}
page.getResponse().sendRedirect(page.param(String.class, "returnUrl"));
return;
}
if (search.getLimit() < 20) {
search.setLimit(20);
}
search.setSuggestions(false);
Renderer renderer = new Renderer(page, search, allDisplays, displays);
page.putOverride(Recordable.class, new HtmlFormatter<Recordable>() {