FELIX-3290 Unify cookie handling:
  - global prefix "felix-webconsole-" with local names (bundlelist, locale)
  - sticky cookie for 20 years
  - bind to web console root path

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1222209 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/resources/res/lib/support.js b/webconsole/src/main/resources/res/lib/support.js
index fdcc3c4..0698624 100644
--- a/webconsole/src/main/resources/res/lib/support.js
+++ b/webconsole/src/main/resources/res/lib/support.js
@@ -268,6 +268,30 @@
 	return element;
 }
 
+/**
+ * Sets the name cookie at the appRoot (/system/console by default) path
+ * to last for 20 years.
+ * @param name The name of the cookie
+ * @param value The value for the cookie
+ */
+function setCookie( /* String */name, /* String */value) {
+    var date = new Date();
+    date.setFullYear(date.getFullYear() + 20);
+    $.cookies.set("felix-webconsole-" + name, value, {
+        expiresAt : date,
+        path : appRoot
+    });
+}
+
+/**
+ * Returns the value of the name cookie or nothing if the cookie does
+ * not exist or is not accessible.
+ * @param name The name of the cookie
+ */
+/* String */ function getCookie(/*String */name) {
+    $.cookies.get("felix-webconsole-" + name);
+}
+
 // language selection element
 var langSelect = false;
 $(document).ready(function() {
@@ -275,14 +299,10 @@
 		function() { $(this).find('.flags').show('blind') },
 		function() { $(this).find('.flags').hide('blind') });
 	langSelect.find('.flags img').click(function() {
-	        var date = new Date();
-	        date.setFullYear(date.getFullYear() + 20);
-		$.cookies.set('felix.webconsole.locale',
-			$(this).attr('alt'),
-			{ expiresAt: date });
+        setCookie("locale", $(this).attr('alt'));
 		location.reload();
 	});
-	var locale = $.cookies.get('felix.webconsole.locale');
+	var locale = getCookie("locale");
 	if (locale) {
 		if ( !$.datepicker.regional[locale] ) locale = '';
 		$.datepicker.setDefaults($.datepicker.regional[locale]);
diff --git a/webconsole/src/main/resources/res/ui/bundles.js b/webconsole/src/main/resources/res/ui/bundles.js
index ff429be..9406b16 100644
--- a/webconsole/src/main/resources/res/ui/bundles.js
+++ b/webconsole/src/main/resources/res/ui/bundles.js
@@ -41,8 +41,10 @@
     }
     initStaticWidgets();
 
-	var cv = $.cookies.get("webconsolebundlelist");
-	if (cv) bundlesTable.trigger('sorton', [cv]);
+	var cv = getCookie("bundlelist");
+	if (cv) {
+	    bundlesTable.trigger('sorton', [cv]);
+	}
 
 	// show dialog on error
 	if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
@@ -261,9 +263,11 @@
 		},
 		textExtraction:mixedLinksExtraction
 	}).bind("sortEnd", function() {
-		var t = bundlesTable.eq(0).attr("config");
-		if (t.sortList) $.cookies.set("webconsolebundlelist", t.sortList);
-	});
+        var t = bundlesTable.eq(0).attr("config");
+        if (t.sortList) {
+            setCookie("bundlelist", t.sortList);
+        }
+    });
 	bundlesBody     = bundlesTable.find('tbody');
 	bundlesTemplate = bundlesBody.find('tr').clone();