Repository: wicket
Updated Branches:
  refs/heads/WICKET-6056-client-properties 954f27754 -> a7a46269d


WICKET-6056 show extended client properties usage


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

Branch: refs/heads/WICKET-6056-client-properties
Commit: a7a46269d58a932e30b04c331d0e7230e58ac198
Parents: 954f277
Author: Sven Meier <svenme...@apache.org>
Authored: Fri Nov 25 21:14:20 2016 +0100
Committer: Sven Meier <svenme...@apache.org>
Committed: Fri Nov 25 21:14:20 2016 +0100

----------------------------------------------------------------------
 .../markup/html/pages/wicket-browser-info.js    |  5 ++
 .../wicket/protocol/http/ClientProperties.java  | 29 +++++-----
 .../ajaxhellobrowser/AjaxHelloBrowser.java      | 36 +++++++++++--
 .../ajaxhellobrowser/ExtendedClientInfo.java    | 56 ++++++++++++++++++++
 4 files changed, 109 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/a7a46269/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 5832fa0..cd0da94 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
@@ -63,6 +63,11 @@
                                info.browserWidth =  window.innerWidth || 
document.body.offsetWidth;
                                info.browserHeight =  window.innerHeight || 
document.body.offsetHeight;
                                info.hostname =  window.location.hostname;
+
+                               if (Wicket.BrowserInfo.collectExtraInfo) {
+                                       
Wicket.BrowserInfo.collectExtraInfo(info);
+                               }
+
                                return info;
                        },
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/a7a46269/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 3d5b54a..109d175 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
@@ -17,6 +17,7 @@
 package org.apache.wicket.protocol.http;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.util.Collection;
 import java.util.TimeZone;
 
@@ -78,16 +79,15 @@ public class ClientProperties implements IClusterable
        private int screenColorDepth = -1;
        private int screenHeight = -1;
        private int screenWidth = -1;
-       /** Cached timezone for repeating calls to {@link #getTimeZone()} */
-       private TimeZone timeZone;
        private String utcDSTOffset;
-
        private String utcOffset;
-
        private String hostname;
 
        private boolean javaScriptEnabled;
 
+       /** Cached timezone for repeating calls to {@link #getTimeZone()} */
+       private transient TimeZone timeZone;
+
        /**
         * @return The browser height at the time it was measured
         */
@@ -731,15 +731,19 @@ public class ClientProperties implements IClusterable
        {
                StringBuilder b = new StringBuilder();
 
-               Field[] fields = ClientProperties.class.getDeclaredFields();
+               Class<?> clazz = getClass();
+               while (clazz != Object.class) {
+                       Field[] fields = clazz.getDeclaredFields();
 
-               for (Field field : fields)
-               {
-                       // Ignore these fields
-                       if (field.getName().equals("serialVersionUID") == false 
&&
-                               field.getName().startsWith("class$") == false &&
-                               field.getName().startsWith("timeZone") == false)
+                       for (Field field : fields)
                        {
+                               // Ignore these fields
+                               if (Modifier.isStatic(field.getModifiers()) ||
+                                       
Modifier.isTransient(field.getModifiers())  ||
+                                       field.isSynthetic())
+                               {
+                                       continue;
+                               }
 
                                field.setAccessible(true);
 
@@ -773,8 +777,9 @@ public class ClientProperties implements IClusterable
                                        b.append('\n');
                                }
                        }
-               }
 
+                       clazz = clazz.getSuperclass();
+               }
                return b.toString();
        }
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/a7a46269/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 f63f9cd..8dcc615 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,14 +21,18 @@ import java.util.Calendar;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import org.apache.wicket.Component;
 import org.apache.wicket.ajax.AjaxClientInfoBehavior;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.examples.WicketExamplePage;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.basic.MultiLineLabel;
 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.request.cycle.RequestCycle;
 import org.apache.wicket.settings.RequestCycleSettings;
 
 
@@ -78,11 +82,33 @@ public class AjaxHelloBrowser extends WicketExamplePage
                clientTime.setOutputMarkupPlaceholderTag(true);
                clientTime.setVisible(false);
 
-               add(AjaxClientInfoBehavior.onClientInfo((AjaxRequestTarget 
target, WebClientInfo info) -> {
-                       clientInfo.setVisible(true);
-                       clientTime.setVisible(true);
-                       target.add(clientInfo, clientTime);
-               }));
+               add(new AjaxClientInfoBehavior() {
+
+                       @Override
+                       public void renderHead(Component component, 
IHeaderResponse response)
+                       {
+                               super.renderHead(component, response);
+
+                               String script = 
"Wicket.BrowserInfo.collectExtraInfo = function(info) { info.foo = 'FOO'; };";
+
+                               
response.render(JavaScriptHeaderItem.forScript(script, "extended-client-info"));
+                       }
+
+                       @Override
+                       protected WebClientInfo newWebClientInfo(RequestCycle 
requestCycle)
+                       {
+                               return new ExtendedClientInfo(requestCycle);
+                       }
+
+                       @Override
+                       protected void onClientInfo(AjaxRequestTarget target, 
WebClientInfo webClientInfo)
+                       {
+                               clientInfo.setVisible(true);
+                               clientTime.setVisible(true);
+
+                               target.add(clientInfo, clientTime);
+                       }
+               });
 
                add(clientInfo, clientTime);
        }

http://git-wip-us.apache.org/repos/asf/wicket/blob/a7a46269/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/ExtendedClientInfo.java
----------------------------------------------------------------------
diff --git 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/ExtendedClientInfo.java
 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/ExtendedClientInfo.java
new file mode 100644
index 0000000..d772cdb
--- /dev/null
+++ 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/ExtendedClientInfo.java
@@ -0,0 +1,56 @@
+/*
+ * 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.protocol.http.ClientProperties;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+
+
+public class ExtendedClientInfo extends WebClientInfo
+{
+
+       public ExtendedClientInfo(RequestCycle requestCycle)
+       {
+               super(requestCycle);
+       }
+
+       @Override
+       protected ClientProperties newClientProperties()
+       {
+               return new ExtendedClientProperties();
+       }
+
+       public class ExtendedClientProperties extends ClientProperties
+       {
+               private String foo;
+               
+               public String getFoo()
+               {
+                       return foo;
+               }
+               
+               @Override
+               public void read(IRequestParameters parameters)
+               {
+                       super.read(parameters);
+                       
+                       foo = 
parameters.getParameterValue("foo").toString("N/A");
+               }
+       }
+}

Reply via email to