Search in sources :

Example 1 with ViewableContext

use of org.glassfish.jersey.server.mvc.spi.ViewableContext in project jersey by jersey.

the class ViewableMessageBodyWriter method resolve.

/**
     * Resolve the given {@link org.glassfish.jersey.server.mvc.Viewable viewable} using
     * {@link org.glassfish.jersey.server.mvc.spi.ViewableContext}.
     *
     * @param viewable viewable to be resolved.
     * @return resolved viewable or {@code null}, if the viewable cannot be resolved.
     */
private ResolvedViewable resolve(final Viewable viewable) {
    if (viewable instanceof ResolvedViewable) {
        return (ResolvedViewable) viewable;
    } else {
        final ViewableContext viewableContext = getViewableContext();
        final Set<TemplateProcessor> templateProcessors = getTemplateProcessors();
        final List<MediaType> producibleMediaTypes = TemplateHelper.getProducibleMediaTypes(requestProvider.get(), extendedUriInfoProvider.get(), null);
        final Class<?> resourceClass = resourceInfoProvider.get().getResourceClass();
        if (viewable instanceof ImplicitViewable) {
            // Template Names.
            final ImplicitViewable implicitViewable = (ImplicitViewable) viewable;
            for (final String templateName : implicitViewable.getTemplateNames()) {
                final Viewable simpleViewable = new Viewable(templateName, viewable.getModel());
                final ResolvedViewable resolvedViewable = resolve(simpleViewable, producibleMediaTypes, implicitViewable.getResolvingClass(), viewableContext, templateProcessors);
                if (resolvedViewable != null) {
                    return resolvedViewable;
                }
            }
        } else {
            return resolve(viewable, producibleMediaTypes, resourceClass, viewableContext, templateProcessors);
        }
        return null;
    }
}
Also used : ResolvedViewable(org.glassfish.jersey.server.mvc.spi.ResolvedViewable) TemplateProcessor(org.glassfish.jersey.server.mvc.spi.TemplateProcessor) Viewable(org.glassfish.jersey.server.mvc.Viewable) ResolvedViewable(org.glassfish.jersey.server.mvc.spi.ResolvedViewable) MediaType(javax.ws.rs.core.MediaType) ViewableContext(org.glassfish.jersey.server.mvc.spi.ViewableContext)

Aggregations

MediaType (javax.ws.rs.core.MediaType)1 Viewable (org.glassfish.jersey.server.mvc.Viewable)1 ResolvedViewable (org.glassfish.jersey.server.mvc.spi.ResolvedViewable)1 TemplateProcessor (org.glassfish.jersey.server.mvc.spi.TemplateProcessor)1 ViewableContext (org.glassfish.jersey.server.mvc.spi.ViewableContext)1