You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/12/14 22:02:01 UTC

[1/5] git commit: WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added

Updated Branches:
  refs/heads/wicket-6.x 94c0c8415 -> dd5de0e55


WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/90235c1c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/90235c1c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/90235c1c

Branch: refs/heads/wicket-6.x
Commit: 90235c1c2ef7eb6ffa9d5d836ce7d0a398ca2821
Parents: ba2e5ce
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Dec 12 15:51:57 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Dec 12 15:51:57 2013 +0200

----------------------------------------------------------------------
 Gruntfile.js                                    |   3 +-
 .../markup/html/pages/AjaxBrowserInfoForm.java  |  74 +++++++++++
 .../markup/html/pages/BrowserInfoForm.html      |  33 +----
 .../markup/html/pages/BrowserInfoForm.java      |  70 ++++++-----
 .../markup/html/pages/BrowserInfoPage.html      |   2 +-
 .../markup/html/pages/BrowserInfoPage.java      |  26 ++--
 .../markup/html/pages/wicket-browser-info.js    |  83 ++++++++++++
 .../ajaxhellobrowser/AjaxHelloBrowser.html      |  24 ++++
 .../ajaxhellobrowser/AjaxHelloBrowser.java      | 126 +++++++++++++++++++
 .../HelloBrowserApplication.java                |  33 +++++
 .../examples/hellobrowser/HelloBrowser.java     |  17 +--
 .../hellobrowser/HelloBrowserApplication.java   |  14 +--
 .../wicket/examples/homepage/HomePage.html      |   3 +-
 wicket-examples/src/main/webapp/WEB-INF/web.xml |  16 +++
 14 files changed, 428 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
