org.springframework.web.servlet.view.AbstractUrlBasedView Java Examples

The following examples show how to use org.springframework.web.servlet.view.AbstractUrlBasedView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeetlSpringViewResolver.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 实例化GroupTemplate
 *
 * @param viewName
 * @return
 * @throws Exception
 */
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception
{

	BeetlSpringView beetlView = (BeetlSpringView) super.buildView(viewName);
	beetlView.setGroupTemplate(groupTemplate);
	String suffix = getSuffix();
	//如果配置有后缀,需要重新设定视图
	if(suffix!=null&&suffix.length()!=0){
		if (viewName.contains("#")) {
			String[] split = viewName.split("#");
			if (split.length > 2) {
			throw new Exception("视图名称有误:" + viewName);
			}
			beetlView.setUrl(getPrefix() + split[0] + getSuffix() + "#" + split[1]);
		}
	}
	return beetlView;
	
}
 
Example #2
Source File: TrimouViewResolverTest.java    From trimou with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure the prefix is passed on to the template loader
 * and that the template loader is called with a fully
 * resolved view path.
 */
@Test
public void resolvesViewWithPrefix() throws Exception {
    //given
    final String viewPath = "/WEB-INF/views/";
    final String viewName = "hello.mustache";

    //when
    when(engine.getMustache(viewPath + viewName)).thenReturn(mustache);

    TrimouViewResolver sut = new TrimouViewResolver();
    sut.setServletContext(servletContext);
    sut.setPrefix(viewPath);
    sut.afterPropertiesSet();
    sut.setEngine(engine);

    //then
    AbstractUrlBasedView view = sut.buildView(viewName);
    assertThat(view, is(notNullValue()));
}
 
Example #3
Source File: XsltViewResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	XsltView view = (XsltView) super.buildView(viewName);
	if (this.sourceKey != null) {
		view.setSourceKey(this.sourceKey);
	}
	if (this.uriResolver != null) {
		view.setUriResolver(this.uriResolver);
	}
	if (this.errorListener != null) {
		view.setErrorListener(this.errorListener);
	}
	view.setIndent(this.indent);
	if (this.outputProperties != null) {
		view.setOutputProperties(this.outputProperties);
	}
	view.setCacheTemplates(this.cacheTemplates);
	return view;
}
 
Example #4
Source File: TrimouViewResolverTest.java    From trimou with Apache License 2.0 6 votes vote down vote up
/**
 * When not valid prefix did set, then viewResolver throws the MustacheException.
 */
@Test(expected = MustacheException.class)
public void resolvesViewWithNotValidPrefix() throws Exception {
    //given
    final String viewPath = "WEB-INF/views/";
    final String viewName = "top-level.mustache";

    //when
    when(engine.getMustache(viewName)).thenReturn(mustache);

    TrimouViewResolver sut = new TrimouViewResolver();
    sut.setServletContext(servletContext);
    sut.setPrefix(viewPath);
    sut.afterPropertiesSet();
    sut.setEngine(engine);

    //then
    AbstractUrlBasedView view = sut.buildView(viewName);
    assertThat(view, is(notNullValue()));
}
 
Example #5
Source File: TrimouViewResolverTest.java    From trimou with Apache License 2.0 6 votes vote down vote up
/**
 * When the prefix did not set, then viewResolver throws the NullPointerException.
 */
@Test(expected = MustacheException.class)
public void resolvesViewWithoutPrefix() throws Exception {
    //given
    final String viewName = "top-level.mustache";

    //when
    when(engine.getMustache(viewName)).thenReturn(mustache);

    TrimouViewResolver sut = new TrimouViewResolver();
    sut.setServletContext(servletContext);
    sut.afterPropertiesSet();
    sut.setEngine(engine);

    //then
    AbstractUrlBasedView view = sut.buildView(viewName);
    assertThat(view, is(notNullValue()));
}
 
Example #6
Source File: XsltViewResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	XsltView view = (XsltView) super.buildView(viewName);
	if (this.sourceKey != null) {
		view.setSourceKey(this.sourceKey);
	}
	if (this.uriResolver != null) {
		view.setUriResolver(this.uriResolver);
	}
	if (this.errorListener != null) {
		view.setErrorListener(this.errorListener);
	}
	view.setIndent(this.indent);
	if (this.outputProperties != null) {
		view.setOutputProperties(this.outputProperties);
	}
	view.setCacheTemplates(this.cacheTemplates);
	return view;
}
 
