Example usage for org.springframework.web.servlet.view InternalResourceView setUrl

List of usage examples for org.springframework.web.servlet.view InternalResourceView setUrl

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view InternalResourceView setUrl.

Prototype

public void setUrl(@Nullable String url) 

Source Link

Document

Set the URL of the resource that this view wraps.

Usage

From source file:eu.europa.ejusticeportal.dss.demo.web.view.TemplateViewResolver.java

/**
 * {@inheritDoc}/*from   w ww  . ja v  a 2 s .com*/
 */
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
    String contentUrl = getPrefix() + viewName + getSuffix();
    InternalResourceView view = (InternalResourceView) super.buildView(viewName);
    view.setUrl(this.templateUrl);
    view.addStaticAttribute(this.contentUrlParameterName, contentUrl);
    return view;
}

From source file:org.jasig.cas.services.web.RegisteredServiceThemeBasedViewResolver.java

/**
 * 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/*from  w ww . ja va 2s.co m*/
 * @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;
}