Skip to content

Commit 9de21a4

Browse files
committed
When using the Web messager, prefer to use its capability to apply
parameters on the message instead of using the LocalizationBundle#getStringWithParams for that. When building a user notification about the modification or the creation of a contribution in the different Silverpeas apps, encode for HTML the title/name and the description of the contribution.
1 parent 2dabff5 commit 9de21a4

File tree

32 files changed

+102
-135
lines changed

32 files changed

+102
-135
lines changed

blog/blog-library/src/main/java/org/silverpeas/components/blog/notification/AbstractBlogUserNotification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.silverpeas.components.blog.notification;
2626

27+
import org.owasp.encoder.Encode;
2728
import org.silverpeas.components.blog.model.Category;
2829
import org.silverpeas.components.blog.model.PostDetail;
2930
import org.silverpeas.core.admin.user.model.User;
@@ -54,7 +55,7 @@ protected void performTemplateData(final String language, final PostDetail resou
5455
defaultStringIfNotDefined(getTitle(language), getTitle()),
5556
"");
5657
template.setAttribute("blog", resource);
57-
template.setAttribute("blogName", resource.getPublication().getName(language));
58+
template.setAttribute("blogName", Encode.forHtml(resource.getPublication().getName(language)));
5859
template.setAttribute("blogDate", DateUtil.getOutputDate(resource.getDateEvent(), language));
5960
final Category categorie = resource.getCategory();
6061
String categorieName = null;

blog/blog-library/src/main/java/org/silverpeas/components/blog/notification/BlogUserSubscriptionNotification.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.silverpeas.components.blog.notification;
2525

26+
import org.owasp.encoder.Encode;
2627
import org.silverpeas.components.blog.model.PostDetail;
2728
import org.silverpeas.core.admin.user.model.UserDetail;
2829
import org.silverpeas.core.comment.model.Comment;
@@ -89,16 +90,11 @@ protected void performTemplateData(final String language, final PostDetail resou
8990
template.setAttribute("comment", comment);
9091
String commentMessage = null;
9192
if (comment != null) {
92-
commentMessage = comment.getMessage();
93+
commentMessage = Encode.forHtml(comment.getMessage());
9394
}
9495
template.setAttribute("commentMessage", commentMessage);
9596
}
9697

