繁体   English   中英

如何在邮件中重用JIRA速度模板?

[英]How to reuse the JIRA velocity templates for emails?

我想更改JIRA的通知行为,并向某些问题事件添加其他接收者。 我知道我可以注册EventPublisher并捕获所有必要的事件。

public class MyIssueCreatedResolvedListenerImpl implements InitializingBean, DisposableBean {
    private final EventPublisher eventPublisher;

    public MyIssueCreatedResolvedListenerImpl(EventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        eventPublisher.register(this);
    }

    @Override
    public void destroy() throws Exception {
        eventPublisher.unregister(this);
    }

    @EventListener
    public void onIssueEvent(IssueEvent issueEvent) {
        // Process the issue events. I'm using the code presented below.
    }
}

onIssueEvent我想重用JIRA中的现有电子邮件模板,并将它们与SMTPMailServer对象一起发送给其他接收者。 目前,我正在使用以下代码读取和填充速度模板。

ApplicationProperties ap = ComponentAccessor.getApplicationProperties();
String baseUrl = ap.getString(APKeys.JIRA_BASEURL);
String webworkEncoding = ap.getString(APKeys.JIRA_WEBWORK_ENCODING);

VelocityManager vm = ComponentAccessor.getVelocityManager();
VelocityParamFactory vp = ComponentAccessor.getVelocityParamFactory();

Map context = vp.getDefaultVelocityParams();
context.put("baseurl", baseUrl);
context.put("currentTimestamp", new Date());
context.put("issue", issueEvent.getIssue());

String renderedText = vm.getEncodedBody("templates/email/html/", "issueclosed.vm", baseUrl, webworkEncoding, context);

SMTPMailServer mailServer = MailFactory.getServerManager().getDefaultSMTPMailServer();

Email email = new Email("<E-Mail-Adress>");
email.setMimeType("text/html");
email.setEncoding("utf-8");
email.setBody(renderedText);

try {
    mailServer.send(email);
} catch (MailException e) {
    e.printStackTrace();
}

上面的代码工作不完整。 填写了几个字段,但是我仍然想不到电子邮件通知中的CSS,图像或i18n。 请注意,我不会使用市场上的任何其他加载项。

  • 这是重用JIRA模板的正确实现吗?

  • 如何包含CSS,图片,i18n等? 还是可以使用其他方法?

填充了几个字段,但我仍然想念CSS,图像或i18n

国际化如何运作?

在对插件实施国际化(也称为“ i18n ”,因为“ i”和“ n”之间有18个字母)支持之前,了解插件如何国际化很重要。

首先,必须将插件中的所有消息移到代码外,然后移入插件的属性文件中。 属性文件存储插件内所有消息的默认(英文)翻译。 属性文件格式是键=值格式,其中键用于引用代码中的资源,值是英语中的默认消息。

除非您映射目录,否则不能在路径中使用/ images /。

包括Javascript和CSS资源:

对于每个资源,资源的位置应与插件JAR文件中资源的路径匹配。 资源路径已为您的插件命名空间,因此它们不会与其他具有相同位置的插件中的资源发生冲突(与i18n或Velocity资源不同)。 但是,您可能会发现使用特定于您的插件的路径名来与这些其他类型保持一致很方便。

要在使用插件的页面中包含自定义Web资源,请使用#requireResource Velocity宏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM