javax.mvc.Models Java Examples

The following examples show how to use javax.mvc.Models. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewEngineContextImpl.java    From krazo with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for view engine contexts.
 *
 * @param view Name of view.
 * @param models Instance of models.
 * @param request HTTP servlet request.
 * @param response HTTP servlet response.
 * @param responseHeaders The response responseHeaders
 * @param outputStream The response stream
 * @param mediaType The media type
 * @param uriInfo URI info about the request.
 * @param resourceInfo Resource matched info.
 * @param configuration the configuration.
 * @param locale the request locale
 */
public ViewEngineContextImpl(String view, Models models, Object request, Object response,
                             MultivaluedMap<String, Object> responseHeaders, OutputStream outputStream,
                             MediaType mediaType, UriInfo uriInfo, ResourceInfo resourceInfo,
                             Configuration configuration, Locale locale) {
    this.view = view;
    this.models = models;
    this.request = request;
    this.response = response;
    this.responseHeaders = responseHeaders;
    this.outputStream = outputStream;
    this.mediaType = mediaType;
    this.uriInfo = uriInfo;
    this.resourceInfo = resourceInfo;
    this.configuration = configuration;
    this.locale = locale;
}
 
Example #2
Source File: WebContextProducer.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public SpringPortletWebContext(ApplicationContext applicationContext, Models models, String lifecyclePhase,
	HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
	ServletContext servletContext, Locale locale, javax.ws.rs.core.Configuration configuration) {

	super(httpServletRequest, httpServletResponse, servletContext, locale);
	this.applicationContext = applicationContext;
	this.models = models;
	this.beanNames = new HashSet<>();

	boolean portletSpecBeans = false;

	VariableValidator variableValidator = applicationContext.getBean(VariableValidator.class);

	boolean headerPhase = lifecyclePhase.equals(PortletRequest.HEADER_PHASE);
	boolean renderPhase = lifecyclePhase.equals(PortletRequest.RENDER_PHASE);
	boolean resourcePhase = lifecyclePhase.equals(PortletRequest.RESOURCE_PHASE);

	for (String beanName : applicationContext.getBeanDefinitionNames()) {

		if ((beanName != null) &&
				variableValidator.isValidName(beanName, headerPhase, renderPhase, resourcePhase)) {
			this.beanNames.add(beanName);
		}
	}
}
 
Example #3
Source File: WebContextProducer.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public CDIPortletWebContext(BeanManager beanManager, VariableValidator variableInspector, Models models,
	String lifecyclePhase, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
	ServletContext servletContext, Locale locale) {

	super(httpServletRequest, httpServletResponse, servletContext, locale);
	this.beanManager = beanManager;
	this.models = models;
	this.beanNames = new HashSet<>();

	boolean headerPhase = lifecyclePhase.equals(PortletRequest.HEADER_PHASE);
	boolean renderPhase = lifecyclePhase.equals(PortletRequest.RENDER_PHASE);
	boolean resourcePhase = lifecyclePhase.equals(PortletRequest.RESOURCE_PHASE);

	Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {
			});

	for (Bean<?> bean : beans) {
		String beanName = bean.getName();

		if ((beanName != null) &&
				variableInspector.isValidName(beanName, headerPhase, renderPhase, resourcePhase)) {
			this.beanNames.add(beanName);
		}
	}
}
 
Example #4
Source File: ViewEngineContextImpl.java    From ozark with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for view engine contexts.
 *
 * @param view Name of view.
 * @param models Instance of models.
 * @param request HTTP servlet request.
 * @param response HTTP servlet response.
 * @param responseHeaders The response responseHeaders
 * @param outputStream The response stream
 * @param mediaType The media type
 * @param uriInfo URI info about the request.
 * @param resourceInfo Resource matched info.
 * @param configuration the configuration.
 * @param locale the request locale
 */
