public class BasicLTIUtil extends Object
Sample Descriptor
<?xml version="1.0" encoding="UTF-8"?> <basic_lti_link xmlns="http://www.imsglobal.org/xsd/imsbasiclti_v1p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <title>generated by tp+user</title> <description>generated by tp+user</description> <custom> <parameter key="keyname">value</parameter> </custom> <extensions platform="www.lms.com"> <parameter key="keyname">value</parameter> </extensions> <launch_url>url to the basiclti launch URL</launch_url> <secure_launch_url>url to the basiclti launch URL</secure_launch_url> <icon>url to an icon for this tool (optional)</icon> <secure_icon>url to an icon for this tool (optional)</secure_icon> <cartridge_icon identifierref="BLTI001_Icon"/> <vendor> <code>vendor.com</code> <name>Vendor Name</name> <description> This is a Grade Book that supports many column types. </description> <contact> <email>support@vendor.com</email> </contact> <url>http://www.vendor.com/product</url> </vendor> </basic_lti_link>
Modifier and Type | Field and Description |
---|---|
static String |
ISO_8601_FORMAT |
Constructor and Description |
---|
BasicLTIUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
adaptToCustomPropertyName(String propertyName)
A simple utility method which implements the specified semantics of custom
properties.
|
static boolean |
checkProperties(Map<String,String> postProp,
String url,
String method,
String oauth_consumer_key,
String oauth_consumer_secret)
Check if the fields are properly signed
|
static boolean |
checkProperties(Properties postProp,
String url,
String method,
String oauth_consumer_key,
String oauth_consumer_secret)
Deprecated.
|
static Map<String,String> |
convertToMap(Properties properties)
Simple utility method to help with the migration from Properties to
Map
|
static Properties |
convertToProperties(Map<String,String> map)
Deprecated.
Should migrate to Map
|
static boolean |
equals(String str1,
String str2)
Compares two Strings, returning
true if they are equal. |
static boolean |
equalsIgnoreCase(String str1,
String str2)
Compares two Strings, returning
true if they are equal
ignoring the case. |
static String |
getISO8601()
Return a ISO 8601 formatted date
|
static String |
getISO8601(Date date)
Return a ISO 8601 formatted date
|
static String |
getOAuthURL(String method,
String url,
String oauth_consumer_key,
String oauth_secret)
getOAuthURL - Form a GET request signed by OAuth
|
static String |
getOAuthURL(String method,
String url,
String oauth_consumer_key,
String oauth_secret,
String signature)
getOAuthURL - Form a GET request signed by OAuth
|
static String |
getRealPath(HttpServletRequest request,
String extUrl) |
static String |
getRealPath(String servletUrl,
String extUrl)
Simple utility method deal with a request that has the wrong URL when behind
a proxy.
|
static int |
getResponseCode(HttpURLConnection connection)
getResponseCode - Read the HTTP Response
|
static String |
htmlspecialchars(String input) |
static boolean |
isBlank(String str)
Checks if a String is whitespace, empty ("") or null.
|
static boolean |
isNotBlank(String str)
Checks if a String is not empty (""), not null and not whitespace only.
|
static boolean |
isRequest(HttpServletRequest request) |
static String |
mapKeyName(String keyname)
The parameter name is mapped to lower case and any character that is
neither a number or letter is replaced with an "underscore".
|
static boolean |
parseDescriptor(Map<String,String> launch_info,
Map<String,String> postProp,
String descriptor) |
static boolean |
parseDescriptor(Properties launch_info,
Properties postProp,
String descriptor)
Deprecated.
|
static String |
postLaunchHTML(Map<String,String> cleanProperties,
String endpoint,
String launchtext,
boolean autosubmit,
boolean debug,
Map<String,String> extra)
Create the HTML to render a POST form and then automatically submit it.
|
static String |
postLaunchHTML(Map<String,String> cleanProperties,
String endpoint,
String launchtext,
boolean debug,
Map<String,String> extra)
Create the HTML to render a POST form and then automatically submit it.
|
static String |
postLaunchHTML(Properties cleanProperties,
String endpoint,
String launchtext,
boolean autosubmit,
boolean debug,
Map<String,String> extra)
Deprecated.
|
static String |
postLaunchHTML(Properties cleanProperties,
String endpoint,
String launchtext,
boolean debug,
Map<String,String> extra)
Deprecated.
|
static String |
prepareForExport(String descriptor) |
static String |
readHttpResponse(HttpURLConnection connection)
readHttpResponse - Read the HTTP Response
|
static HttpURLConnection |
sendOAuthURL(String method,
String url,
String oauth_consumer_key,
String oauth_secret)
getOAuthURL - Form a GET request signed by OAuth
|
static void |
setProperty(Map<String,String> map,
String key,
String value)
Mutates the passed Map
|
static void |
setProperty(Properties props,
String key,
String value)
Deprecated.
|
static Map<String,String> |
signProperties(Map<String,String> postProp,
String url,
String method,
String oauth_consumer_key,
String oauth_consumer_secret,
String tool_consumer_instance_guid,
String tool_consumer_instance_description,
String tool_consumer_instance_url,
String tool_consumer_instance_name,
String tool_consumer_instance_contact_email,
Map<String,String> extra)
Add the necessary fields and sign.
|
static Properties |
signProperties(Properties postProp,
String url,
String method,
String oauth_consumer_key,
String oauth_consumer_secret,
String org_id,
String org_desc,
String org_url,
Map<String,String> extra)
|
static String |
toNull(String str) |
static String |
validateDescriptor(String descriptor) |
static Object |
validateMessage(HttpServletRequest request,
String URL,
String oauth_secret,
String expected_oauth_key) |
public static final String ISO_8601_FORMAT
public static boolean isRequest(HttpServletRequest request)
public static Object validateMessage(HttpServletRequest request, String URL, String oauth_secret, String expected_oauth_key)
public static String adaptToCustomPropertyName(String propertyName)
i.e. The parameter names are mapped to lower case and any character that is neither a number nor letter in a parameter name is replaced with an "underscore".
e.g. Review:Chapter=1.2.56 would map to custom_review_chapter=1.2.56.
propertyName
- public static Properties signProperties(Properties postProp, String url, String method, String oauth_consumer_key, String oauth_consumer_secret, String org_id, String org_desc, String org_url, Map<String,String> extra)
signProperties(Map, String, String, String, String, String, String, String, String, String, Map)
postProp
- url
- method
- oauth_consumer_key
- oauth_consumer_secret
- org_id
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_GUID
org_desc
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_DESCRIPTION
org_url
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_URL
extra
- public static Map<String,String> signProperties(Map<String,String> postProp, String url, String method, String oauth_consumer_key, String oauth_consumer_secret, String tool_consumer_instance_guid, String tool_consumer_instance_description, String tool_consumer_instance_url, String tool_consumer_instance_name, String tool_consumer_instance_contact_email, Map<String,String> extra)
postProp
- url
- method
- oauth_consumer_key
- oauth_consumer_secret
- tool_consumer_instance_guid
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_GUID
tool_consumer_instance_description
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_DESCRIPTION
tool_consumer_instance_url
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_URL
tool_consumer_instance_name
- See: BasicLTIConstants.TOOL_CONSUMER_INSTANCE_NAME
tool_consumer_instance_contact_email
- See:
BasicLTIConstants.TOOL_CONSUMER_INSTANCE_CONTACT_EMAIL
extra
- public static boolean checkProperties(Properties postProp, String url, String method, String oauth_consumer_key, String oauth_consumer_secret)
checkProperties(Map, String, String, String, String)
postProp
- url
- method
- oauth_consumer_key
- oauth_consumer_secret
- public static boolean checkProperties(Map<String,String> postProp, String url, String method, String oauth_consumer_key, String oauth_consumer_secret)
postProp
- url
- method
- oauth_consumer_key
- oauth_consumer_secret
- public static String postLaunchHTML(Properties cleanProperties, String endpoint, String launchtext, boolean debug, Map<String,String> extra)
postLaunchHTML(Map, String, String, boolean, Map)
cleanProperties
- endpoint
- The LTI launch url.launchtext
- The LTI launch text. Used if javascript is turned off.debug
- Useful for viewing the HTML before posting to end point.extra
- public static String postLaunchHTML(Properties cleanProperties, String endpoint, String launchtext, boolean autosubmit, boolean debug, Map<String,String> extra)
postLaunchHTML(Map, String, String, boolean, boolean, Map)
cleanProperties
- endpoint
- The LTI launch url.launchtext
- The LTI launch text. Used if javascript is turned off.autosubmit
- Whether or not we want the form autosubmitteddebug
- Useful for viewing the HTML before posting to end point.extra
- public static String postLaunchHTML(Map<String,String> cleanProperties, String endpoint, String launchtext, boolean debug, Map<String,String> extra)
cleanProperties
- endpoint
- The LTI launch url.launchtext
- The LTI launch text. Used if javascript is turned off.debug
- Useful for viewing the HTML before posting to end point.extra
- Useful for viewing the HTML before posting to end point.public static String postLaunchHTML(Map<String,String> cleanProperties, String endpoint, String launchtext, boolean autosubmit, boolean debug, Map<String,String> extra)
cleanProperties
- endpoint
- The LTI launch url.launchtext
- The LTI launch text. Used if javascript is turned off.autosubmit
- Whether or not we want the form autosubmittedextra
- Useful for viewing the HTML before posting to end point.public static String getOAuthURL(String method, String url, String oauth_consumer_key, String oauth_secret)
method
- url
- oauth_consumer_key
- oauth_secret
- public static String getOAuthURL(String method, String url, String oauth_consumer_key, String oauth_secret, String signature)
method
- url
- oauth_consumer_key
- oauth_secret
- signature
- public static HttpURLConnection sendOAuthURL(String method, String url, String oauth_consumer_key, String oauth_secret)
method
- url
- oauth_consumer_key
- oauth_secret
- HttpURLConnection connection = sendOAuthURL('GET', url, oauth_consumer_key, oauth_secret)
int responseCode = connection.getResponseCode();
String data = readHttpResponse(connection)public static int getResponseCode(HttpURLConnection connection)
connection
- public static String readHttpResponse(HttpURLConnection connection)
connection
- public static boolean parseDescriptor(Properties launch_info, Properties postProp, String descriptor)
parseDescriptor(Map, Map, String)
launch_info
- Variable is mutated by this method.postProp
- Variable is mutated by this method.descriptor
- public static boolean parseDescriptor(Map<String,String> launch_info, Map<String,String> postProp, String descriptor)
launch_info
- Variable is mutated by this method.postProp
- Variable is mutated by this method.descriptor
- public static String mapKeyName(String keyname)
public static void setProperty(Map<String,String> map, String key, String value)
map
- Variable is mutated by this method.key
- value
- public static void setProperty(Properties props, String key, String value)
setProperty(Map, String, String)
props
- Variable is mutated by this method.key
- value
- public static String getRealPath(String servletUrl, String extUrl)
servletUrl
- extUrl
- The url that the external world sees us as responding to. This needs to be
up to but not including the last slash like and not include any path information
http://www.sakaiproject.org - although we do compensate for extra stuff at the end.public static String getRealPath(HttpServletRequest request, String extUrl)
public static Map<String,String> convertToMap(Properties properties)
properties
- public static Properties convertToProperties(Map<String,String> map)
map
- public static boolean isBlank(String str)
Checks if a String is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false
str
- the String to check, may be nulltrue
if the String is null, empty or whitespacepublic static boolean isNotBlank(String str)
Checks if a String is not empty (""), not null and not whitespace only.
StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true
str
- the String to check, may be nulltrue
if the String is not empty and not null and not
whitespacepublic static boolean equals(String str1, String str2)
Compares two Strings, returning true
if they are equal.
null
s are handled without exceptions. Two null
references are considered to be equal. The comparison is case sensitive.
StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false
str1
- the first String, may be nullstr2
- the second String, may be nulltrue
if the Strings are equal, case sensitive, or both
null
String.equals(Object)
public static boolean equalsIgnoreCase(String str1, String str2)
Compares two Strings, returning true
if they are equal
ignoring the case.
null
s are handled without exceptions. Two null
references are considered equal. Comparison is case insensitive.
StringUtils.equalsIgnoreCase(null, null) = true StringUtils.equalsIgnoreCase(null, "abc") = false StringUtils.equalsIgnoreCase("abc", null) = false StringUtils.equalsIgnoreCase("abc", "abc") = true StringUtils.equalsIgnoreCase("abc", "ABC") = true
str1
- the first String, may be nullstr2
- the second String, may be nulltrue
if the Strings are equal, case insensitive, or
both null
String.equalsIgnoreCase(String)
public static String getISO8601()
Copyright © 2003–2019 The Sakai Foundation. All rights reserved.