Java 类org.glassfish.jersey.server.mvc.spi.TemplateProcessor 实例源码

项目:ameba    文件:ResolvingViewableContext.java   
/**
 * Resolve given {@link Viewable viewable} with relative template name using {@link MediaType media type},
 * {@code resolving class} and {@link TemplateProcessor template processor}.
 *
 * @param viewable          viewable to be resolved.
 * @param mediaType         media type of te output.
 * @param resolvingClass    resolving class.
 * @param templateProcessor template processor to be used.
 * @return resolved viewable or {@code null} if the viewable cannot be resolved.
 */
private ResolvedViewable resolveRelativeViewable(final Viewable viewable,
                                                 final Class<?> resolvingClass,
                                                 final MediaType mediaType,
                                                 final TemplateProcessor templateProcessor) {
    final String path = TemplateHelper.getTemplateName(viewable);

    ResolvedViewable resolvedViewable = resolveRelativeViewable(Viewables.PROTECTED_DIR + "/" + path,
            viewable, resolvingClass, mediaType, templateProcessor);

    if (resolvedViewable == null) {
        resolvedViewable = resolveRelativeViewable(path,
                viewable, resolvingClass, mediaType, templateProcessor);
    }

    return resolvedViewable;
}
项目:ameba    文件:ViewableMessageBodyWriter.java   
/**
 * Resolve given {@link org.glassfish.jersey.server.mvc.Viewable viewable}
 * for a list of {@link javax.ws.rs.core.MediaType mediaTypes} and a {@link Class resolvingClass}
 * using given {@link org.glassfish.jersey.server.mvc.spi.ViewableContext viewableContext}
 * and a set of {@link org.glassfish.jersey.server.mvc.spi.TemplateProcessor templateProcessors}
 *
 * @param viewable           viewable to be resolved.
 * @param mediaTypes         producible media types.
 * @param resolvingClass     non-null resolving class.
 * @param viewableContext    viewable context.
 * @param templateProcessors collection of available template processors.
 * @return resolved viewable or {@code null}, if the viewable cannot be resolved.
 */
private ResolvedViewable resolve(final Viewable viewable,
                                 final List<MediaType> mediaTypes,
                                 final Class<?> resolvingClass,
                                 final ViewableContext viewableContext,
                                 final Set<TemplateProcessor> templateProcessors) {
    for (TemplateProcessor templateProcessor : templateProcessors) {
        for (final MediaType mediaType : mediaTypes) {
            final ResolvedViewable resolvedViewable = viewableContext
                    .resolveViewable(viewable, mediaType, resolvingClass, templateProcessor);

            if (resolvedViewable != null) {
                return resolvedViewable;
            }
        }
    }

    return null;
}
项目:ameba    文件:NotFoundForward.java   
/**
 * <p>mappedViewPath.</p>
 *
 * @return a {@link java.lang.String} object.
 */
public String mappedViewPath() {
    String path = getCurrentPath();
    //受保护目录,不允许直接访问
    String pDir = Viewables.PROTECTED_DIR + "/";
    if (path.startsWith(pDir)
            || path.startsWith("/" + pDir)) return null;
    for (TemplateProcessor templateProcessor : getTemplateProcessors()) {
        Object has = templateProcessor.resolve(path, MediaType.TEXT_HTML_TYPE);
        if (has == null) {
            path = path + (path.endsWith("/") ? "" : "/") + "index";
            has = templateProcessor.resolve(path, MediaType.TEXT_HTML_TYPE);
        }
        if (has != null) {
            return path;
        }
    }
    return null;
}
项目:ameba    文件:ResolvingViewableContext.java   
/**
 * {@inheritDoc}
 *
 * Resolve given {@link Viewable viewable} using {@link MediaType media type}, {@code resolving class} and
 * {@link TemplateProcessor template processor}.
 */
public ResolvedViewable resolveViewable(final Viewable viewable, final MediaType mediaType,
                                        final Class<?> resourceClass, final TemplateProcessor templateProcessor) {
    if (viewable.isTemplateNameAbsolute()) {
        return resolveAbsoluteViewable(viewable, resourceClass, mediaType, templateProcessor);
    } else {
        if (resourceClass == null) {
            throw new ViewableContextException(LocalizationMessages.TEMPLATE_RESOLVING_CLASS_CANNOT_BE_NULL());
        }

        return resolveRelativeViewable(viewable, resourceClass, mediaType, templateProcessor);
    }
}
项目:ameba    文件:ResolvingViewableContext.java   
/**
 * Resolve given {@link Viewable viewable} with absolute template name using {@link MediaType media type} and
 * {@link TemplateProcessor template processor}.
 *
 * @param viewable          viewable to be resolved.
 * @param mediaType         media type of te output.
 * @param resourceClass     resource class.
 * @param templateProcessor template processor to be used.
 * @return resolved viewable or {@code null} if the viewable cannot be resolved.
 */
@SuppressWarnings("unchecked")
private ResolvedViewable resolveAbsoluteViewable(final Viewable viewable, Class<?> resourceClass,
                                                 final MediaType mediaType,
                                                 final TemplateProcessor templateProcessor) {
    final Object resolvedTemplateObject = templateProcessor.resolve(viewable.getTemplateName(), mediaType);

    if (resolvedTemplateObject != null) {
        return new ResolvedViewable(templateProcessor, resolvedTemplateObject, viewable, resourceClass, mediaType);
    }

    return null;
}
项目:ameba    文件:ViewableMessageBodyWriter.java   
/**
 * 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();

        List<MediaType> producibleMediaTypes = TemplateHelper
                .getProducibleMediaTypes(requestProvider.get(), extendedUriInfoProvider.get(), null);

        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 {
            final Class<?> resourceClass = resourceInfoProvider.get().getResourceClass();
            return resolve(viewable, producibleMediaTypes, resourceClass, viewableContext, templateProcessors);
        }

        return null;
    }
}
项目:ameba    文件:ViewableMessageBodyWriter.java   
/**
 * Get a {@link java.util.LinkedHashSet collection} of available template processors.
 *
 * @return set of template processors.
 */
private Set<TemplateProcessor> getTemplateProcessors() {
    final Set<TemplateProcessor> templateProcessors = Sets.newLinkedHashSet();

    templateProcessors.addAll(Providers.getCustomProviders(injectionManager, TemplateProcessor.class));
    templateProcessors.addAll(Providers.getProviders(injectionManager, TemplateProcessor.class));

    return templateProcessors;
}
项目:ameba    文件:NotFoundForward.java   
private Set<TemplateProcessor> getTemplateProcessors() {
    Set<TemplateProcessor> templateProcessors = Sets.newLinkedHashSet();

    templateProcessors.addAll(Providers.getCustomProviders(injectionManager, TemplateProcessor.class));
    templateProcessors.addAll(Providers.getProviders(injectionManager, TemplateProcessor.class));
    return templateProcessors;
}