Search in sources :

Example 1 with BeanModel

use of freemarker.ext.beans.BeanModel in project OpenMEAP by OpenMEAP.

the class AdminServlet method service.

@SuppressWarnings("unchecked")
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
    logger.trace("Entering service()");
    try {
        DocumentProcessor documentProcessor = null;
        logger.debug("Request uri: {}", request.getRequestURI());
        logger.debug("Request url: {}", request.getRequestURL());
        logger.debug("Query string: {}", request.getQueryString());
        if (logger.isDebugEnabled()) {
            logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap()));
        }
        if (request.getParameter("logout") != null) {
            logger.trace("Executing logout");
            request.getSession().invalidate();
            response.sendRedirect(request.getContextPath() + "/interface/");
        }
        if (request.getParameter("refreshContext") != null && context instanceof AbstractApplicationContext) {
            logger.trace("Refreshing context");
            ((AbstractApplicationContext) context).refresh();
        }
        // support for clearing the persistence context
        if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) {
            logger.trace("Clearing the persistence context");
            ModelServiceImpl ms = (ModelServiceImpl) ((AbstractApplicationContext) context).getBean("modelService");
            ms.clearPersistenceContext();
        }
        // default to the mainOptionPage, unless otherwise specified
        String pageBean = null;
        if (request.getParameter(FormConstants.PAGE_BEAN) != null)
            pageBean = request.getParameter(FormConstants.PAGE_BEAN);
        else
            pageBean = FormConstants.PAGE_BEAN_MAIN;
        logger.debug("Using page bean: {}", pageBean);
        documentProcessor = (DocumentProcessor) context.getBean(pageBean);
        ModelManager mgr = getModelManager();
        Map<Object, Object> map = new HashMap<Object, Object>();
        // TODO: I'm not really happy with this hacky work-around for the login form not being in actual request scope
        if (documentProcessor.getProcessesFormData()) {
            GlobalSettings settings = mgr.getGlobalSettings();
            map = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), settings.getTemporaryStoragePath(), request);
            map.put("userPrincipalName", new String[] { request.getUserPrincipal().getName() });
            AuthorizerImpl authorizer = (AuthorizerImpl) context.getBean("authorizer");
            authorizer.setRequest(request);
        }
        response.setContentType(FormConstants.CONT_TYPE_HTML);
        Map<Object, Object> defaultTemplateVars = new HashMap<Object, Object>();
        defaultTemplateVars.put("request", new BeanModel(request, new DefaultObjectWrapper()));
        documentProcessor.setTemplateVariables(defaultTemplateVars);
        documentProcessor.handleProcessAndRender(map, response.getWriter());
        response.getWriter().flush();
        response.getWriter().close();
    } catch (IOException te) {
        throw new RuntimeException(te);
    }
    logger.trace("Leaving service()");
}
Also used : BeanModel(freemarker.ext.beans.BeanModel) DocumentProcessor(com.openmeap.web.DocumentProcessor) HashMap(java.util.HashMap) AuthorizerImpl(com.openmeap.AuthorizerImpl) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) GlobalSettings(com.openmeap.model.dto.GlobalSettings) IOException(java.io.IOException) ModelManager(com.openmeap.model.ModelManager) ModelServiceImpl(com.openmeap.model.ModelServiceImpl) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext)

Aggregations

AuthorizerImpl (com.openmeap.AuthorizerImpl)1 ModelManager (com.openmeap.model.ModelManager)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 DocumentProcessor (com.openmeap.web.DocumentProcessor)1 BeanModel (freemarker.ext.beans.BeanModel)1 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)1