Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.kuali.student.r2.common.util;
 
 
 import java.util.Date;
This is a library of utility methods that can be used when working with the context info.

Author(s):
Kuali Rice Team (kuali-rice@googlegroups.com)
public class ContextUtils {
    
    
Create a new instance of ContextInfo.

Returns:
    public static ContextInfo getContextInfo(){
        ContextInfo contextInfo = new ContextInfo();
        UserSession userSession = GlobalVariables.getUserSession();
        if (userSession != null) {
            contextInfo.setPrincipalId(userSession.getPrincipalId());
        }
        return contextInfo;
    }

    
Creates a default context with the current user and date and default locale

Returns:
a default context
    public static ContextInfo createDefaultContextInfo(){
        ContextInfo contextInfo = new ContextInfo();
        UserSession userSession = GlobalVariables.getUserSession();
        if (userSession != null) {
            contextInfo.setAuthenticatedPrincipalId(userSession.getPrincipalId());
            contextInfo.setPrincipalId(userSession.getPrincipalId());
        }
        contextInfo.setCurrentDate(new Date());
        LocaleInfo localeInfo = new LocaleInfo();
        localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
        localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
        contextInfo.setLocale(localeInfo);
        return contextInfo;
    }
New to GrepCode? Check out our FAQ X