97-
@Override
98-
protected boolean stopWhenNoUserToNotify() {
99-
return true;
100-
}
101-
10298
@Override
10399
protected NotifAction getAction() {
104100
return action;

classifieds/classifieds-library/src/main/java/org/silverpeas/components/classifieds/notification/AbstractClassifiedUserNotification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.silverpeas.components.classifieds.notification;
2525

26+
import org.owasp.encoder.Encode;
2627
import org.silverpeas.components.classifieds.ClassifiedUtil;
2728
import org.silverpeas.components.classifieds.model.ClassifiedDetail;
2829
import org.silverpeas.core.admin.user.model.User;
@@ -55,7 +56,7 @@ protected void performTemplateData(final String language, final ClassifiedDetail
5556
final SilverpeasTemplate template) {
5657
getNotificationMetaData().addLanguage(language, getTitle(), "");
5758
template.setAttribute("classified", resource);
58-
template.setAttribute("classifiedName", resource.getTitle());
59+
template.setAttribute("classifiedName", Encode.forHtml(resource.getTitle()));
5960
template.setAttribute("senderName", User.getById(getSender()).getDisplayedName());
6061
}
6162

classifieds/classifieds-library/src/main/java/org/silverpeas/components/classifieds/notification/ClassifiedValidationUserNotification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Collection;
2727
import java.util.Collections;
2828

29+
import org.owasp.encoder.Encode;
2930
import org.silverpeas.components.classifieds.model.ClassifiedDetail;
3031
import org.silverpeas.core.template.SilverpeasTemplate;
3132
import org.silverpeas.core.notification.user.client.constant.NotifAction;
@@ -78,7 +79,7 @@ protected void perform(final ClassifiedDetail resource) {
7879
protected void performTemplateData(final String language, final ClassifiedDetail resource,
7980
final SilverpeasTemplate template) {
8081
super.performTemplateData(language, resource, template);
81-
template.setAttribute("refusalMotive", refusalMotive);
82+
template.setAttribute("refusalMotive", Encode.forHtml(refusalMotive));
8283
}
8384

8485
@Override

community/community-war/src/main/java/org/silverpeas/components/community/CommunityWebManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ private String getSpaceName(final CommunityOfUsers community) {
311311
*/
312312
private void successMessage(String messageKey, Object... params) {
313313
final String userLanguage = getUserLanguage();
314-
getMessager().addSuccess(getMessagesIn(userLanguage).getStringWithParams(messageKey, params));
314+
getMessager().addSuccess(getMessagesIn(userLanguage).getString(messageKey), params);
315315
}
316316

317317
private String getUserLanguage() {

delegatednews/delegatednews-library/src/main/java/org/silverpeas/components/delegatednews/notification/AbstractDelegatedNewsUserNotification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.silverpeas.components.delegatednews.notification;
2626

27+
import org.owasp.encoder.Encode;
2728
import org.silverpeas.components.delegatednews.model.DelegatedNews;
2829
import org.silverpeas.core.admin.user.model.User;
2930
import org.silverpeas.core.contribution.publication.model.PublicationDetail;
@@ -55,7 +56,7 @@ protected void performTemplateData(final String language, final DelegatedNews re
5556
final String title = defaultStringIfNotDefined(getTitle(language), getTitle());
5657
getNotificationMetaData().addLanguage(language, title, "");
5758
template.setAttribute("publicationId", publication.getId());
58-
template.setAttribute("publicationName", publication.getName(language));
59+
template.setAttribute("publicationName", Encode.forHtml(publication.getName(language)));
5960
template.setAttribute("senderName", (user != null ? user.getDisplayedName() : ""));
6061
}
6162

delegatednews/delegatednews-library/src/main/java/org/silverpeas/components/delegatednews/notification/DelegatedNewsDeniedNotification.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
*/
2424
package org.silverpeas.components.delegatednews.notification;
2525

26+
import org.owasp.encoder.Encode;
2627
import org.silverpeas.components.delegatednews.model.DelegatedNews;
2728
import org.silverpeas.core.admin.user.model.User;
2829
import org.silverpeas.core.notification.user.client.constant.NotifAction;
2930
import org.silverpeas.core.template.SilverpeasTemplate;
3031

3132
public class DelegatedNewsDeniedNotification extends AbstractDelegatedNewsUserNotification {
3233

33-
private String reasonForRefusal;
34+
private final String reasonForRefusal;
3435

3536
public DelegatedNewsDeniedNotification(final DelegatedNews delegatedNews, final User user,
3637
String reasonForRefusal) {
@@ -63,6 +64,6 @@ protected void perform(final DelegatedNews resource) {
6364
protected void performTemplateData(final String language, final DelegatedNews resource,
6465
final SilverpeasTemplate template) {
6566
super.performTemplateData(language, resource, template);
66-
template.setAttribute("refusalMotive", reasonForRefusal);
67+
template.setAttribute("refusalMotive", Encode.forHtml(reasonForRefusal));
6768
}
6869
}

formsOnline/formsOnline-library/src/main/java/org/silverpeas/components/formsonline/notification/FormsOnlineValidationRequestUserNotification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.silverpeas.components.formsonline.notification;
2525

26+
import org.owasp.encoder.Encode;
2627
import org.silverpeas.components.formsonline.model.FormInstance;
2728
import org.silverpeas.core.notification.user.client.constant.NotifAction;
2829
import org.silverpeas.core.template.SilverpeasTemplate;
@@ -79,7 +80,7 @@ protected void performTemplateData(final String language, final FormInstance res
7980
final SilverpeasTemplate template) {
8081
super.performTemplateData(language, resource, template);
8182
getResource().getValidations().getLatestValidation()
82-
.ifPresent(v -> template.setAttribute("comment", v.getComment()));
83+
.ifPresent(v -> template.setAttribute("comment", Encode.forHtml(v.getComment())));
8384
}
8485

8586
@Override

forums/forums-library/src/main/java/org/silverpeas/components/forums/notification/AbstractForumsForumUserNotification.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.silverpeas.components.forums.notification;
2525

26+
import org.owasp.encoder.Encode;
2627
import org.silverpeas.components.forums.model.ForumDetail;
2728
import org.silverpeas.core.notification.user.client.constant.NotifAction;
2829
import org.silverpeas.core.notification.user.model.NotificationResourceData;
@@ -32,18 +33,14 @@
3233
import java.util.MissingResourceException;
3334

3435
/**
35-
* User: Yohann Chastagnier
36+
* @author Yohann Chastagnier
3637
* Date: 10/06/13
3738
*/
3839
public abstract class AbstractForumsForumUserNotification
3940
extends AbstractForumsUserNotification<ForumDetail> {
4041

41-
private NotifAction action = null;
42+
private final NotifAction action;
4243

43-
/**
44-
* Default constructor.
45-
* @param resource
46-
*/
4744
public AbstractForumsForumUserNotification(final ForumDetail resource, final NotifAction action) {
4845
super(resource);
4946
this.action = action;
@@ -66,7 +63,7 @@ protected void performTemplateData(final String language, final ForumDetail reso
6663
title = getTitle();
6764
}
6865
getNotificationMetaData().addLanguage(language, title, "");
69-
template.setAttribute("title", resource.getName());
66+
template.setAttribute("title", Encode.forHtml(resource.getName()));
7067
}
7168

7269
@Override

forums/forums-library/src/main/java/org/silverpeas/components/forums/notification/AbstractForumsMessageUserNotification.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.silverpeas.components.forums.notification;
2525

26+
import org.owasp.encoder.Encode;
2627
import org.silverpeas.components.forums.model.Message;
2728
import org.silverpeas.core.notification.user.client.constant.NotifAction;
2829
import org.silverpeas.core.notification.user.model.NotificationResourceData;
@@ -35,25 +36,18 @@
3536
import java.util.MissingResourceException;
3637

3738
/**
38-
* User: Yohann Chastagnier
39+
* @author Yohann Chastagnier
3940
* Date: 10/06/13
4041
*/
4142
public abstract class AbstractForumsMessageUserNotification
4243
extends AbstractForumsUserNotification<Message> {
4344

4445
private NotifAction action = null;
4546

46-
/**
47-
* @param resource
48-
*/
4947
public AbstractForumsMessageUserNotification(final Message resource) {
5048
super(resource);
5149
}
5250

53-
/**
54-
* @param resource
55-
* @param action
56-
*/
5751
public AbstractForumsMessageUserNotification(final Message resource, final NotifAction action) {
5852
super(resource);
5953
this.action = action;
@@ -71,8 +65,8 @@ protected void performTemplateData(final String language, final Message resource
7165
}
7266
getNotificationMetaData().addLanguage(language, title, "");
7367
template.setAttribute("isSubject", resource.isSubject());
74-
template.setAttribute("title", resource.getTitle());
75-
template.setAttribute("text", resource.getText());
68+
template.setAttribute("title", Encode.forHtml(resource.getTitle()));
69+
template.setAttribute("text", Encode.forHtml(resource.getText()));
7670
template.setAttribute("originTitle", getForumsService()
7771
.getMessageTitle(getForumsService().getMessageParentId(getResource().getId())));
7872
}
@@ -82,7 +76,7 @@ protected void performNotificationResource(final String language, final Message
8276
final NotificationResourceData notificationResourceData) {
8377
notificationResourceData.setFeminineGender(false);
8478
notificationResourceData.setResourceId(resource.getId());
85-
notificationResourceData.setResourceType(resource.getResourceType());
79+
notificationResourceData.setResourceType(Message.getResourceType());
8680
notificationResourceData.setResourceName(resource.getTitle());
8781
}
8882

@@ -107,7 +101,7 @@ protected String getResourceURL(final Message resource) {
107101

108102
/**
109103
* Gets the bundle key prefix according to the resource if it is a subject or a message.
110-
* @return
104+
* @return the bundle key prefix
111105
*/
112106
protected String getNotificationBundleKeyPrefix() {
113107
StringBuilder bundleKeyPrefix = new StringBuilder("forums.");

0 commit comments

Comments
 (0)