Example usage for org.springframework.web.servlet.view.xslt XsltView setSourceKey

List of usage examples for org.springframework.web.servlet.view.xslt XsltView setSourceKey

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view.xslt XsltView setSourceKey.

Prototype

public void setSourceKey(String sourceKey) 

Source Link

Document

Set the name of the model attribute that represents the XSLT Source.

Usage

From source file:org.jasig.portlet.proxy.mvc.portlet.xslt.XsltPortletController.java

@RequestMapping
public ModelAndView showContent(PortletRequest request) {
    final ModelAndView mv = new ModelAndView();

    final PortletPreferences preferences = request.getPreferences();

    // locate the content service to use to retrieve our XML
    final String contentServiceKey = preferences.getValue(CONTENT_SERVICE_KEY, null);
    final IContentService contentService = applicationContext.getBean(contentServiceKey, IContentService.class);
    final IContentRequest proxyRequest = contentService.getRequest(request);

    // retrieve the XML content
    final IContentResponse proxyResponse = contentService.getContent(proxyRequest, request);
    try {/*from  w  w  w. j  a v a  2s.  com*/
        mv.addObject("xml", proxyResponse.getContent());
    } finally {
        proxyResponse.close();
    }

    // set the appropriate view name
    final String mainXslt = preferences.getValue(MAIN_XSLT_KEY, null);
    final String mobileXslt = preferences.getValue(MOBILE_XSLT_KEY, null);
    final String xslt;
    if (mobileXslt != null) {
        final boolean isMobile = viewSelector.isMobile(request);
        xslt = isMobile ? mobileXslt : mainXslt;
    } else {
        xslt = mainXslt;
    }

    // create an XSLT view using the configured source
    final XsltView view = new XsltView();
    view.setUrl(xslt);
    view.setSourceKey("xml");
    view.setApplicationContext(this.applicationContext);
    mv.setView(view);

    return mv;
}