Example #7
Source File: StudentGroupController.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@RequestMapping(value = "/editStudentGroupAttends/{studentGroup}", method = RequestMethod.POST)
public AbstractUrlBasedView editStudentGroupAttends(Model model, @PathVariable Grouping grouping,
        @ModelAttribute("attends") @Validated AttendsBean attendsBean, @PathVariable StudentGroup studentGroup,
        BindingResult bindingResult) {

    Map<String, Boolean> studentsToRemove = attendsBean.getRemoveStudent();
    Map<String, Boolean> studentsToAdd = attendsBean.getAddStudent();
    if (bindingResult.hasErrors()) {
        model.addAttribute("removeStudent", studentsToRemove);
        model.addAttribute("addStudent", studentsToAdd);
        model.addAttribute("errors", "binding error " + bindingResult.getAllErrors());
        return viewStudentGroup(model, grouping, studentGroup);
    }

    studentGroupService.updateStudentGroupMembers(studentGroup, studentsToRemove, studentsToAdd);
    return new RedirectView("/teacher/" + executionCourse.getExternalId() + "/student-groups/" + grouping.getExternalId()
            + "/viewStudentGroup/" + studentGroup.getExternalId(), true);
}
 
Example #8
Source File: VelocityViewResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	VelocityView view = (VelocityView) super.buildView(viewName);
	view.setDateToolAttribute(this.dateToolAttribute);
	view.setNumberToolAttribute(this.numberToolAttribute);
	if (this.toolboxConfigLocation != null) {
		((VelocityToolboxView) view).setToolboxConfigLocation(this.toolboxConfigLocation);
	}
	return view;
}
 
Example #9
Source File: TilesViewResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	TilesView view = (TilesView) super.buildView(viewName);
	if (this.alwaysInclude != null) {
		view.setAlwaysInclude(this.alwaysInclude);
	}
	return view;
}
 
Example #10
Source File: ViewResolver.java    From playground with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	if (viewName.isEmpty() || viewName.endsWith("/")) {
		viewName += "index";
	}
	return super.buildView(viewName);
}
 
Example #11
Source File: StudentGroupController.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/shift/{shift}/createStudentGroup", method = RequestMethod.POST)
public AbstractUrlBasedView createStudentGroup(Model model, @PathVariable Grouping grouping, @PathVariable Shift shift,
        @ModelAttribute("addStudent") @Validated AttendsBean addStudents, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return new RedirectView("/teacher/" + executionCourse.getExternalId() + "/student-groups/view/"
                + grouping.getExternalId(), true);
    }

    StudentGroup studentgroup = studentGroupService.createStudentGroup(grouping, shift);
    return new RedirectView("/teacher/" + executionCourse.getExternalId() + "/student-groups/" + grouping.getExternalId()
            + "/viewStudentGroup/" + studentgroup.getExternalId(), true);
}
 
Example #12
Source File: StudentGroupController.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/editStudentGroupShift/{studentGroup}", method = RequestMethod.POST)
public AbstractUrlBasedView editStudentGroupShift(@PathVariable Grouping grouping, @PathVariable StudentGroup studentGroup,
        @ModelAttribute("newShift") @Validated Shift newShift, BindingResult bindingResult) {
    studentGroupService.updateStudentGroupShift(studentGroup, newShift);
    return new RedirectView("/teacher/" + executionCourse.getExternalId() + "/student-groups/" + grouping.getExternalId()
            + "/viewStudentGroup/" + studentGroup.getExternalId(), true);

}
 
Example #13
Source File: StudentGroupController.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/deleteStudentGroup/{studentGroup}", method = RequestMethod.POST)
public AbstractUrlBasedView deleteStudentGroup(Model model, @PathVariable Grouping grouping,
        @PathVariable StudentGroup studentGroup) {
    if (!studentGroup.getAttendsSet().isEmpty()) {
        model.addAttribute("errors", "errors.invalid.delete.not.empty.studentGroup");
        return viewStudentGroup(model, grouping, studentGroup);
    }
    studentGroupService.deleteStudentGroup(studentGroup);
    return new RedirectView("/teacher/" + executionCourse.getExternalId() + "/student-groups/view/"
            + grouping.getExternalId(), true);
}
 