public ViewEngineContextImpl(String view, Models models, Object request, Object response,
                             MultivaluedMap<String, Object> responseHeaders, OutputStream outputStream,
                             MediaType mediaType, UriInfo uriInfo, ResourceInfo resourceInfo,
                             Configuration configuration, Locale locale) {
    this.view = view;
    this.models = models;
    this.request = request;
    this.response = response;
    this.responseHeaders = responseHeaders;
    this.outputStream = outputStream;
    this.mediaType = mediaType;
    this.uriInfo = uriInfo;
    this.resourceInfo = resourceInfo;
    this.configuration = configuration;
    this.locale = locale;
}
 
Example #5
Source File: TrimouViewEngine.java    From trimou with Apache License 2.0 5 votes vote down vote up
@Override
public void processView(ViewEngineContext context)
        throws ViewEngineException {
    try {
        Models models = context.getModels();
        models.put("request", context.getRequest());
        models.put("locale", context.getRequest().getLocale());
        Writer writer = context.getResponse().getWriter();
        engine.getMustache(context.getView()).render(writer, models);
        writer.flush();
    } catch (IOException e) {
        throw new ViewEngineException(e);
    }
}
 
Example #6
Source File: ViewEngineContextImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public ViewEngineContextImpl(Configuration configuration, PortletRequest portletRequest, MimeResponse mimeResponse,
	Models models, Locale locale) {
	this.configuration = configuration;
	this.portletRequest = portletRequest;
	this.mimeResponse = mimeResponse;
	this.models = models;
	this.locale = locale;
}
 
Example #7
Source File: WebContextProducer.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Scope(proxyMode = ScopedProxyMode.INTERFACES, value = "portletRequest")
@Bean
public IWebContext getWebContext(MvcContext mvcContext, Models models, PortletRequest portletRequest,
	MimeResponse mimeResponse, ServletContext servletContext) {

	return new SpringPortletWebContext(applicationContext, models,
			(String) portletRequest.getAttribute(PortletRequest.LIFECYCLE_PHASE),
			new HttpServletRequestAdapter(portletRequest), new HttpServletResponseAdapter(mimeResponse),
			servletContext, mvcContext.getLocale(), mvcContext.getConfig());
}
 
Example #8
Source File: WebContextProducer.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@PortletRequestScoped
@Produces
public IWebContext getWebContext(BeanManager beanManager, VariableValidator variableValidator,
	MvcContext mvcContext, Models models, PortletRequest portletRequest, MimeResponse mimeResponse,
	ServletContext servletContext) {

	return new CDIPortletWebContext(beanManager, variableValidator, models,
			(String) portletRequest.getAttribute(PortletRequest.LIFECYCLE_PHASE),
			new HttpServletRequestAdapter(portletRequest), new HttpServletResponseAdapter(mimeResponse),
			servletContext, mvcContext.getLocale());
}
 
Example #9
Source File: ViewEngineContextImpl.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Models getModels() {
	return models;
}
 
Example #10
Source File: ViewEngineContextImpl.java    From krazo with Apache License 2.0 4 votes vote down vote up
@Override
public Models getModels() {
    return models;
}
 
Example #11
Source File: ModelsImpl.java    From krazo with Apache License 2.0 4 votes vote down vote up
@Override
public Models put(String name, Object model) {
    Objects.requireNonNull(name, "Name must not be null");
    map.put(name, model);
    return this;
}
 
Example #12
Source File: ViewableWriter.java    From krazo with Apache License 2.0 4 votes vote down vote up
/**
 * Searches for a suitable {@link javax.mvc.engine.ViewEngine} to process the view. If no engine
 * is found, is forwards the request back to the servlet container.
 */
