如何重用电子邮件的JIRA速度模板?

And*_*ter 8 java email templates velocity jira

我想更改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.
    }
}
Run Code Online (Sandbox Code Playgroud)

在这里,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();
}
Run Code Online (Sandbox Code Playgroud)

上面的代码工作部分.填写了几个字段,但我仍然错过了电子邮件通知中的CSS,图片或i18n.请注意,我不会使用市场上的任何其他附加组件.

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

  • 如何包含CSS,图像,i18n等?或者我可以使用不同的方法吗?

Tha*_*rif 2

几个字段已填满,但我仍然想念 CSS、图像或 i18n

国际化如何运作?

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

首先,插件中的所有消息都必须移至代码外部并移至插件中的属性文件中。属性文件存储插件内所有消息的默认(英语)翻译。属性文件格式是key = value格式,其中key用于引用代码中的资源,value是默认的英文消息。

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

包括Javascript和CSS资源:

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

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