index cd47c7a..10dbdc3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -23,7 +23,8 @@ module.exports = function(grunt) {
 			'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js',
 			"wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckSelector.js",
 			"wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js",
-			"wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.js"
+			"wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.js",
+			"wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js"
 		],
 		extensionsJs = [
 			"wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js",

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
new file mode 100644
index 0000000..86b2bb1
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
@@ -0,0 +1,74 @@
+package org.apache.wicket.markup.html.pages;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxCallListener;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
+import org.apache.wicket.core.request.ClientInfo;
+import org.apache.wicket.markup.html.form.Form;
+
+/**
+ * An extension of BrowserInfoForm that uses AjaxFormSubmitBehavior
+ * to collect the client info without redirect to another page
+ */
+public class AjaxBrowserInfoForm extends BrowserInfoForm
+{
+	/**
+	 * Constructor.
+	 *
+	 * @param id component id
+	 */
+	public AjaxBrowserInfoForm(String id)
+	{
+		super(id);
+	}
+
+	@Override
+	protected Form<? extends ClientPropertiesBean> createForm(String componentId)
+	{
+		Form<? extends ClientPropertiesBean> f = super.createForm(componentId);
+		f.add(new AjaxFormSubmitBehavior(f, "domready")
+		{
+			@Override
+			protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+			{
+				super.updateAjaxAttributes(attributes);
+				AjaxCallListener listener = new AjaxCallListener();
+				listener.onBefore(String.format("Wicket.BrowserInfo.populateFields('%s');", getFormMarkupId()));
+				attributes.getAjaxCallListeners().add(listener);
+			}
+
+			@Override
+			protected void onAfterSubmit(AjaxRequestTarget target)
+			{
+				super.onAfterSubmit(target);
+				ClientInfo info = getSession().getClientInfo();
+				AjaxBrowserInfoForm.this.onAfterSubmit(target, info);
+			}
+		});
+		return f;
+	}
+
+	/**
+	 * A callback method called when the client info is collected
+	 *
+	 * @param target
+	 *      The Ajax request handler
+	 * @param info
+	 *      The client info
+	 */
+	protected void onAfterSubmit(AjaxRequestTarget target, ClientInfo info)
+	{
+	}
+
+	/**
+	 * Does nothing.
+	 *
+	 * Use {@linkplain #onAfterSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.core.request.ClientInfo)}
+	 */
+	@Override
+	protected final void afterSubmit()
+	{
+		super.afterSubmit();
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
index 2e46491..5676493 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
@@ -15,39 +15,8 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!DOCTYPE html>
 <html xmlns:wicket="http://wicket.apache.org">
-	<wicket:head>
-		<script type="text/javascript">/*<![CDATA[*/
-		function submitform() {
-			document.postback.navigatorAppName.value = window.navigator.appName;
-			document.postback.navigatorAppVersion.value = window.navigator.appVersion;
-			document.postback.navigatorAppCodeName.value = window.navigator.appCodeName;
-			var cookieEnabled = (window.navigator.cookieEnabled)? true : false;
-			if (typeof window.navigator.cookieEnabled == "undefined" && !cookieEnabled) { 
-				document.cookie = "wickettestcookie";
-				cookieEnabled = (document.cookie.indexOf("wickettestcookie")!=-1)? true : false;
-			}
-			document.postback.navigatorCookieEnabled.value = cookieEnabled;
-			document.postback.navigatorJavaEnabled.value =  window.navigator.javaEnabled();
-			document.postback.navigatorLanguage.value = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
-			document.postback.navigatorPlatform.value = window.navigator.platform;
-			document.postback.navigatorUserAgent.value = window.navigator.userAgent;
-			if (window.screen) {
-				document.postback.screenWidth.value = window.screen.width;
-				document.postback.screenHeight.value = window.screen.height;
-				document.postback.screenColorDepth.value = window.screen.colorDepth;
-			}
-			document.postback.utcOffset.value = (new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-			document.postback.utcDSTOffset.value = (new Date(new Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-			document.postback.browserWidth.value =  window.innerWidth || document.body.offsetWidth;
-			document.postback.browserHeight.value =  window.innerHeight || document.body.offsetHeight;
-			document.postback.hostname.value =  window.location.hostname;
-
-			document.postback.submit();
-		}
-		/*]]>*/</script>
-	</wicket:head>
 	<wicket:panel>
 		<form name="postback" wicket:id="postback" style="position:absolute; left: -10000px;">
 			<input type="text" wicket:id="navigatorAppName" value="test" />

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
index 0b6d530..653c9eb 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
@@ -16,7 +16,8 @@
  */
 package org.apache.wicket.markup.html.pages;
 
-import org.apache.wicket.util.io.IClusterable;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.markup.html.panel.Panel;
@@ -24,23 +25,24 @@ import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.protocol.http.ClientProperties;
 import org.apache.wicket.protocol.http.WebSession;
 import org.apache.wicket.protocol.http.request.WebClientInfo;
-import org.apache.wicket.core.request.ClientInfo;
 import org.apache.wicket.request.cycle.RequestCycle;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.util.io.IClusterable;
 
 /**
  * Form for posting JavaScript properties.
  */
 public class BrowserInfoForm extends Panel
 {
-	/** log. */
-	private static final Logger log = LoggerFactory.getLogger(BrowserInfoForm.class);
-
 	private static final long serialVersionUID = 1L;
 
 	/**
-	 * Construct.
+	 * The special form that submits the client/browser info
+	 */
+	private final Form<? extends ClientPropertiesBean> form;
+
+	/**
+	 * Constructor.
 	 * 
 	 * @param id
 	 *            component id
@@ -49,21 +51,32 @@ public class BrowserInfoForm extends Panel
 	{
 		super(id);
 
-		Form<ClientPropertiesBean> form = new Form<ClientPropertiesBean>("postback",
-			new CompoundPropertyModel<ClientPropertiesBean>(new ClientPropertiesBean()))
+		this.form = createForm("postback");
+		form.setOutputMarkupId(true);
+		add(form);
+	}
+
+	/**
+	 * Creates the form
+	 *
+	 * @param componentId
+	 *      the id for the Form component
+	 * @return the Form that will submit the data
+	 */
+	protected Form<? extends ClientPropertiesBean> createForm(String componentId)
+	{
+		Form<ClientPropertiesBean> form = new Form<ClientPropertiesBean>(componentId,
+				new CompoundPropertyModel<ClientPropertiesBean>(new ClientPropertiesBean()))
 		{
 			private static final long serialVersionUID = 1L;
 
-			/**
-			 * @see org.apache.wicket.markup.html.form.Form#onSubmit()
-			 */
 			@Override
 			protected void onSubmit()
 			{
 				ClientPropertiesBean propertiesBean = getModelObject();
 
 				RequestCycle requestCycle = getRequestCycle();
-				WebSession session = (WebSession)getSession();
+				WebSession session = getWebSession();
 				WebClientInfo clientInfo = session.getClientInfo();
 
 				if (clientInfo == null)
@@ -94,27 +107,28 @@ public class BrowserInfoForm extends Panel
 		form.add(new TextField<String>("browserWidth"));
 		form.add(new TextField<String>("browserHeight"));
 		form.add(new TextField<String>("hostname"));
-		add(form);
+		return form;
 	}
 
-
-	/**
-	 * Log a warning that for in order to use this page, you should really be using
-	 * {@link WebClientInfo}.
-	 * 
-	 * @param clientInfo
-	 *            the actual client info object
-	 */
-	void warnNotUsingWebClientInfo(ClientInfo clientInfo)
+	protected void afterSubmit()
 	{
-		log.warn("using " + getClass().getName() + " makes no sense if you are not using " +
-			WebClientInfo.class.getName() + " (you are using " + clientInfo.getClass().getName() +
-			" instead)");
 	}
 
-	protected void afterSubmit()
+	@Override
+	public void renderHead(IHeaderResponse response)
 	{
+		super.renderHead(response);
+
+		response.render(JavaScriptHeaderItem.forReference(
+				new JavaScriptResourceReference(BrowserInfoForm.class, "wicket-browser-info.js")));
+	}
 
+	/**
+	 * @return The markup id of the form that submits the client info
+	 */
+	public String getFormMarkupId()
+	{
+		return form.getMarkupId();
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
index 2427950..81019d4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
@@ -20,7 +20,7 @@
 	<head>
 		<meta wicket:id="meta" http-equiv="refresh" />
 	</head>
-	<body onload="javascript:submitform();">
+	<body>
 		If you see this, it means that both javascript and meta-refresh are not support by
 		your browser configuration. Please click <a wicket:id="link" href="#">this link</a> to
 		continue to the original destination.

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
index 3f5452b..373cbb5 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
@@ -17,6 +17,8 @@
 package org.apache.wicket.markup.html.pages;
 
 import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnLoadHeaderItem;
 import org.apache.wicket.markup.html.WebComponent;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.WebPage;
@@ -29,7 +31,6 @@ import org.apache.wicket.protocol.http.request.WebClientInfo;
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.settings.IRequestCycleSettings;
 
-
 /**
  * <p>
  * This page uses a form post right after the page has loaded in the browser, using JavaScript or
@@ -49,6 +50,8 @@ public class BrowserInfoPage extends WebPage
 {
 	private static final long serialVersionUID = 1L;
 
+	private BrowserInfoForm browserInfoForm;
+
 	/**
 	 * Bookmarkable constructor. This is not for normal framework client use. It will be called
 	 * whenever JavaScript is not supported, and the browser info page's meta refresh fires to this
@@ -74,9 +77,15 @@ public class BrowserInfoPage extends WebPage
 		continueToOriginalDestination();
 	}
 
-	/**
-	 * @see org.apache.wicket.Component#isVersioned()
-	 */
+	@Override
+	public void renderHead(IHeaderResponse response)
+	{
+		super.renderHead(response);
+
+		response.render(OnLoadHeaderItem.forScript(
+				String.format("Wicket.BrowserInfo.submitForm('%s')", browserInfoForm.getFormMarkupId())));
+	}
+
 	@Override
 	public boolean isVersioned()
 	{
@@ -117,18 +126,17 @@ public class BrowserInfoPage extends WebPage
 		WebMarkupContainer link = new WebMarkupContainer("link");
 		link.add(AttributeModifier.replace("href", urlModel));
 		add(link);
-		add(new BrowserInfoForm("postback")
+
+		browserInfoForm = new BrowserInfoForm("postback")
 		{
 			private static final long serialVersionUID = 1L;
 
-			/**
-			 * @see org.apache.wicket.markup.html.pages.BrowserInfoForm#afterSubmit()
-			 */
 			@Override
 			protected void afterSubmit()
 			{
 				continueToOriginalDestination();
 			}
-		});
+		};
+		add(browserInfoForm);
 	}
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
new file mode 100644
index 0000000..6fb1fa3
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Wicket BrowserInfo Support
+ *
+ * Populates a special form with the client/browser info
+ * and submits it to the server
+ */
+
+;(function (undefined) {
+
+	'use strict';
+
+	if (typeof(Wicket) === 'undefined') {
+		window.Wicket = {};
+	}
+
+	if (typeof(Wicket.BrowserInfo) === 'undefined') {
+		window.Wicket.BrowserInfo = {
+
+			/**
+			 * Populates the form elements with the client info
+			 *
+			 * @param formMarkupId   The markup id of the special form
+			 * @returns {HTMLFormElement} The special form
+			 */
+			populateFields: function(formMarkupId) {
+				var postbackForm = document.getElementById(formMarkupId);
+				postbackForm.navigatorAppName.value = window.navigator.appName;
+				postbackForm.navigatorAppVersion.value = window.navigator.appVersion;
+				postbackForm.navigatorAppCodeName.value = window.navigator.appCodeName;
+				var cookieEnabled = (window.navigator.cookieEnabled);
+				if (typeof(window.navigator.cookieEnabled) === "undefined" && !cookieEnabled) {
+					document.cookie = "wickettestcookie";
+					cookieEnabled = (document.cookie.indexOf("wickettestcookie") !== -1);
+				}
+				postbackForm.navigatorCookieEnabled.value = cookieEnabled;
+				postbackForm.navigatorJavaEnabled.value =  window.navigator.javaEnabled();
+				postbackForm.navigatorLanguage.value = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
+				postbackForm.navigatorPlatform.value = window.navigator.platform;
+				postbackForm.navigatorUserAgent.value = window.navigator.userAgent;
+				if (window.screen) {
+					postbackForm.screenWidth.value = window.screen.width;
+					postbackForm.screenHeight.value = window.screen.height;
+					postbackForm.screenColorDepth.value = window.screen.colorDepth;
+				}
+				postbackForm.utcOffset.value = (new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+				postbackForm.utcDSTOffset.value = (new Date(new Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+				postbackForm.browserWidth.value =  window.innerWidth || document.body.offsetWidth;
+				postbackForm.browserHeight.value =  window.innerHeight || document.body.offsetHeight;
+				postbackForm.hostname.value =  window.location.hostname;
+
+				return postbackForm;
+			},
+
+			/**
+			 * Populates and submits the special form.
+			 *
+			 * @param formMarkupId  The markup id of the special form
+			 */
+			submitForm: function(formMarkupId) {
+				var postbackForm = Wicket.BrowserInfo.populateFields(formMarkupId);
+				postbackForm.submit();
+			}
+		};
+	}
+
+})();

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
new file mode 100644
index 0000000..059abbc
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+<head>
+    <title>Wicket Examples - hellobrowser</title>
+    <link rel="stylesheet" type="text/css" href="style.css"/>
+</head>
+<body>
+    <div wicket:id="mainNavigation"></div>
+
+    <div wicket:id="form"></div>
+
+	<p>
+	    Hi there. We have been snooping around your browser, even doing a sneaky
+	    redirect to test some javascript properties in the process, and this is what we
+	    found out: <br /><br />
+	    ClientProperties: <span wicket:id="clientinfo">client info here</span>
+	</p>
+
+	<p>
+		<span wicket:id="clienttime">client time info here</span>
+	</p>
+
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
new file mode 100644
index 0000000..824caf0
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.examples.ajaxhellobrowser;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.core.request.ClientInfo;
+import org.apache.wicket.examples.WicketExamplePage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.basic.MultiLineLabel;
+import org.apache.wicket.markup.html.pages.AjaxBrowserInfoForm;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.protocol.http.ClientProperties;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.settings.IRequestCycleSettings;
+
+
+/**
+ * A demo usage of AjaxBrowserInfoForm
+ */
+public class AjaxHelloBrowser extends WicketExamplePage
+{
+	/**
+	 * Constructor.
+	 */
+	public AjaxHelloBrowser()
+	{
+		final MultiLineLabel clientInfo = new MultiLineLabel("clientinfo", new AbstractReadOnlyModel<String>()
+		{
+			@Override
+			public String getObject()
+			{
+				ClientProperties properties = getClientProperties();
+				return properties.toString();
+			}
+		});
+		clientInfo.setOutputMarkupPlaceholderTag(true);
+		clientInfo.setVisible(false);
+
+		IModel<String> clientTimeModel = new AbstractReadOnlyModel<String>()
+		{
+			@Override
+			public String getObject()
+			{
+				ClientProperties properties = getClientProperties();
+				TimeZone timeZone = properties.getTimeZone();
+				if (timeZone != null)
+				{
+					Calendar cal = Calendar.getInstance(timeZone);
+					Locale locale = getLocale();
+					DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, locale);
+					String calAsString = dateFormat.format(cal.getTime());
+					StringBuilder b = new StringBuilder("Based on your settings, your time is: ");
+					b.append(calAsString);
+					b.append(" (and your time zone is ");
+					b.append(timeZone.getDisplayName(getLocale()));
+					b.append(')');
+					return b.toString();
+				}
+				return "Unfortunately, we were not able to figure out what your time zone is, so we have"
+						+ " no idea what your time is";
+			}
+		};
+		final Label clientTime = new Label("clienttime", clientTimeModel);
+		clientTime.setOutputMarkupPlaceholderTag(true);
+		clientTime.setVisible(false);
+
+		AjaxBrowserInfoForm form = new AjaxBrowserInfoForm("form")
+		{
+			@Override
+			protected void onAfterSubmit(AjaxRequestTarget target, ClientInfo info)
+			{
+				super.onAfterSubmit(target, info);
+
+				clientInfo.setVisible(true);
+				clientTime.setVisible(true);
+				target.add(clientInfo, clientTime);
+			}
+		};
+
+		add(form, clientInfo, clientTime);
+	}
+
+	/**
+	 * A helper function that makes sure that gathering of extended browser info
+	 * is not enabled when reading the ClientInfo's properties
+	 *
+	 * @return the currently available client info
+	 */
+	private ClientProperties getClientProperties()
+	{
+		IRequestCycleSettings requestCycleSettings = getApplication().getRequestCycleSettings();
+		boolean gatherExtendedBrowserInfo = requestCycleSettings.getGatherExtendedBrowserInfo();
+		ClientProperties properties = null;
+		try
+		{
+			requestCycleSettings.setGatherExtendedBrowserInfo(false);
+			WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo();
+			properties = clientInfo.getProperties();
+		}
+		finally
+		{
+			requestCycleSettings.setGatherExtendedBrowserInfo(gatherExtendedBrowserInfo);
+		}
+		return properties;
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java
new file mode 100644
index 0000000..982b892
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.examples.ajaxhellobrowser;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.examples.WicketExampleApplication;
+
+/**
+ * Application class for Ajax based browser info extractor.
+ */
+public class HelloBrowserApplication extends WicketExampleApplication
+{
+	@Override
+	public Class<? extends Page> getHomePage()
+	{
+		return AjaxHelloBrowser.class;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
index 5cab415..12532c9 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
@@ -43,13 +43,8 @@ public class HelloBrowser extends WicketExamplePage
 	 */
 	public HelloBrowser()
 	{
-		// add a label that outputs a the client info object; it will result in
-		// the calls RequestCycle.getClientInfo -> Session.getClientInfo ->
-		// RequestCycle.newClientInfo. this is done once by default and
-		// afterwards cached in the session object. This application uses
-		// a custom requestcycle that overrides newClientInfo to not only
-		// look at the user-agent request header, but also snoops javascript
-		// properties by redirecting to a special page.
+		// Add a label that outputs the client info object; it will result in
+		// the calls Session.getClientInfo.
 
 		// don't use a property model here or anything else that is resolved
 		// during rendering, as changing the request target during rendering
@@ -73,17 +68,17 @@ public class HelloBrowser extends WicketExamplePage
 					Locale locale = getLocale();
 					DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, locale);
 					String calAsString = dateFormat.format(cal.getTime());
-				 StringBuilder b = new StringBuilder("Based on your settings, your time is: ");
+					StringBuilder b = new StringBuilder("Based on your settings, your time is: ");
 					b.append(calAsString);
 					b.append(" (and your time zone is ");
 					b.append(timeZone.getDisplayName(getLocale()));
-					b.append(")");
+					b.append(')');
 					return b.toString();
 				}
 				return "Unfortunately, we were not able to figure out what your time zone is, so we have"
-					+ "no idea what your time is";
+					+ " no idea what your time is";
 			}
 		};
 		add(new Label("clienttime", clientTimeModel));
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
index 66079cb..4e98f03 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
@@ -26,31 +26,19 @@ import org.apache.wicket.examples.WicketExampleApplication;
  */
 public class HelloBrowserApplication extends WicketExampleApplication
 {
-	/**
-	 * Constructor.
-	 */
-	public HelloBrowserApplication()
-	{
-	}
-
-	/**
-	 * @see org.apache.wicket.Application#getHomePage()
-	 */
 	@Override
 	public Class<? extends Page> getHomePage()
 	{
 		return HelloBrowser.class;
 	}
 
-	/**
-	 * @see org.apache.wicket.examples.WicketExampleApplication#init()
-	 */
 	@Override
 	protected void init()
 	{
 		super.init();
 
 		getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
+
 		mountPage("howdy", HelloBrowser.class);
 	}
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html b/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
index e8d396d..e6c5daf 100644
--- a/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
+++ b/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
@@ -41,7 +41,8 @@
         <tr><td align="right"><a href="template">template</a></td><td> - Templating example.</td></tr>
         <tr><td align="right"><a href="mailtemplate">mail template</a></td><td> - Generate mail templates out of Page, Panel or TextTemplate.</td></tr>
 		<tr><td align="right"><a href="stateless">stateless</a></td><td> - Demonstrates stateless pages/sessions.</td></tr>
-        <tr><td align="right"><a href="hellobrowser">hellobrowser</a></td><td> - Browser snooper.</td></tr>
+        <tr><td align="right"><a href="hellobrowser">Browser Info</a></td><td> - Extracts client info by redirecting to a temporary page.</td></tr>
+        <tr><td align="right"><a href="ajaxhellobrowser">Ajax Browser Info</a></td><td> - Extracts client info by using Ajax.</td></tr>
         <tr><td align="right"><a href="frames">frames</a></td><td> - Example demonstrating HTML frames.</td></tr>
         <tr><td align="right"><a href="prototype">ajax with prototype</a></td><td> - AJAX example using prototype.js.</td></tr>
         <tr><td align="right"><a href="wizard">abacadabra</a></td><td> - Demonstrates the wizard component.</td></tr>

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/WEB-INF/web.xml b/wicket-examples/src/main/webapp/WEB-INF/web.xml
index 38799f0..db9c840 100644
--- a/wicket-examples/src/main/webapp/WEB-INF/web.xml
+++ b/wicket-examples/src/main/webapp/WEB-INF/web.xml
@@ -117,6 +117,15 @@
 	</filter>
 
 	<filter>
+		<filter-name>AjaxHelloBrowserApplication</filter-name>
+		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+		<init-param>
+			<param-name>applicationClassName</param-name>
+			<param-value>org.apache.wicket.examples.ajaxhellobrowser.HelloBrowserApplication</param-value>
+		</init-param>
+	</filter>
+
+	<filter>
 		<filter-name>StockQuoteApplication</filter-name>
 		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
 		<init-param>
@@ -572,6 +581,13 @@
 	</filter-mapping>
 
 	<filter-mapping>
+		<filter-name>AjaxHelloBrowserApplication</filter-name>
+		<url-pattern>/ajaxhellobrowser/*</url-pattern>
+		<dispatcher>REQUEST</dispatcher>
+		<dispatcher>INCLUDE</dispatcher>
+	</filter-mapping>
+
+	<filter-mapping>
 		<filter-name>FormInputApplication</filter-name>
 		<url-pattern>/forminput/*</url-pattern>
 		<dispatcher>REQUEST</dispatcher>


[2/5] git commit: Add licence

Posted by mg...@apache.org.
Add licence


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7fcbfe7b
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7fcbfe7b
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7fcbfe7b

Branch: refs/heads/wicket-6.x
Commit: 7fcbfe7bc4172c8671ab037c73780c1006d1704d
Parents: 90235c1
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Dec 12 15:55:15 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Dec 12 15:55:15 2013 +0200

----------------------------------------------------------------------
 .../markup/html/pages/AjaxBrowserInfoForm.java      | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/7fcbfe7b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
index 86b2bb1..00cdcca 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.wicket.markup.html.pages;
 
 import org.apache.wicket.ajax.AjaxRequestTarget;


[4/5] git commit: WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added

Posted by mg...@apache.org.
WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added

Introduce AjaxClientInfoBehavior that collects the client info.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c84f0c25
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c84f0c25
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c84f0c25

Branch: refs/heads/wicket-6.x
Commit: c84f0c25bf86731e5abdaa1899def55f2545ee90
Parents: a2c21b1
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Sat Dec 14 10:09:30 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Sat Dec 14 10:09:30 2013 +0200

----------------------------------------------------------------------
 .../wicket/ajax/AjaxClientInfoBehavior.java     | 134 +++++++++++++++++++
 .../markup/html/pages/AjaxBrowserInfoForm.java  |  91 -------------
 .../markup/html/pages/wicket-browser-info.js    |  57 +++++---
 .../wicket/protocol/http/ClientProperties.java  |  26 ++--
 .../ajaxhellobrowser/AjaxHelloBrowser.html      |   7 +-
 .../ajaxhellobrowser/AjaxHelloBrowser.java      |  13 +-
 6 files changed, 191 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c84f0c25/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java
new file mode 100644
index 0000000..c106d72
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxClientInfoBehavior.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.ClientProperties;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.util.time.Duration;
+
+/**
+ * An behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax
+ */
+public class AjaxClientInfoBehavior extends AbstractAjaxTimerBehavior
+{
+	/**
+	 * Constructor.
+	 *
+	 * Auto fires after 50 millis.
+	 */
+	public AjaxClientInfoBehavior()
+	{
+		this(Duration.milliseconds(50));
+	}
+
+	/**
+	 * Constructor.
+	 *
+	 * Auto fires after {@code duration}.
+	 */
+	public AjaxClientInfoBehavior(Duration duration)
+	{
+		super(duration);
+	}
+
+	@Override
+	protected final void onTimer(AjaxRequestTarget target)
+	{
+		stop(target);
+
+		RequestCycle requestCycle = RequestCycle.get();
+		IRequestParameters requestParameters = requestCycle.getRequest().getRequestParameters();
+		String navigatorAppName = requestParameters.getParameterValue("navigatorAppName").toString("N/A");
+		String navigatorAppVersion = requestParameters.getParameterValue("navigatorAppVersion").toString("N/A");
+		String navigatorAppCodeName = requestParameters.getParameterValue("navigatorAppCodeName").toString("N/A");
+		boolean navigatorCookieEnabled = requestParameters.getParameterValue("navigatorCookieEnabled").toBoolean(false);
+		Boolean navigatorJavaEnabled = requestParameters.getParameterValue("navigatorJavaEnabled").toBoolean(false);
+		String navigatorLanguage = requestParameters.getParameterValue("navigatorLanguage").toString("N/A");
+		String navigatorPlatform = requestParameters.getParameterValue("navigatorPlatform").toString("N/A");
+		String navigatorUserAgent = requestParameters.getParameterValue("navigatorUserAgent").toString("N/A");
+		int screenWidth = requestParameters.getParameterValue("screenWidth").toInt(-1);
+		int screenHeight = requestParameters.getParameterValue("screenHeight").toInt(-1);
+		int screenColorDepth = requestParameters.getParameterValue("screenColorDepth").toInt(-1);
+		String utcOffset = requestParameters.getParameterValue("utcOffset").toString("N/A");
+		String utcDSTOffset = requestParameters.getParameterValue("utcDSTOffset").toString("N/A");
+		int browserWidth = requestParameters.getParameterValue("browserWidth").toInt(-1);
+		int browserHeight = requestParameters.getParameterValue("browserHeight").toInt(-1);
+		String hostname = requestParameters.getParameterValue("hostname").toString("N/A");
+
+		WebClientInfo clientInfo = new WebClientInfo(requestCycle);
+		Session.get().setClientInfo(clientInfo);
+
+		ClientProperties properties = clientInfo.getProperties();
+		properties.setNavigatorAppCodeName(navigatorAppCodeName);
+		properties.setNavigatorAppName(navigatorAppName);
+		properties.setNavigatorAppVersion(navigatorAppVersion);
+		properties.setCookiesEnabled(navigatorCookieEnabled);
+		properties.setJavaEnabled(navigatorJavaEnabled);
+		properties.setNavigatorLanguage(navigatorLanguage);
+		properties.setNavigatorPlatform(navigatorPlatform);
+		properties.setNavigatorUserAgent(navigatorUserAgent);
+		properties.setScreenWidth(screenWidth);
+		properties.setScreenHeight(screenHeight);
+		properties.setScreenColorDepth(screenColorDepth);
+		properties.setUtcOffset(utcOffset);
+		properties.setUtcDSTOffset(utcDSTOffset);
+		properties.setBrowserWidth(browserWidth);
+		properties.setBrowserHeight(browserHeight);
+		properties.setHostname(hostname);
+
+		onClientInfo(target, clientInfo);
+	}
+
+	/**
+	 * A callback method invoked when the client info is collected.
+	 * 
+	 * @param target
+	 *          The Ajax request handler
+	 * @param clientInfo
+	 *          The collected info for the client 
+	 */
+	protected void onClientInfo(AjaxRequestTarget target, WebClientInfo clientInfo)
+	{
+	}
+
+	@Override
+	protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+	{
+		super.updateAjaxAttributes(attributes);
+
+		attributes.getDynamicExtraParameters().add("return Wicket.BrowserInfo.collect()");
+	}
+
+	@Override
+	public void renderHead(Component component, IHeaderResponse response)
+	{
+		super.renderHead(component, response);
+
+		response.render(JavaScriptHeaderItem.forReference(
+				new JavaScriptResourceReference(BrowserInfoForm.class, "wicket-browser-info.js")));
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/c84f0c25/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
deleted file mode 100644
index 1ac842c..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.markup.html.pages;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxCallListener;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
-import org.apache.wicket.core.request.ClientInfo;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.protocol.http.request.WebClientInfo;
-
-/**
- * An extension of BrowserInfoForm that uses AjaxFormSubmitBehavior
- * to collect the client info without redirect to another page
- */
-public class AjaxBrowserInfoForm extends BrowserInfoForm
-{
-	/**
-	 * Constructor.
-	 *
-	 * @param id component id
-	 */
-	public AjaxBrowserInfoForm(String id)
-	{
-		super(id);
-	}
-
-	@Override
-	protected Form<? extends ClientPropertiesBean> createForm(String componentId)
-	{
-		Form<? extends ClientPropertiesBean> f = super.createForm(componentId);
-		f.add(new AjaxFormSubmitBehavior(f, "domready")
-		{
-			@Override
-			protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
-			{
-				super.updateAjaxAttributes(attributes);
-				AjaxCallListener listener = new AjaxCallListener();
-				listener.onBefore(String.format("Wicket.BrowserInfo.populateFields('%s');", getFormMarkupId()));
-				attributes.getAjaxCallListeners().add(listener);
-			}
-
-			@Override
-			protected void onAfterSubmit(AjaxRequestTarget target)
-			{
-				super.onAfterSubmit(target);
-				WebClientInfo info = getWebSession().getClientInfo();
-				AjaxBrowserInfoForm.this.onAfterSubmit(target, info);
-			}
-		});
-		return f;
-	}
-
-	/**
-	 * A callback method called when the client info is collected
-	 *
-	 * @param target
-	 *      The Ajax request handler
-	 * @param info
-	 *      The client info
-	 */
-	protected void onAfterSubmit(AjaxRequestTarget target, WebClientInfo info)
-	{
-	}
-
-	/**
-	 * Does nothing.
-	 *
-	 * Use {@linkplain #onAfterSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.protocol.http.request.WebClientInfo)}
-	 */
-	@Override
-	protected final void afterSubmit()
-	{
-		super.afterSubmit();
-	}
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/c84f0c25/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
index 6fb1fa3..528ff44 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
@@ -34,36 +34,51 @@
 		window.Wicket.BrowserInfo = {
 
 			/**
-			 * Populates the form elements with the client info
+			 * Collects the client information
 			 *
-			 * @param formMarkupId   The markup id of the special form
-			 * @returns {HTMLFormElement} The special form
+			 * @returns {Object}
 			 */
-			populateFields: function(formMarkupId) {
-				var postbackForm = document.getElementById(formMarkupId);
-				postbackForm.navigatorAppName.value = window.navigator.appName;
-				postbackForm.navigatorAppVersion.value = window.navigator.appVersion;
-				postbackForm.navigatorAppCodeName.value = window.navigator.appCodeName;
+			collect: function() {
+				var info = {};
+				info.navigatorAppName = window.navigator.appName;
+				info.navigatorAppVersion = window.navigator.appVersion;
+				info.navigatorAppCodeName = window.navigator.appCodeName;
 				var cookieEnabled = (window.navigator.cookieEnabled);
 				if (typeof(window.navigator.cookieEnabled) === "undefined" && !cookieEnabled) {
 					document.cookie = "wickettestcookie";
 					cookieEnabled = (document.cookie.indexOf("wickettestcookie") !== -1);
 				}
-				postbackForm.navigatorCookieEnabled.value = cookieEnabled;
-				postbackForm.navigatorJavaEnabled.value =  window.navigator.javaEnabled();
-				postbackForm.navigatorLanguage.value = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
-				postbackForm.navigatorPlatform.value = window.navigator.platform;
-				postbackForm.navigatorUserAgent.value = window.navigator.userAgent;
+				info.navigatorCookieEnabled = cookieEnabled;
+				info.navigatorJavaEnabled =  window.navigator.javaEnabled();
+				info.navigatorLanguage = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
+				info.navigatorPlatform = window.navigator.platform;
+				info.navigatorUserAgent = window.navigator.userAgent;
 				if (window.screen) {
-					postbackForm.screenWidth.value = window.screen.width;
-					postbackForm.screenHeight.value = window.screen.height;
-					postbackForm.screenColorDepth.value = window.screen.colorDepth;
+					info.screenWidth = window.screen.width;
+					info.screenHeight = window.screen.height;
+					info.screenColorDepth = window.screen.colorDepth;
+				}
+				info.utcOffset = (new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+				info.utcDSTOffset = (new Date(new Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+				info.browserWidth =  window.innerWidth || document.body.offsetWidth;
+				info.browserHeight =  window.innerHeight || document.body.offsetHeight;
+				info.hostname =  window.location.hostname;
+				return info;
+			},
+
+			/**
+			 * Populates the form elements with the client info
+			 *
+			 * @param formMarkupId   The markup id of the special form
+			 * @returns {HTMLFormElement} The special form
+			 */
+			populateFields: function(formMarkupId) {
+				var postbackForm = document.getElementById(formMarkupId);
+				var info = Wicket.BrowserInfo.collect();
+				var i;
+				for (i in info) {
+					postbackForm[i].value = info[i];
 				}
-				postbackForm.utcOffset.value = (new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-				postbackForm.utcDSTOffset.value = (new Date(new Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-				postbackForm.browserWidth.value =  window.innerWidth || document.body.offsetWidth;
-				postbackForm.browserHeight.value =  window.innerHeight || document.body.offsetHeight;
-				postbackForm.hostname.value =  window.location.hostname;
 
 				return postbackForm;
 			},

http://git-wip-us.apache.org/repos/asf/wicket/blob/c84f0c25/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
index edf07be..dcd72a9 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
@@ -254,12 +254,12 @@ public class ClientProperties implements IClusterable
 					// offset which can be parsed by the TimeZone class.
 
 					AppendingStringBuffer sb = new AppendingStringBuffer("GMT");
-					sb.append(offsetHours > 0 ? "+" : "-");
+					sb.append(offsetHours > 0 ? '+' : '-');
 					sb.append(Math.abs(offsetHours));
-					sb.append(":");
+					sb.append(':');
 					if (offsetMins < 10)
 					{
-						sb.append("0");
+						sb.append('0');
 					}
 					sb.append(offsetMins);
 					timeZone = TimeZone.getTimeZone(sb.toString());
@@ -271,13 +271,13 @@ public class ClientProperties implements IClusterable
 					{
 						utc = utc.substring(1);
 					}
-					timeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? "+" : "-") + utc);
+					timeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? '+' : '-') + utc);
 				}
 
 				String dstOffset = getUtcDSTOffset();
 				if (timeZone != null && dstOffset != null)
 				{
-					TimeZone dstTimeZone = null;
+					TimeZone dstTimeZone;
 					dotPos = dstOffset.indexOf('.');
 					if (dotPos >= 0)
 					{
@@ -296,12 +296,12 @@ public class ClientProperties implements IClusterable
 						// offset which can be parsed by the TimeZone class.
 
 						AppendingStringBuffer sb = new AppendingStringBuffer("GMT");
-						sb.append(offsetHours > 0 ? "+" : "-");
+						sb.append(offsetHours > 0 ? '+' : '-');
 						sb.append(Math.abs(offsetHours));
-						sb.append(":");
+						sb.append(':');
 						if (offsetMins < 10)
 						{
-							sb.append("0");
+							sb.append('0');
 						}
 						sb.append(offsetMins);
 						dstTimeZone = TimeZone.getTimeZone(sb.toString());
@@ -313,7 +313,7 @@ public class ClientProperties implements IClusterable
 						{
 							dstOffset = dstOffset.substring(1);
 						}
-						dstTimeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? "+" : "-") +
+						dstTimeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? '+' : '-') +
 							dstOffset);
 					}
 					// if the dstTimezone (1 July) has a different offset then
@@ -1096,7 +1096,7 @@ public class ClientProperties implements IClusterable
 	@Override
 	public String toString()
 	{
-	 StringBuilder b = new StringBuilder();
+		StringBuilder b = new StringBuilder();
 
 		Field[] fields = ClientProperties.class.getDeclaredFields();
 
@@ -1110,7 +1110,7 @@ public class ClientProperties implements IClusterable
 
 				field.setAccessible(true);
 
-				Object value = null;
+				Object value;
 				try
 				{
 					value = field.get(this);
@@ -1135,9 +1135,9 @@ public class ClientProperties implements IClusterable
 				if (value != null)
 				{
 					b.append(field.getName());
-					b.append("=");
+					b.append('=');
 					b.append(value);
-					b.append("\n");
+					b.append('\n');
 				}
 			}
 		}

http://git-wip-us.apache.org/repos/asf/wicket/blob/c84f0c25/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
index 059abbc..48e9a0e 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
@@ -7,12 +7,9 @@
 <body>
     <div wicket:id="mainNavigation"></div>
 
-    <div wicket:id="form"></div>
-
 	<p>
-	    Hi there. We have been snooping around your browser, even doing a sneaky
-	    redirect to test some javascript properties in the process, and this is what we
-	    found out: <br /><br />
+	    This page uses <em>org.apache.wicket.ajax.AjaxClientInfoBehavior</em>
+        to collect the following information: <br /><br />
 	    ClientProperties: <span wicket:id="clientinfo">client info here</span>
 	</p>
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/c84f0c25/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
index 9e6c8e0..024ec01 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
@@ -21,12 +21,11 @@ import java.util.Calendar;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import org.apache.wicket.ajax.AjaxClientInfoBehavior;
 import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.core.request.ClientInfo;
 import org.apache.wicket.examples.WicketExamplePage;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.basic.MultiLineLabel;
-import org.apache.wicket.markup.html.pages.AjaxBrowserInfoForm;
 import org.apache.wicket.model.AbstractReadOnlyModel;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.protocol.http.ClientProperties;
@@ -84,20 +83,20 @@ public class AjaxHelloBrowser extends WicketExamplePage
 		clientTime.setOutputMarkupPlaceholderTag(true);
 		clientTime.setVisible(false);
 
-		AjaxBrowserInfoForm form = new AjaxBrowserInfoForm("form")
+		add(new AjaxClientInfoBehavior()
 		{
 			@Override
-			protected void onAfterSubmit(AjaxRequestTarget target, WebClientInfo info)
+			protected void onClientInfo(AjaxRequestTarget target, WebClientInfo info)
 			{
-				super.onAfterSubmit(target, info);
+				super.onClientInfo(target, info);
 
 				clientInfo.setVisible(true);
 				clientTime.setVisible(true);
 				target.add(clientInfo, clientTime);
 			}
-		};
+		});
 
-		add(form, clientInfo, clientTime);
+		add(clientInfo, clientTime);
 	}
 
 	/**


[3/5] git commit: WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added

Posted by mg...@apache.org.
WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added

Since it uses Ajax it should be *Web*ClientInfo


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/a2c21b13
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/a2c21b13
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/a2c21b13

Branch: refs/heads/wicket-6.x
Commit: a2c21b134d0c855a1c1c7cd3d83ff1ad93c068d6
Parents: 7fcbfe7
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Dec 12 16:06:59 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Dec 12 16:06:59 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java  | 7 ++++---
 .../wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java    | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/a2c21b13/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
index 00cdcca..1ac842c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
@@ -22,6 +22,7 @@ import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
 import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
 import org.apache.wicket.core.request.ClientInfo;
 import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
 
 /**
  * An extension of BrowserInfoForm that uses AjaxFormSubmitBehavior
@@ -58,7 +59,7 @@ public class AjaxBrowserInfoForm extends BrowserInfoForm
 			protected void onAfterSubmit(AjaxRequestTarget target)
 			{
 				super.onAfterSubmit(target);
-				ClientInfo info = getSession().getClientInfo();
+				WebClientInfo info = getWebSession().getClientInfo();
 				AjaxBrowserInfoForm.this.onAfterSubmit(target, info);
 			}
 		});
@@ -73,14 +74,14 @@ public class AjaxBrowserInfoForm extends BrowserInfoForm
 	 * @param info
 	 *      The client info
 	 */
-	protected void onAfterSubmit(AjaxRequestTarget target, ClientInfo info)
+	protected void onAfterSubmit(AjaxRequestTarget target, WebClientInfo info)
 	{
 	}
 
 	/**
 	 * Does nothing.
 	 *
-	 * Use {@linkplain #onAfterSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.core.request.ClientInfo)}
+	 * Use {@linkplain #onAfterSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.protocol.http.request.WebClientInfo)}
 	 */
 	@Override
 	protected final void afterSubmit()

http://git-wip-us.apache.org/repos/asf/wicket/blob/a2c21b13/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
index 824caf0..9e6c8e0 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
@@ -87,7 +87,7 @@ public class AjaxHelloBrowser extends WicketExamplePage
 		AjaxBrowserInfoForm form = new AjaxBrowserInfoForm("form")
 		{
 			@Override
-			protected void onAfterSubmit(AjaxRequestTarget target, ClientInfo info)
+			protected void onAfterSubmit(AjaxRequestTarget target, WebClientInfo info)
 			{
 				super.onAfterSubmit(target, info);
 


[5/5] git commit: Merge branch 'wicket-6.x' into 5435-ajax-browser-info

Posted by mg...@apache.org.
Merge branch 'wicket-6.x' into 5435-ajax-browser-info


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/dd5de0e5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/dd5de0e5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/dd5de0e5

Branch: refs/heads/wicket-6.x
Commit: dd5de0e554d6b0e33f8221b4c34c608c7b8e4046
Parents: c84f0c2 94c0c84
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Sat Dec 14 22:59:56 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Sat Dec 14 22:59:56 2013 +0200

----------------------------------------------------------------------
 pom.xml                                         |   2 +-
 .../wicket/page/PageAccessSynchronizerTest.java |  12 +-
 .../ajax/markup/html/modal/res/modal.js         |   6 +-
 .../html/captcha/CaptchaImageResource.java      | 190 ++++++++++++++-----
 .../html/captcha/CaptchaImageResourceTest.java  |  84 ++++++++
 .../java/org/apache/wicket/util/time/Time.java  |   2 +-
 .../apache/wicket/util/time/TimeOfDayTest.java  |   1 +
 .../org/apache/wicket/util/time/TimeTest.java   |  13 +-
 8 files changed, 253 insertions(+), 57 deletions(-)
----------------------------------------------------------------------