package uk.ac.edukapp.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class ServletUtils {

	public static String getCookieValue(Cookie[] cookies, String cookieName,
			String defaultValue) {
		for (int i = 0; i < cookies.length; i++) {
			Cookie cookie = cookies[i];
			if (cookieName.equals(cookie.getName()))
				return (cookie.getValue());
		}
		return (defaultValue);
	}

	public static String getServletRootURL ( HttpServletRequest request ) {
		String serverName = request.getServerName();
		int serverPort = request.getServerPort();
		String protocol;
		
		if (request.isSecure()){
			protocol = "https";
		}
		else {
			protocol = "http";
		}
		
		String root = protocol+"://"+serverName+":"+serverPort+"/edukapp";
		
		return root;
	}
	
	
	public static boolean isNumeric(String str) {
		return str.matches("-?\\d+(.\\d+)?");
	}
}

@@ -108,16 +108,78 @@
 est;%0D%0A%0D%0A
+import org.apache.commons.validator.routines.UrlValidator;%0D%0A%0D%0A
 public c
@@ -979,11 +979,204 @@
 );%0D%0A%09%7D%0D%0A
+%09%0D%0A%09public static boolean checkURL ( String url ) %7B%0D%0A%09%09String schemes%5B%5D = %7B%22http%22, %22https%22%7D;%0D%0A%09%09UrlValidator urlValidator = new UrlValidator(schemes);%0D%0A%09%09return urlValidator.isValid(url);%0D%0A%09%7D%0D%0A
 %7D%0D%0A

Support for web url widget creator