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();
}
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();
}
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;
}
}
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());
}
Aggregations