Search in sources :

Example 1 with ViewManager

use of act.view.ViewManager in project actframework by actframework.

the class ActErrorPageRender method getTemplate.

private Template getTemplate(int statusCode, ActionContext context) {
    H.Format format = context.accept();
    String key = statusCode + "" + format;
    $.Var<Template> templateBag = templateCache.get(key);
    if (null == templateBag) {
        ViewManager vm = Act.viewManager();
        if (null == vm) {
            // unit testing
            return null;
        }
        context.templatePath(templatePath(statusCode, context));
        Template t = vm.load(context);
        if (null == t) {
            // try default one
            if (Act.isDev()) {
                context.templatePath("/error/dev/errorPage." + context.accept().name());
            } else {
                context.templatePath("/error/errorPage." + context.accept().name());
            }
            t = vm.load(context);
        }
        templateBag = $.var(t);
        templateCache.put(key, templateBag);
    }
    return templateBag.get();
}
Also used : org.osgl.$(org.osgl.$) H(org.osgl.http.H) ViewManager(act.view.ViewManager) Template(act.view.Template)

Example 2 with ViewManager

use of act.view.ViewManager in project actframework by actframework.

the class Act method initViewManager.

private static void initViewManager() {
    LOGGER.debug("initializing view manager ...");
    viewManager = new ViewManager();
}
Also used : ViewManager(act.view.ViewManager)

Example 3 with ViewManager

use of act.view.ViewManager in project actframework by actframework.

the class MailerContext method createMessage.

private MimeMessage createMessage() throws Exception {
    MailerConfig config = mailerConfig();
    if (null == config) {
        throw E.unexpected("Cannot find mailer config for %s", confId);
    }
    Session session = mailerConfig().session();
    if (Act.isDev()) {
        session.setDebug(true);
    }
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(from());
    msg.setSubject(subject());
    msg.setSentDate(new Date());
    msg.setRecipients(Message.RecipientType.TO, list2Array(to()));
    msg.setRecipients(Message.RecipientType.CC, list2Array(cc()));
    msg.setRecipients(Message.RecipientType.BCC, list2Array(bcc()));
    String content = this.content;
    if (null == content) {
        ViewManager vm = Act.viewManager();
        Template t = vm.load(this);
        E.illegalStateIf(null == t, "Mail template not defined");
        content = t.render(this);
    }
    if (attachments.isEmpty()) {
        msg.setText(content, config().encoding(), accept().name());
    } else {
        Multipart mp = new MimeMultipart();
        MimeBodyPart bp = new MimeBodyPart();
        mp.addBodyPart(bp);
        bp.setText(content, config().encoding(), accept().name());
        for (ISObject sobj : attachments) {
            String fileName = sobj.getAttribute(ISObject.ATTR_FILE_NAME);
            if (S.blank(fileName)) {
                fileName = sobj.getKey();
            }
            String contentType = sobj.getAttribute(ISObject.ATTR_CONTENT_TYPE);
            if (S.blank(contentType)) {
                contentType = "application/octet-stream";
            }
            MimeBodyPart attachment = new MimeBodyPart();
            attachment.attachFile(sobj.asFile(), contentType, null);
            attachment.setFileName(fileName);
            mp.addBodyPart(attachment);
        }
        msg.setContent(mp);
    }
    msg.saveChanges();
    return msg;
}
Also used : ViewManager(act.view.ViewManager) ISObject(org.osgl.storage.ISObject) Template(act.view.Template)

Aggregations

ViewManager (act.view.ViewManager)3 Template (act.view.Template)2 org.osgl.$ (org.osgl.$)1 H (org.osgl.http.H)1 ISObject (org.osgl.storage.ISObject)1