Example #14
Source File: RichFreeMarkerViewResolver.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * if viewName start with / , then ignore prefix.
 */
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	AbstractUrlBasedView view = super.buildView(viewName);
	// start with / ignore prefix
	if (viewName.startsWith("/")) {
		view.setUrl(viewName + getSuffix());
	}
	return view;
}
 
Example #15
Source File: SimpleFreeMarkerViewResolver.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * if viewName start with / , then ignore prefix.
 */
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	AbstractUrlBasedView view = super.buildView(viewName);
	// start with / ignore prefix
	if (viewName.startsWith("/")) {
		view.setUrl(viewName + getSuffix());
	}
	return view;
}
 
Example #16
Source File: CrafterFreeMarkerViewResolver.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
    CrafterFreeMarkerView view = (CrafterFreeMarkerView) super.buildView(viewName);
    view.setSiteItemService(siteItemService);
    view.setComponentTemplateXPathQuery(componentTemplateXPathQuery);
    view.setComponentTemplateNamePrefix(getPrefix());
    view.setComponentTemplateNameSuffix(getSuffix());
    view.setComponentIncludeElementName(componentIncludeElementName);
    view.setComponentEmbeddedElementName(componentEmbeddedElementName);
    view.setComponentScriptResolver(componentScriptResolver);

    return view;
}
 
Example #17
Source File: TrimouViewResolver.java    From trimou with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
    TrimouView view = (TrimouView) super.buildView(viewName);
    try {
        view.setViewName(viewName);
        view.setEngine(engine);
        return view;
    } catch (Exception e) {
        throw new MustacheException(view.getUrl() + " : " + e.getMessage());
    }
}
 
Example #18
Source File: JasperReportsViewResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	AbstractJasperReportsView view = (AbstractJasperReportsView) super.buildView(viewName);
	view.setReportDataKey(this.reportDataKey);
	view.setSubReportUrls(this.subReportUrls);
	view.setSubReportDataKeys(this.subReportDataKeys);
	view.setHeaders(this.headers);
	view.setExporterParameters(this.exporterParameters);
	view.setJdbcDataSource(this.jdbcDataSource);
	return view;
}
 
Example #19
Source File: TemplateResourceViewResolver.java    From anyline with Apache License 2.0 5 votes vote down vote up
protected AbstractUrlBasedView buildView(String viewName) throws Exception { 
	TemplateView view = (TemplateView) BeanUtils.instantiateClass(getViewClass()); 
	if (!viewName.contains(getPrefix())  
			&& !viewName.startsWith("/")) { 
		viewName = getPrefix() + viewName; 
	} 
	if (!viewName.endsWith(getSuffix())) { 
		viewName = viewName + getSuffix(); 
	} 
	view.setUrl(viewName); 
	String contentType = getContentType(); 
	if (contentType != null) 
		view.setContentType(contentType); 

	view.setRequestContextAttribute(getRequestContextAttribute()); 
	view.setAttributesMap(getAttributesMap()); 
	if (this.alwaysInclude != null) 
		view.setAlwaysInclude(this.alwaysInclude.booleanValue()); 

	if (this.exposeContextBeansAsAttributes != null) 
		view.setExposeContextBeansAsAttributes(this.exposeContextBeansAsAttributes.booleanValue()); 

	if (this.exposedContextBeanNames != null) 
		view.setExposedContextBeanNames(this.exposedContextBeanNames); 

	view.setPreventDispatchLoop(true); 
	return view; 
}
 
Example #20
Source File: RegisteredServiceThemeBasedViewResolver.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Uses the viewName and the theme associated with the service.
 * being requested and returns the appropriate view.
 * @param viewName the name of the view to be resolved
 * @return a theme-based UrlBasedView
 * @throws Exception an exception
 */
@Override
protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final WebApplicationService service = WebUtils.getService(requestContext);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    final String themeId = service != null && registeredService != null
            && registeredService.getAccessStrategy().isServiceAccessAllowed()
            && StringUtils.hasText(registeredService.getTheme()) ? registeredService.getTheme() : defaultThemeId;

    final String themePrefix = String.format("%s/%s/ui/", pathPrefix, themeId);
    LOGGER.debug("Prefix {} set for service {} with theme {}", themePrefix, service, themeId);

    //Build up the view like the base classes do, but we need to forcefully set the prefix for each request.
    //From UrlBasedViewResolver.buildView
    final InternalResourceView view = (InternalResourceView) BeanUtils.instantiateClass(getViewClass());
    view.setUrl(themePrefix + viewName + getSuffix());
    final String contentType = getContentType();
    if (contentType != null) {
        view.setContentType(contentType);
    }
    view.setRequestContextAttribute(getRequestContextAttribute());
    view.setAttributesMap(getAttributesMap());

    //From InternalResourceViewResolver.buildView
    view.setAlwaysInclude(false);
    view.setExposeContextBeansAsAttributes(false);
    view.setPreventDispatchLoop(true);

    LOGGER.debug("View resolved: {}", view.getUrl());

    return view;
}
 
