use of cn.taketoday.web.view.View in project today-framework by TAKETODAY.
the class XlsViewTests method testXls.
@Test
@SuppressWarnings("resource")
public void testXls() throws Exception {
View excelView = new AbstractXlsView() {
@Override
protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, RequestContext request) throws Exception {
Sheet sheet = workbook.createSheet("Test Sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Test Value");
}
};
excelView.render(new HashMap<>(), requestContext);
Workbook wb = new HSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
assertThat(wb.getSheetName(0)).isEqualTo("Test Sheet");
Sheet sheet = wb.getSheet("Test Sheet");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
assertThat(cell.getStringCellValue()).isEqualTo("Test Value");
}
use of cn.taketoday.web.view.View in project today-framework by TAKETODAY.
the class ViewResolverRegistry method initContentNegotiatingViewResolver.
private ContentNegotiatingViewResolver initContentNegotiatingViewResolver(View[] defaultViews) {
// ContentNegotiatingResolver in the registry: elevate its precedence!
this.order = order != null ? order : Ordered.HIGHEST_PRECEDENCE;
if (contentNegotiatingResolver != null) {
if (ObjectUtils.isNotEmpty(defaultViews) && CollectionUtils.isNotEmpty(contentNegotiatingResolver.getDefaultViews())) {
ArrayList<View> views = new ArrayList<>(contentNegotiatingResolver.getDefaultViews());
CollectionUtils.addAll(views, defaultViews);
contentNegotiatingResolver.setDefaultViews(views);
}
} else {
this.contentNegotiatingResolver = new ContentNegotiatingViewResolver();
contentNegotiatingResolver.setDefaultViews(Arrays.asList(defaultViews));
contentNegotiatingResolver.setViewResolvers(viewResolvers);
if (contentNegotiationManager != null) {
contentNegotiatingResolver.setContentNegotiationManager(contentNegotiationManager);
}
}
return contentNegotiatingResolver;
}
use of cn.taketoday.web.view.View in project today-framework by TAKETODAY.
the class ModelAndViewReturnValueHandler method handleModelAndView.
/**
* Resolve {@link ModelAndView} return type
*
* @since 2.3.3
*/
public final void handleModelAndView(RequestContext context, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
if (modelAndView != null) {
View view = modelAndView.getView();
String viewName = modelAndView.getViewName();
BindingContext bindingContext = context.getBindingContext();
bindingContext.addAllAttributes(modelAndView.getModel());
if (viewName != null) {
delegate.renderView(context, viewName);
} else if (view != null) {
delegate.renderView(context, view);
}
}
}
use of cn.taketoday.web.view.View in project today-framework by TAKETODAY.
the class XlsViewTests method testXlsxView.
@Test
@SuppressWarnings("resource")
public void testXlsxView() throws Exception {
View excelView = new AbstractXlsxView() {
@Override
protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, RequestContext request) throws Exception {
Sheet sheet = workbook.createSheet("Test Sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Test Value");
}
};
excelView.render(new HashMap<>(), requestContext);
Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
assertThat(wb.getSheetName(0)).isEqualTo("Test Sheet");
Sheet sheet = wb.getSheet("Test Sheet");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
assertThat(cell.getStringCellValue()).isEqualTo("Test Value");
}
use of cn.taketoday.web.view.View in project today-framework by TAKETODAY.
the class XlsViewTests method testXlsxStreamingView.
@Test
@SuppressWarnings("resource")
public void testXlsxStreamingView() throws Exception {
View excelView = new AbstractXlsxStreamingView() {
@Override
protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, RequestContext request) throws Exception {
Sheet sheet = workbook.createSheet("Test Sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Test Value");
}
};
excelView.render(new HashMap<>(), requestContext);
Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
assertThat(wb.getSheetName(0)).isEqualTo("Test Sheet");
Sheet sheet = wb.getSheet("Test Sheet");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
assertThat(cell.getStringCellValue()).isEqualTo("Test Value");
}
Aggregations