Skip to content

Commit

Permalink
SAK-44342 Apply best practice when using ResourceLoader (sakaiproject…
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored Sep 23, 2020
1 parent 7cd7f17 commit 66e7b3d
Show file tree
Hide file tree
Showing 77 changed files with 153 additions and 245 deletions.
2 changes: 1 addition & 1 deletion admin-su/src/java/org/sakaiproject/tool/su/SuTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class SuTool
protected static final String SU_BECOME_USER = "su.become";
protected static final String SU_VIEW_USER = "su.view";

ResourceLoader msgs = new ResourceLoader("tool-tool-su");
private static ResourceLoader msgs = new ResourceLoader("tool-tool-su");

// Service instance variables
private AuthzGroupService M_authzGroupService = ComponentManager.get(AuthzGroupService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@Slf4j
public class LTIReportingJob implements Job {

protected final ResourceLoader rb = new ResourceLoader("email");
protected static final ResourceLoader rb = new ResourceLoader("email");

private LTIService ltiService;
private SiteService siteService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public abstract class BaseCalendarService implements CalendarService, DoubleStor

private DocumentBuilder docBuilder = null;

private ResourceLoader rb = new ResourceLoader("calendar");
private static final ResourceLoader rb = new ResourceLoader("calendar");

private ContentHostingService contentHostingService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class GenericCalendarImporter implements CalendarImporterService

protected Map<String, String> columnMap = null;

private static ResourceLoader rb = new ResourceLoader("calendar");
private static final ResourceLoader rb = new ResourceLoader("calendar");

// These are injected at runtime by Spring.
private CalendarService calendarService = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract class RecurrenceRuleBase implements RecurrenceRule
private Time until = null;

/*For i18n of recurrence rule description*/
protected ResourceLoader rb = new ResourceLoader("calendar");
protected static final ResourceLoader rb = new ResourceLoader("calendar");

/**
* Construct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class CSVReader extends Reader
{
private ResourceLoader rb = new ResourceLoader("calendar");
private static final ResourceLoader rb = new ResourceLoader("calendar");
private Map<String, String> defaultHeaderMap = getDefaultColumnMap();

private static final String COMMENT_LINE_PREFIX = "//";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@Slf4j
public class IcalendarReader extends Reader
{
private ResourceLoader rb = new ResourceLoader("calendar");
private static final ResourceLoader rb = new ResourceLoader("calendar");
private Map<String, String> defaultHeaderMap = getDefaultColumnMap();

private static final String TITLE_PROPERTY_NAME = "Summary";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class MeetingMakerReader extends Reader
{
private ResourceLoader rb = new ResourceLoader("calendar");
private static final ResourceLoader rb = new ResourceLoader("calendar");
private Map<String, String> defaultHeaderMap = getDefaultColumnMap();

private static final String CONTACT_SECTION_HEADER = "Contacts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
public class OutlookReader extends CSVReader
{
private static ResourceLoader rb = new ResourceLoader("calendar");
private static final ResourceLoader rb = new ResourceLoader("calendar");

private Map<String, String> defaultHeaderMap = getDefaultColumnMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class CalendarBean {
private static final String MERGED_CALENDARS_PROP = "mergedCalendarReferences";

/** Resource bundle */
private transient ResourceLoader msgs = new ResourceLoader("calendar");
private static final ResourceLoader msgs = new ResourceLoader("calendar");

private CalendarUtil calendarUtil = new CalendarUtil();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Day implements Serializable {
public final static String STYLE_WITHOUT_ACTIVITY = "calDayWithoutActivity";
public final static String STYLE_OTHER_WITH_ACTIVITY = "calOtherDayWithActivity";
public final static String STYLE_OTHER_WITHOUT_ACTIVITY = "calOtherDayWithNoActivity";
private transient ResourceLoader msgs = new ResourceLoader("calendar");
private static final ResourceLoader msgs = new ResourceLoader("calendar");

Date date = null;
String styleClass = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class EventSummary implements Serializable {
private static final long serialVersionUID = 4943854683550852507L;

/** Resource bundle */
private transient ResourceLoader msgs = new ResourceLoader("calendar");
private static final ResourceLoader msgs = new ResourceLoader("calendar");

private final int MAX_TEXT_SIZE = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class PrefsBean {
public static String SAKPROP_BASE = "calendarSummary.";

/** Resource bundle */
private transient ResourceLoader msgs = new ResourceLoader("calendar");
private static final ResourceLoader msgs = new ResourceLoader("calendar");

private CalendarUtil calendarUtil = new CalendarUtil();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public static String getLocalAMString() {
static String getLocalAMString(DateTime now) {
//we need an AM date
DateTime dt = now.withTimeAtStartOfDay();
Locale locale= new ResourceLoader("calendar").getLocale();
Locale locale = new ResourceLoader().getLocale();
DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
return df.print(dt);
}
Expand All @@ -612,7 +612,7 @@ public static String getLocalPMString() {
static String getLocalPMString(DateTime now) {
//we need an PM date
DateTime dt = now.withTimeAtStartOfDay().plusHours(14);
Locale locale = new ResourceLoader("calendar").getLocale();
Locale locale = new ResourceLoader().getLocale();
DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
return df.print(dt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CommonsContentProducer implements EntityContentProducer {
private List<String> addingEvents = new ArrayList<>();
private List<String> removingEvents = new ArrayList<>();

private ResourceLoader rl = new ResourceLoader("commons");
private static final ResourceLoader rl = new ResourceLoader("commons");

public void init() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class CommonsTool extends HttpServlet {
private SakaiProxy sakaiProxy;
private ServerConfigurationService serverConfigurationService;

private static final ResourceLoader rl = new ResourceLoader("commons");

public void init(ServletConfig config) throws ServletException {

super.init(config);
Expand Down Expand Up @@ -79,7 +81,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
String siteLanguage = sakaiProxy.getCurrentSiteLocale();

Locale locale = null;
ResourceLoader rl = null;

if (siteLanguage != null) {
String[] parts = siteLanguage.split("_");
Expand All @@ -90,10 +91,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
} else if (parts.length == 3) {
locale = new Locale(parts[0], parts[1], parts[2]);
}
rl = new ResourceLoader("commons");
rl.setContextLocale(locale);
} else {
rl = new ResourceLoader(userId, "commons");
locale = rl.getLocale();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public class ResourcesAction
private static final org.sakaiproject.content.copyright.api.CopyrightManager copyrightManager = (org.sakaiproject.content.copyright.api.CopyrightManager)
ComponentManager.get("org.sakaiproject.content.copyright.api.CopyrightManager");


private static final ResourceLoader rl = new ResourceLoader("permissions");

/**
* Action
*
Expand Down Expand Up @@ -4051,9 +4052,8 @@ public String buildListContext ( VelocityPortlet portlet,
log.debug("{}.buildListContext()", this);
// Issue SAK-19442
// ... pass the resource loader object
ResourceLoader pRb = new ResourceLoader("permissions");
HashMap<String, String> pRbValues = new HashMap<>();
for(Iterator<Entry<String, String>> mapIter = pRb.entrySet().iterator(); mapIter.hasNext();)
for(Iterator<Entry<String, String>> mapIter = rl.entrySet().iterator(); mapIter.hasNext();)
{
Entry<String, String> entry = mapIter.next();
pRbValues.put(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class ResourcesMetadata
{
/** Resource bundle using current language locale */
private ResourceLoader rb = new ResourceLoader("content");
private static final ResourceLoader rb = new ResourceLoader("content");

public static final String WIDGET_STRING = "string";
public static final String WIDGET_TEXTAREA = "textarea";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ public void sendEmail(String fromUserId, String senderAddress, String toAddress,
locale = Locale.getDefault();
}

final ResourceLoader rb = new ResourceLoader("org.sakaiproject.feedback");

String subjectTemplate = null;

if (feedbackType.equals(Constants.CONTENT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class SearchTool
{

private ResourceLoader msgs = new ResourceLoader("org.sakaiproject.tool.help.bundle.Messages");
private static final ResourceLoader msgs = new ResourceLoader("org.sakaiproject.tool.help.bundle.Messages");

private HelpManager helpManager;
private List searchResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public int getSearchCount(String searchQuery, String module, String baseName, St

@Override
public void saveOrUpdate(String baseName, String moduleName, ResourceBundle newBundle, Locale locale) {
String key = MessageBundleServiceImpl.getIndexKeyName(baseName, moduleName, locale.toString());
// We avoid doing invalidation here as were unable to detect where bundles were already loaded
// specifically when calling new ResourceLoader()
dbMessageBundleService.saveOrUpdate(baseName, moduleName, newBundle, locale);
cache.remove(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public ResourceLoader(String name, ClassLoader classLoader)
*
* @param userId user's internal sakai id (e.g. user.getId())
* @param name default ResourceBundle base filename
*
* @deprecated
*/
public ResourceLoader(String userId, String name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public class DiscussionForumTool {
private static final String FORUMS_TOOL_ID = "sakai.forums";

private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";
private static final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);

private static final String INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_SETTINGS = "cdfm_insufficient_privileges";
private static final String INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_ORGANIZE = "cdfm_insufficient_privileges";
Expand Down Expand Up @@ -6828,12 +6829,10 @@ public List getLevels()
*/
public static String getResourceBundleString(String key)
{
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
return rb.getString(key);
}

public static String getResourceBundleString(String key, Object[] args) {
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
return rb.getFormattedMessage(key, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public void setGradebookAssignment(
private static final String FORUM_TITLE = "forumTitle";

private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";
private static final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);

private static final String FORUM_STATISTICS = "dfStatisticsList";
private static final String FORUM_STATISTICS_BY_ALL_TOPICS = "dfStatisticsListByAllTopics";
Expand Down Expand Up @@ -2212,14 +2213,11 @@ public void setButtonUserName(String buttonUserName) {
this.buttonUserName = buttonUserName;
}

public static String getResourceBundleString(String key)
{
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
public static String getResourceBundleString(String key) {
return rb.getString(key);
}

public static String getResourceBundleString(String key, Object[] args) {
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
return rb.getFormattedMessage(key, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class PermissionBean {

/** Path to bundle messages */
private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";
private static final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);

/** Keys for bundle messages */
public static final String OWN = "perm_own";
Expand Down Expand Up @@ -406,9 +407,7 @@ public String getName()
* @return
* String for key passed in or [missing: key] if not found
*/
public static String getResourceBundleString(String key)
{
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
public static String getResourceBundleString(String key) {
return rb.getString(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class PrivateMessageDecoratedBean
{

private static final ResourceLoader rl = new ResourceLoader("org.sakaiproject.api.app.messagecenter.bundle.Messages");
private PrivateMessage msg;
public PrivateMessageDecoratedBean(PrivateMessage msg)
{
Expand Down Expand Up @@ -189,7 +189,6 @@ public String getAuthor() {
return msg.getAuthor();
}
public String getLabel(){
ResourceLoader rl = new ResourceLoader("org.sakaiproject.api.app.messagecenter.bundle.Messages");
return rl.getString(msg.getLabel());
}
public boolean getIsPreview() {
Expand Down Expand Up @@ -241,4 +240,4 @@ public void setReplied(boolean isReplied) {
*
* $Header$
*
**********************************************************************************/
**********************************************************************************/
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class AreaManagerImpl extends HibernateDaoSupport implements AreaManager
private static final String MESSAGES_TITLE = "cdfm_message_pvtarea";
private static final String FORUMS_TITLE = "cdfm_discussion_forums";

private ResourceLoader rb;

private IdManager idManager;

private MessageForumsForumManager forumManager;
Expand Down Expand Up @@ -97,6 +99,7 @@ public void setToolManager(ToolManager toolManager) {

public void init() {
log.info("init()");
rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
DEFAULT_AUTO_MARK_READ = serverConfigurationService.getBoolean("msgcntr.forums.default.auto.mark.threads.read", false);
}

Expand Down Expand Up @@ -378,16 +381,12 @@ private String getEventMessage(Object object) {
*/
public String getResourceBundleString(String key)
{
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
return rb.getString(key);
}

private String getResourceBundleString(String key, Object[] replacementValues)
{
final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
return rb.getFormattedMessage(key, replacementValues);


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public class MembershipManagerImpl implements MembershipManager{
private PrivateMessageManager prtMsgManager;

private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";
private ResourceLoader rl = new ResourceLoader(MESSAGECENTER_BUNDLE);
private ResourceLoader rl;


public void init() {
log.info("init()");
;
}
rl = new ResourceLoader(MESSAGECENTER_BUNDLE);
}

/**
*
Expand Down
Loading

0 comments on commit 66e7b3d

Please sign in to comment.