Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/release' into integration/master
Browse files Browse the repository at this point in the history
Conflicts:
	docs/release-notes.md
  • Loading branch information
seanf committed Mar 24, 2015
2 parents 1e5a2f1 + fe9939d commit 3e94428
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Expand Up @@ -30,6 +30,7 @@ property can safely be reverted or removed before subsequent startups.
<h5>Bugfixes</h5>
* [1194543](https://bugzilla.redhat.com/show_bug.cgi?id=1194543) - Manual document re-upload makes previous translations fuzzy
* [1197902](https://bugzilla.redhat.com/show_bug.cgi?id=1197902) - Large translated document push times are inconsistent
* [1183412](https://bugzilla.redhat.com/show_bug.cgi?id=1183412) - Emails to administrators are sent in the current interface language


-----------------------
Expand Down
15 changes: 8 additions & 7 deletions zanata-war/src/main/java/org/zanata/email/EmailBuilder.java
Expand Up @@ -37,6 +37,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import org.zanata.i18n.MessagesFactory;

import static com.googlecode.totallylazy.collections.PersistentMap.constructors.map;
import static org.jboss.seam.ScopeType.EVENT;
Expand Down Expand Up @@ -66,7 +67,7 @@ public EmailBuilder() {
@In
private Context emailContext;
@In
private Messages msgs;
private MessagesFactory messagesFactory;

private static VelocityEngine makeVelocityEngine() {
VelocityEngine ve = new VelocityEngine();
Expand Down Expand Up @@ -149,9 +150,14 @@ MimeMessage buildMessage(MimeMessage msg, EmailStrategy strategy,
InternetAddress[] toAddresses, List<String> receivedReasons)
throws MessagingException {

// TODO remember users' locales, and customise for each recipient
// msgs = messagesFactory.getMessages(account.getLocale());
Messages msgs = messagesFactory.getDefaultLocaleMessages();

Optional<InternetAddress> from = strategy.getFromAddress();
String fromName = msgs.get("jsf.Zanata");
msg.setFrom(from.or(Addresses.getAddress(
emailContext.getFromAddress(), emailContext.getFromName())));
emailContext.getFromAddress(), fromName)));
Optional<InternetAddress[]> replyTo = strategy.getReplyToAddress();
if (replyTo.isPresent()) {
msg.setReplyTo(replyTo.get());
Expand Down Expand Up @@ -202,17 +208,12 @@ MimeMessage buildMessage(MimeMessage msg, EmailStrategy strategy,
public static class Context {
@In
private ApplicationConfiguration applicationConfiguration;
@In
private Messages msgs;
String getServerPath() {
return applicationConfiguration.getServerPath();
}
String getFromAddress() {
return applicationConfiguration.getFromEmailAddr();
}
String getFromName() {
return msgs.get("jsf.Zanata");
}
}

}
33 changes: 30 additions & 3 deletions zanata-war/src/main/java/org/zanata/i18n/Messages.java
@@ -1,5 +1,5 @@
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* Copyright 2010-2015, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
Expand Down Expand Up @@ -58,12 +58,24 @@
@Scope(EVENT)
public class Messages extends AbstractMap<String, String> {

/**
* Gets the 'messages' ResourceBundle for the locale of the current
* request, if any, otherwise server's default locale.
* @see org.jboss.seam.web.Locale
*/
private static ResourceBundle getResourceBundle() {
return getResourceBundle(org.jboss.seam.core.Locale.instance());
}

/**
* Gets the 'messages' ResourceBundle for the specified locale.
*/
private static ResourceBundle getResourceBundle(java.util.Locale locale) {
// Generic ResourceBundle without built-in interpolation:
ResourceBundle resourceBundle = null;
try {
resourceBundle = ResourceBundle.getBundle(
"messages", org.jboss.seam.core.Locale.instance());
"messages", locale);
} catch (MissingResourceException e) {
resourceBundle = new ResourceBundle() {
@Override
Expand All @@ -83,8 +95,23 @@ public Enumeration<String> getKeys() {

private final ResourceBundle resourceBundle;

/**
* Create an instance for the locale of the current request, if any,
* otherwise the server's default locale.
*/
public Messages() {
this.resourceBundle = getResourceBundle();
this(getResourceBundle());
}

/**
* Create an instance for the specified locale.
*/
public Messages(java.util.Locale locale) {
this(getResourceBundle(locale));
}

private Messages(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}

@Observer("org.jboss.seam.localeSelected")
Expand Down
55 changes: 55 additions & 0 deletions zanata-war/src/main/java/org/zanata/i18n/MessagesFactory.java
@@ -0,0 +1,55 @@
/*
* Copyright 2015, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.i18n;

import static org.jboss.seam.ScopeType.APPLICATION;

import lombok.Getter;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import java.util.Locale;

/**
* Factory bean to return an instance of Messages based on a parameter.
*
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*/
@AutoCreate
@Name("messagesFactory")
@Scope(APPLICATION)
public class MessagesFactory {

/**
* Returns an instance of Messages for the server's default locale.
*/
@Getter
private final Messages defaultLocaleMessages = getMessages(Locale.getDefault());

/**
* Returns an instance of Messages for the specified locale.
*/
public Messages getMessages(Locale locale) {
return new Messages(locale);
}
}
18 changes: 11 additions & 7 deletions zanata-war/src/test/java/org/zanata/email/EmailStrategyTest.java
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Locale;
import java.util.Properties;

import javax.mail.BodyPart;
Expand All @@ -42,6 +43,7 @@
import org.testng.annotations.Test;
import org.zanata.common.ProjectType;
import org.zanata.i18n.Messages;
import org.zanata.i18n.MessagesFactory;
import org.zanata.webtrans.shared.model.ProjectIterationId;

/**
Expand All @@ -64,13 +66,20 @@ public String format(String key, Object... args) {
}
};
String fromAddress = "zanata@example.com";
String fromName = "SERVER_NAME[测试]";
String fromName = msgs.get("jsf.Zanata");
String toName = "User Name[测试]";
String toAddress = "username@example.com";
String serverPath = "https://zanata.example.com";
InternetAddress toAddr;
InternetAddress[] toAddresses;

MessagesFactory msgsFactory = new MessagesFactory() {
@Override
public Messages getMessages(Locale locale) {
return msgs;
}
};

Session session = Session.getDefaultInstance(new Properties());
EmailBuilder.Context context = new EmailBuilder.Context() {
@Override
Expand All @@ -82,13 +91,8 @@ String getFromAddress() {
String getServerPath() {
return serverPath;
}

@Override
String getFromName() {
return fromName;
}
};
EmailBuilder builder = new EmailBuilder(session, context, msgs);
EmailBuilder builder = new EmailBuilder(session, context, msgsFactory);
MimeMessage message;

// context values needed for some templates:
Expand Down
Expand Up @@ -170,8 +170,8 @@ public void doublePostResource() throws Exception {
response.releaseConnection();
}

// @Test
// @RunAsClient
@Test
@RunAsClient
public void putResource() throws Exception {
// Create a new Resource
Resource res = new Resource("new-put-resource");
Expand Down
Expand Up @@ -59,6 +59,9 @@ public class TranslationsRawCompatibilityITCase extends RestTest {

@Override
protected void prepareDBUnitOperations() {
addBeforeTestOperation(new DataSetOperation(
"org/zanata/test/model/ClearAllTables.dbunit.xml",
DatabaseOperation.DELETE_ALL));
addBeforeTestOperation(new DataSetOperation(
"org/zanata/test/model/AccountData.dbunit.xml",
DatabaseOperation.CLEAN_INSERT));
Expand Down

0 comments on commit 3e94428

Please sign in to comment.