Example #21
Source File: XsltViewResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	XsltView view = (XsltView) super.buildView(viewName);
	view.setSourceKey(this.sourceKey);
	if (this.uriResolver != null) {
		view.setUriResolver(this.uriResolver);
	}
	if (this.errorListener != null) {
		view.setErrorListener(this.errorListener);
	}
	view.setIndent(this.indent);
	view.setOutputProperties(this.outputProperties);
	view.setCacheTemplates(this.cacheTemplates);
	return view;
}
 
Example #22
Source File: JasperReportsViewResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	AbstractJasperReportsView view = (AbstractJasperReportsView) super.buildView(viewName);
	view.setReportDataKey(this.reportDataKey);
	view.setSubReportUrls(this.subReportUrls);
	view.setSubReportDataKeys(this.subReportDataKeys);
	view.setHeaders(this.headers);
	view.setExporterParameters(this.exporterParameters);
	view.setJdbcDataSource(this.jdbcDataSource);
	return view;
}
 
Example #23
Source File: TilesViewResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	TilesView view = (TilesView) super.buildView(viewName);
	if (this.alwaysInclude != null) {
		view.setAlwaysInclude(this.alwaysInclude);
	}
	return view;
}
 
Example #24
Source File: VelocityLayoutViewResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName);
	// Use not-null checks to preserve VelocityLayoutView's defaults.
	if (this.layoutUrl != null) {
		view.setLayoutUrl(this.layoutUrl);
	}
	if (this.layoutKey != null) {
		view.setLayoutKey(this.layoutKey);
	}
	if (this.screenContentKey != null) {
		view.setScreenContentKey(this.screenContentKey);
	}
	return view;
}
 
Example #25
Source File: VelocityViewResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	VelocityView view = (VelocityView) super.buildView(viewName);
	view.setDateToolAttribute(this.dateToolAttribute);
	view.setNumberToolAttribute(this.numberToolAttribute);
	if (this.toolboxConfigLocation != null) {
		((VelocityToolboxView) view).setToolboxConfigLocation(this.toolboxConfigLocation);
	}
	return view;
}
 
Example #26
Source File: VelocityLayoutViewResolver.java    From scoold with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName);
	// Use not-null checks to preserve VelocityLayoutView's defaults.
	if (this.layoutUrl != null) {
		view.setLayoutUrl(this.layoutUrl);
	}
	if (this.layoutKey != null) {
		view.setLayoutKey(this.layoutKey);
	}
	if (this.screenContentKey != null) {
		view.setScreenContentKey(this.screenContentKey);
	}
	return view;
}
 
Example #27
Source File: XsltViewResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	XsltView view = (XsltView) super.buildView(viewName);
	view.setSourceKey(this.sourceKey);
	if (this.uriResolver != null) {
		view.setUriResolver(this.uriResolver);
	}
	if (this.errorListener != null) {
		view.setErrorListener(this.errorListener);
	}
	view.setIndent(this.indent);
	view.setOutputProperties(this.outputProperties);
	view.setCacheTemplates(this.cacheTemplates);
	return view;
}
 
Example #28
Source File: VelocityLayoutViewResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName);
	// Use not-null checks to preserve VelocityLayoutView's defaults.
	if (this.layoutUrl != null) {
		view.setLayoutUrl(this.layoutUrl);
	}
	if (this.layoutKey != null) {
		view.setLayoutKey(this.layoutKey);
	}
	if (this.screenContentKey != null) {
		view.setScreenContentKey(this.screenContentKey);
	}
	return view;
}
 
Example #29
Source File: VelocityViewResolver.java    From scoold with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
	VelocityView view = (VelocityView) super.buildView(viewName);
	return view;
}
 
Example #30
Source File: AppViewResolver.java    From xiaoyaoji with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
    return super.buildView(viewName);
}