Search in sources :

Example 1 with Viewable

use of org.glassfish.jersey.server.mvc.Viewable in project jersey by jersey.

the class AbstractErrorTemplateMapper method toResponse.

@Override
public final Response toResponse(final T throwable) {
    final ErrorTemplate error = getErrorTemplate();
    final String templateName = "".equals(error.name()) ? "index" : error.name();
    return Response.status(getErrorStatus(throwable)).entity(new Viewable(templateName, getErrorModel(throwable))).build();
}
Also used : ErrorTemplate(org.glassfish.jersey.server.mvc.ErrorTemplate) Viewable(org.glassfish.jersey.server.mvc.Viewable)

Example 2 with Viewable

use of org.glassfish.jersey.server.mvc.Viewable in project jersey by jersey.

the class TemplateMethodInterceptor method aroundWriteTo.

@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
    final Template template = TemplateHelper.getTemplateAnnotation(context.getAnnotations());
    final Object entity = context.getEntity();
    if (template != null && !(entity instanceof Viewable)) {
        context.setType(Viewable.class);
        context.setEntity(new Viewable(template.name(), entity));
    }
    context.proceed();
}
Also used : Viewable(org.glassfish.jersey.server.mvc.Viewable) Template(org.glassfish.jersey.server.mvc.Template)

Example 3 with Viewable

use of org.glassfish.jersey.server.mvc.Viewable 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)

Example 4 with Viewable

use of org.glassfish.jersey.server.mvc.Viewable in project jersey by jersey.

the class CombinedFeedController method create.

@POST
@Template(name = "/index.ftl")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Viewable create(@Valid @BeanParam FeedRequestBean request) {
    String[] urlArray = createUrls(request.getUrls()).stream().toArray(String[]::new);
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(null, urlArray).title(request.getTitle()).description(request.getDescription()).refreshPeriod(request.getRefreshPeriod()).build();
    feedService.save(feed);
    return new Viewable("/index.ftl", getModel());
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Viewable(org.glassfish.jersey.server.mvc.Viewable) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Template(org.glassfish.jersey.server.mvc.Template) ErrorTemplate(org.glassfish.jersey.server.mvc.ErrorTemplate)

Aggregations

Viewable (org.glassfish.jersey.server.mvc.Viewable)4 ErrorTemplate (org.glassfish.jersey.server.mvc.ErrorTemplate)2 Template (org.glassfish.jersey.server.mvc.Template)2 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 MediaType (javax.ws.rs.core.MediaType)1 CombinedFeed (org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)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