@Override
public void writeTo(Viewable viewable, Class<?> aClass, Type type, Annotation[] annotations, MediaType resolvedMediaType,
                    MultivaluedMap<String, Object> headers, OutputStream out)
    throws IOException, WebApplicationException {

    // Find engine for this Viewable
    final ViewEngine engine = engineFinder.find(viewable);
    if (engine == null) {
        throw new ServerErrorException(messages.get("NoViewEngine", viewable), INTERNAL_SERVER_ERROR);
    }

    // build the full media type (including the charset) and make sure the response header is set correctly
    MediaType mediaType = buildMediaTypeWithCharset(resolvedMediaType);
    headers.putSingle(HttpHeaders.CONTENT_TYPE, mediaType);

    HttpServletRequest request = unwrapOriginalRequest(injectedRequest);
    HttpServletResponse response = unwrapOriginalResponse(injectedResponse);

    // Create wrapper for response
    final ServletOutputStream responseStream = new DelegatingServletOutputStream(out);
    final HttpServletResponse responseWrapper = new MvcHttpServletResponse(response, responseStream, mediaType, headers);

    // Pass request to view engine
    try {
        // If no models in viewable, inject via CDI
        Models models = viewable.getModels();
        if (models == null) {
            models = modelsInstance.get();
        }

        // Bind EL 'mvc' object in models
        models.put("mvc", mvc);

        // Execute the view engine
        eventDispatcher.fireBeforeProcessViewEvent(engine, viewable);
        try {

            // Process view using selected engine
            engine.processView(new ViewEngineContextImpl(viewable.getView(), models, request, responseWrapper,
                                                         headers, responseStream, mediaType, uriInfo, resourceInfo, config, mvc.getLocale()));

        } finally {
            eventDispatcher.fireAfterProcessViewEvent(engine, viewable);
        }

    } catch (ViewEngineException e) {
        throw new ServerErrorException(INTERNAL_SERVER_ERROR, e);
    } finally {
        responseWrapper.getWriter().flush();
    }
}
 
Example #13
Source File: ModelsImpl.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Models put(String name, Object model) {
	modelsMap.put(name, model);

	return this;
}
 
Example #14
Source File: ViewEngineContextImpl.java    From ozark with Apache License 2.0 4 votes vote down vote up
@Override
public Models getModels() {
    return models;
}
 
Example #15
Source File: ModelsImpl.java    From ozark with Apache License 2.0 4 votes vote down vote up
@Override
public Models put(String name, Object model) {
    Objects.requireNonNull(name, "Name must not be null");
    map.put(name, model);
    return this;
}
 
Example #16
Source File: Viewable.java    From ozark with Apache License 2.0 2 votes vote down vote up
/**
 * Set the models instance.
 *
 * @param models the new models instance.
 */
public void setModels(Models models) {
    this.models = models;
}
 
Example #17
Source File: Viewable.java    From krazo with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance using a view and a models instance.
 *
 * @param view the view.
 * @param models the models instance.
 */
public Viewable(String view, Models models) {
    this(view, models, null);
}
 
Example #18
Source File: Viewable.java    From ozark with Apache License 2.0 2 votes vote down vote up
/**
 * Get the models instance.
 *
 * @return the models instance or {@code null}.
 */
public Models getModels() {
    return models;
}
 
Example #19
Source File: Viewable.java    From ozark with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance using a view, a models and a view engine instances.
 *
 * @param view the view.
 * @param models the models instance.
 * @param viewEngine the view engine class.
 */
public Viewable(String view, Models models, Class<? extends ViewEngine> viewEngine) {
    this.view = view;
    this.models = models;
    this.viewEngine = viewEngine;
}
 
Example #20
Source File: Viewable.java    From ozark with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance using a view and a models instance.
 *
 * @param view the view.
 * @param models the models instance.
 */
public Viewable(String view, Models models) {
    this(view, models, null);
}
 
Example #21
Source File: Viewable.java    From krazo with Apache License 2.0 2 votes vote down vote up
/**
 * Set the models instance.
 *
 * @param models the new models instance.
 */
public void setModels(Models models) {
    this.models = models;
}
 
Example #22
Source File: Viewable.java    From krazo with Apache License 2.0 2 votes vote down vote up
/**
 * Get the models instance.
 *
 * @return the models instance or {@code null}.
 */
public Models getModels() {
    return models;
}
 
Example #23
Source File: Viewable.java    From krazo with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance using a view, a models and a view engine instances.
 *
 * @param view the view.
 * @param models the models instance.
 * @param viewEngine the view engine class.
 */
public Viewable(String view, Models models, Class<? extends ViewEngine> viewEngine) {
    this.view = view;
    this.models = models;
    this.viewEngine = viewEngine;
}