How to apply text alignment for converted jira wiki markup text to html?

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 16, 2014

Hi everybody,

i'm using JIRA as a helpdesk system. In the workflow we have transitions where user can send email with a custom groovyrunner postfunction. In the post function we convert JIRA wiki markup to html. For Right To Left languages (Arabic, etc) we want to alligh text on the right. I have tried some things by the text allignment does not apply.

Thank you in advance

The code i'm using is the following

import javax.mail.internet.*;
import javax.mail.*
import javax.activation.*
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.attachment.Attachment;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.util.AttachmentUtils;
import groovy.text.GStringTemplateEngine;
import com.atlassian.jira.issue.fields.renderer.wiki.AtlassianWikiRenderer;
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.groups.GroupManager;



//Convert wiki markup to HTML
EventPublisher eventPublisher = ComponentAccessor.getOSGiComponentInstanceOfType(EventPublisher.class);
VelocityRequestContextFactory velocityRequestContextFactory = ComponentAccessor.getOSGiComponentInstanceOfType(VelocityRequestContextFactory.class);
AtlassianWikiRenderer wikiRenderer = new AtlassianWikiRenderer(eventPublisher, velocityRequestContextFactory);



def groupManager = ComponentAccessor.getGroupManager()

def currentUser = componentManager.jiraAuthenticationContext?.user








//Get Comment Manager
CommentManager commentManager = componentManager.getCommentManager();

//Get custom field manager
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();





//Get custom field email by id
CustomField customField_email = customFieldManager.getCustomFieldObject( 10205 );

CustomField customField_mtu = customFieldManager.getCustomFieldObject( 11000 );

//get value of customField_email
to = issue.getCustomFieldValue( customField_email )


//get value of customField_mtu
mtu = issue.getCustomFieldValue( customField_mtu ).toString();


//Convert JIRA wiki to HTML
m_t_u = wikiRenderer.render(mtu, null);



//Email Headers
sender="test@test.com"
sendername="Test Test"


//Email acccount credentials
def username="test@test.com"
def password="test"

//Gmail Default port
port = 25

//Email Body
content = """\
<div align="right">
$m_t_u
</div>
"""

//Creat first part of email, Email Body


Multipart mp = new MimeMultipart("mixed");

MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(content.toString(), "text/html; charset=utf-8");
mp.addBodyPart(htmlPart);

//Email Properties

props = new Properties()

props.put("mail.smtp.port", port);
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.quitwait", "false");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

//New session

Session session = Session.getInstance(props,
		  new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username, password);
			}
		  });


MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender,sendername));
message.setSubject("Title");

message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setContent(mp)

try{
		Transport transport = session.getTransport("smtp");
		transport.connect( "smtp.gmail.com",port,username,password );
		transport.sendMessage(message,message.getAllRecipients());
		transport.close();
		log.warn ("mail sent sucesfully to : "+ issue.getCustomFieldValue( customField_email).toString() + ", for issue: " + issue.getKey())


}catch (MessagingException mex) {
		log.warn ("Could not sent email to : "+ issue.getCustomFieldValue( customField_email).toString() + " for issue: " + issue.getKey())		
		mex.printStackTrace();
}

1 answer

1 accepted

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 18, 2014

Interesting... do you think this this an HTML problem or an issue with i18n in jira?

How does it look when you view RTL languages in the browser, is it correct?

If it's an HTML issue have you tried using the dir attrib as per http://www.i18nguy.com/markup/right-to-left.html?

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2014

If i use

<div dir="rtl">
$m_t_u
</div>

in code the text is alligned on the right. I have just tested it.

Using

<div align="right">
$m_t_u
</div>

has exactly the same results.

Finally, it was not an HTML problem nor a i18n in JIRA. I was using wrong script in post function. :(

Thanks for the help

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2014

I'm trying to add a conditional expression in email's body but in email i get printed the conditional expression also.

what i use is the following

content = """\

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") out << '<div dir="rtl">
	  $m_t_u
	  </div>' else out << '<div>
	  $m_t_u
	  </div>'%>
"""

And the email i get is the following

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") out << '
test
tetetest
testtesttest

' else out << '
test
tetetest
testtesttest

'%>

Any idea what's wrong in the syntax i use?

Thanx in advance

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2014

I think it should be like this:

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") %>
	'<div dir="rtl">$m_t_u
<% else %>
    ....

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2014

I have tried your suggestion but it seems that the way the syntax is ignores the condition. Html works though.

The condition i have used is the following

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") %>
    '<div dir="rtl">$m_t_u</div>
<% else %>
'<div>$m_t_u</div>

The result i get is in the next screenshot

I have tried different modifications, without luck.

Suggest an answer

Log in or Sign up to answer