Index: lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java =================================================================== diff -u -r65ed4da382b320542dcd88cb1375662dcfac8769 -r216fbff3a88bbd983de02053931906fa476fc3ce --- lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision 65ed4da382b320542dcd88cb1375662dcfac8769) +++ lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision 216fbff3a88bbd983de02053931906fa476fc3ce) @@ -94,8 +94,8 @@ } /** - * @exception IllegalArgumentException - - * if not set + * @exception IllegalArgumentException + * - if not set */ public static void checkObject(String paramName, Object paramValue) throws IllegalArgumentException { boolean isNull = paramValue == null; @@ -110,8 +110,8 @@ /** * @return integer value of paramValue - * @exception IllegalArgumentException - - * if (a) not set and is not optional or (b) not integer + * @exception IllegalArgumentException + * - if (a) not set and is not optional or (b) not integer */ public static Integer checkInteger(String paramName, String paramValue, boolean isOptional) throws IllegalArgumentException { @@ -129,8 +129,8 @@ /** * @return long value of paramValue - * @exception IllegalArgumentException - - * if (a) not set and is not optional or (b) not long + * @exception IllegalArgumentException + * - if (a) not set and is not optional or (b) not long */ public static Long checkLong(String paramName, String paramValue, boolean isOptional) throws IllegalArgumentException { @@ -151,8 +151,8 @@ * null * * @return long value of paramValue - * @exception IllegalArgumentException - - * if not set or not long + * @exception IllegalArgumentException + * - if not set or not long */ public static long checkLong(String paramName, Long paramValue, boolean isOptional) throws IllegalArgumentException { if (!isOptional) { @@ -163,8 +163,8 @@ /** * @return boolean value of paramValue - * @exception IllegalArgumentException - - * if not set or not boolean + * @exception IllegalArgumentException + * - if not set or not boolean */ public static boolean checkBoolean(String paramName, String paramValue) throws IllegalArgumentException { @@ -175,8 +175,10 @@ /** * Read an int parameter, throwing exception if null or not a integer * - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @return parameter value */ public static int readIntParam(HttpServletRequest req, String paramName) { @@ -186,8 +188,10 @@ /** * Read an int parameter, throwing exception if ( not optional and null ) or not a integer * - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @param isOptional * @return parameter value */ @@ -198,8 +202,10 @@ /** * Read an long parameter, throwing exception if null or not a long * - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @return parameter value */ public static long readLongParam(HttpServletRequest req, String paramName) { @@ -209,8 +215,10 @@ /** * Read an long parameter, throwing exception if ( not optional and null ) or not a long * - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @param isOptional * @return parameter value */ @@ -219,17 +227,21 @@ } /** - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @return parameter value */ public static String readStrParam(HttpServletRequest req, String paramName) { return readStrParam(req, paramName, false); } /** - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @param isOptional * @return parameter value */ @@ -241,21 +253,25 @@ } /** - * @param req - - * @param paramName - + * @param req + * - + * @param paramName + * - * @return parameter value - * @exception IllegalArgumentException - - * if valid boolean parameter value is not found + * @exception IllegalArgumentException + * - if valid boolean parameter value is not found */ public static boolean readBooleanParam(HttpServletRequest req, String paramName) throws IllegalArgumentException { return checkBoolean(paramName, req.getParameter(paramName)); } /** - * @param req - - * @param paramName - - * @param defaultValue - - * if valid boolean parameter value is not found, return this value + * @param req + * - + * @param paramName + * - + * @param defaultValue + * - if valid boolean parameter value is not found, return this value * @return parameter value */ public static boolean readBooleanParam(HttpServletRequest req, String paramName, boolean defaultValue) { @@ -274,7 +290,8 @@ * TODO default proper exception at lams level to replace RuntimeException TODO isTesting should be removed when * login is done properly. * - * @param req - + * @param req + * - * @return username from principal object */ public static String getUsername(HttpServletRequest req, boolean isTesting) throws RuntimeException { @@ -372,11 +389,11 @@ * Append a parameter to a requested url. * * @param parameterName - * the name of the parameter + * the name of the parameter * @param parameterValue - * the value of the parameter + * the value of the parameter * @param learnerUrl - * the target url + * the target url * @return the url with parameter appended. */ public static String appendParameterToURL(String url, String parameterName, String parameterValue) { @@ -390,7 +407,7 @@ * It is using a null safe String util method to checkup the url String and append proper deliminator if necessary. * * @param url - * the url needs to append deliminator. + * the url needs to append deliminator. * @return target url with the deliminator; */ public static String appendParameterDeliminator(String url) { @@ -409,7 +426,7 @@ * appended to the server url from the LAMS Configuration. * * @param url - * e.g. tool/lanb11/starter/learner.do + * e.g. tool/lanb11/starter/learner.do * @return complete url */ public static String convertToFullURL(String url) { @@ -428,7 +445,8 @@ } /** - * Convert any newslines in a string to
. If input = null, returns null. + * Convert any newslines in a string to
+ * . If input = null, returns null. */ public static String convertNewlines(String input) { if (input != null) { @@ -442,7 +460,7 @@ * Strips HTML tags and leave "pure" text. Useful for CKeditor created text. * * @param text - * string to process + * string to process * @return string after stripping */ public static String removeHTMLtags(String text) { @@ -602,19 +620,18 @@ return conn.getInputStream(); } - + public static String extractParameterValue(String url, String param) { if (!StringUtils.isBlank(url) && !StringUtils.isBlank(param)) { int quotationMarkIndex = url.indexOf("?"); String queryPart = quotationMarkIndex > -1 ? url.substring(quotationMarkIndex + 1) : url; String[] paramEntries = queryPart.split("&"); for (String paramEntry : paramEntries) { String[] paramEntrySplitted = paramEntry.split("="); - if (param.equalsIgnoreCase(paramEntrySplitted[0])) { + if (paramEntrySplitted.length > 1 && param.equalsIgnoreCase(paramEntrySplitted[0])) { return paramEntrySplitted[1]; } } - } return null; }