BindingProvider bindingProvider = operationContext.getBindingProvider();
Collection<Page> pagesList = pages.getChildren();
List<ExportTask> tasks = new ArrayList<ExportTask>(pagesList.size());
PageExportTask pageExportTask = new PageExportTask(siteKey, dataStorage, pageService, bindingProvider.getMarshaller(
org.exoplatform.portal.config.model.Page.PageSet.class, ContentType.XML));
String pageName = operationContext.getAddress().resolvePathTemplate("page-name");
for (Page page : pagesList) {
if (pageName == null) {
PathAddress pageAddress = operationContext.getAddress().append(page.getName());
// We need to look up the subresource because this sets the path template resolver to be used by the filter.
operationContext.getManagedResource().getSubResource(pageAddress);
PathTemplateFilter filter;
try {
filter = PathTemplateFilter.parse(operationContext.getAttributes().getValues("filter"));
} catch (ParseException e) {
throw new OperationException(operationContext.getOperationName(), "Could not parse filter attributes.", e);
}
if (pageAddress.accepts(filter)) {
pageExportTask.addPageName(page.getName());
}
} else if (pageName.equals(page.getName())) {
pageExportTask.addPageName(page.getName());
}
}
if (pageExportTask.getPageNames().isEmpty() && pageName != null) {
throw new ResourceNotFoundException("No page found for " + new PageKey(siteKey, pageName));
} else if (pageExportTask.getPageNames().isEmpty()) {
resultHandler.completed(new ExportResourceModel(Collections.<ExportTask> emptyList()));
} else {
tasks.add(pageExportTask);
resultHandler.completed(new ExportResourceModel(tasks));
}