You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ta...@apache.org on 2015/07/28 14:17:43 UTC

deltaspike git commit: DELTASPIKE-962 Refactor windowhandler.html

Repository: deltaspike
Updated Branches:
  refs/heads/master 641028c02 -> 1cadbf066


DELTASPIKE-962 Refactor windowhandler.html

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

Branch: refs/heads/master
Commit: 1cadbf06678785c81b6e09d1c2b96c0679971be1
Parents: 641028c
Author: Thomas Andraschko <ta...@apache.org>
Authored: Tue Jul 28 14:17:28 2015 +0200
Committer: Thomas Andraschko <ta...@apache.org>
Committed: Tue Jul 28 14:17:28 2015 +0200

----------------------------------------------------------------------
 .../scope/window/DefaultClientWindowConfig.java |   3 +
 .../resources/deltaspike/windowhandler.js       |   8 +
 .../main/resources/static/windowhandler.html    | 257 ++++++++-----------
 3 files changed, 121 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1cadbf06/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
index 3005156..67549f9 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
@@ -31,6 +31,7 @@ import org.apache.deltaspike.core.util.ClassUtils;
 import org.apache.deltaspike.core.util.ExceptionUtils;
 import org.apache.deltaspike.jsf.api.config.JsfModuleConfig;
 import org.apache.deltaspike.jsf.api.config.base.JsfBaseConfig;
+import org.apache.deltaspike.jsf.util.ValueExpressionEvaluationInputStream;
 
 /**
  * <p>Default implementation of {@link ClientWindowConfig}.
@@ -150,6 +151,8 @@ public class DefaultClientWindowConfig implements ClientWindowConfig
         }
 
         InputStream is = ClassUtils.getClassLoader(null).getResourceAsStream(getClientWindowResourceLocation());
+        // wrap InputStream to evaluate EL expressions like resource includes
+        is = new ValueExpressionEvaluationInputStream(FacesContext.getCurrentInstance(), is);
         StringBuffer sb = new StringBuffer();
         try
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1cadbf06/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
index ecfe05d..839447d 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
+++ b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
@@ -290,6 +290,14 @@ window.dswh = window.dswh || {
             return someArray.join("|||");
         },
 
+        unstringify : function(serialized) {
+            if (JSON) {
+                return JSON.parse(serialized);
+            }
+
+            return serialized.split("|||");
+        },
+
         equalsIgnoreCase : function(source, destination) {
             //either both are not set or null
             if (!source && !destination) {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1cadbf06/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html b/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
index ec21e9e..5fdb300 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
+++ b/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
@@ -20,163 +20,126 @@
  under the License.
 -->
 <html>
-
-<head><title>Loading...</title></head>
-<body><div id="message" style="position:absolute;left:40%;top:40%">
-    Your browser does not support JavaScript.
-    Click <a href="$$noscriptUrl$$">here</a> to continue without JavaScript.
-</div></body>
-
-<script type="text/javascript" >
-function isHtml5() {
-    try { return !!localStorage.getItem;
-    } catch(e) { return false; }
-}
-function unstringify(serialized) {
-    if (JSON) { return JSON.parse(serialized); }
-    return serialized.split("|||");
-}
-function getOldBody() {
-    if (window.name.length != null) {
-        return localStorage.getItem(window.name + '_body');
-    }
-}
-function getOldBodyAttrs() {
-    if (window.name.length != null) {
-        return localStorage.getItem(window.name + '_bodyAttrs');
-    }
-}
-function getOldCss() {
-    if (window.name.length != null) {
-        return unstringify(localStorage.getItem(window.name + '_css'));
-    }
-}
-
-function addCss(url) {
-    var newSS = document.createElement("style");
-    newSS.setAttribute("rel", "stylesheet");
-    newSS.setAttribute("type", "text/css");
-    newSS.appendChild(document.createTextNode("@import url(" +url + ");"));
-    document.getElementsByTagName("head")[0].appendChild(newSS);
-}
-
-function loadCss(clean) {
-    if (!isHtml5()) { // only do this stuff on html browsers
-        return;
-    }
-    var oldCss  = getOldCss();
-    if (window.name && oldCss) {
-        for (i=0; oldCss && i< oldCss.length; i++) {
-            addCss(oldCss[i]);
+    <head>
+        <title>Loading...</title>
+        <script type="text/javascript" src="#{resource['deltaspike/windowhandler.js']}"></script>
+    </head>
+    <body>
+        <div id="message" style="position:absolute;left:40%;top:40%">
+            Your browser does not support JavaScript.
+            Click <a href="$$noscriptUrl$$">here</a> to continue without JavaScript.
+        </div>
+    </body>
+
+    <script type="text/javascript" >
+        function getOldBody() {
+            if (window.name.length !== null) {
+                return localStorage.getItem(window.name + '_body');
+            }
         }
-        if (clean) {
-            localStorage.removeItem(window.name + '_css');
+        function getOldBodyAttrs() {
+            if (window.name.length !== null) {
+                return localStorage.getItem(window.name + '_bodyAttrs');
+            }
         }
-    }
-}
-
-function replaceContent() {
-    if (!isHtml5()) { // only do this stuff on html browsers
-        document.getElementById('message').textContent = "Loading...";
-        return;
-    }
-    loadCss(false);
-
-    var oldBody = getOldBody();
-
-    if (window.name && oldBody) {
-        document.body.innerHTML = oldBody;
-
-        //X TODO should restore all attribs of the body tag
-        document.body.setAttribute("class", getOldBodyAttrs());
-        document.body.setAttribute("style", " cursor: wait !important;");
-
-        localStorage.removeItem(window.name + '_body');
-        localStorage.removeItem(window.name + '_bodyAttrs');
-
-        // overlay the doc with an un-clickable full-size div
-        var newDiv = document.createElement("div");
-        newDiv.setAttribute("style", "position:absolute; z-index:1000; background-color:transparent; top:0; left:0; width:100%; height: 100%");
-        newDiv.setAttribute("class", "fulldiv");
-        document.body.appendChild(newDiv);
-    } else {
-        document.getElementById('message').textContent = "Loading...";
-    }
-}
-
-function setUrlParam(baseUrl, paramName, paramValue) {
-    var query = baseUrl;
-    var vars = query.split(/&|\?/g);
-    var newQuery = "";
-    var iParam = 0;
-    var paramFound = false;
-    for (var i=0; vars != null && i < vars.length; i++) {
-        var pair = vars[i].split("=");
-        if (pair.length == 1) {
-            newQuery = pair[0];
-        } else {
-            if (pair[0] != paramName) {
-                var amp = iParam++ > 0 ? "&" : "?";
-                newQuery =  newQuery + amp + pair[0] + "=" + pair[1];
-            } else {
-                paramFound = true;
-                var amp = iParam++ > 0 ? "&" : "?";
-                newQuery =  newQuery + amp + paramName + "=" + paramValue;
+        function getOldCss() {
+            if (window.name.length !== null) {
+                return dswh.utils.unstringify(localStorage.getItem(window.name + '_css'));
             }
         }
-    }
-    if (!paramFound) {
-        var amp = iParam++ > 0 ? "&" : "?";
-        newQuery =  newQuery + amp + paramName + "=" + paramValue;
-    }
-    return newQuery;
-}
-
-replaceContent();
-
-window.onload = function() {
-    // uncomment the following line to debug the intermediate page
-    // if (!confirm('reload?')) { return true; }
-
-    loadCss(true);
-    // this will be replaced in the phase listener
-    var windowId = window.name;
-    var urlId = windowId;
-    if (!windowId || windowId.length < 1) {
-        var newWindowId = '$$windowIdValue$$';
-        if (newWindowId != 'uninitializedWindowId') {
-            window.name = newWindowId; // set the window.name with our windowId
-            windowId = newWindowId;
-            urlId = windowId;
+
+        function addCss(url) {
+            var newSS = document.createElement("style");
+            newSS.setAttribute("rel", "stylesheet");
+            newSS.setAttribute("type", "text/css");
+            newSS.appendChild(document.createTextNode("@import url(" +url + ");"));
+            document.getElementsByTagName("head")[0].appendChild(newSS);
         }
-        else {
-            windowId = 'automatedEntryPoint';
-            urlId = null;
+
+        function loadCss(clean) {
+            if (!dswh.utils.isHtml5()) { // only do this stuff on html5 browsers
+                return;
+            }
+            var oldCss  = getOldCss();
+            if (window.name && oldCss) {
+                for (i=0; oldCss && i< oldCss.length; i++) {
+                    addCss(oldCss[i]);
+                }
+                if (clean) {
+                    localStorage.removeItem(window.name + '_css');
+                }
+            }
         }
-    }
-    // occurs with the "duplicate tab" feature of chrome
-    else if (windowId === 'tempWindowId') {
-        window.name = '';
-        windowId = 'automatedEntryPoint';
-        urlId = null;
-    }
 
-    // 3 seconds expiry time
-    var expdt = new Date();
-    expdt.setTime(expdt.getTime()+(3*1000));
-    var expires = "; expires="+expdt.toGMTString();
+        function replaceContent() {
+            if (!dswh.utils.isHtml5()) { // only do this stuff on html browsers
+                document.getElementById('message').textContent = "Loading...";
+                return;
+            }
+            loadCss(false);
 
-    var requestToken = Math.floor(Math.random()*999);
-    var newUrl = setUrlParam(window.location.href, "dsrid", requestToken);
+            var oldBody = getOldBody();
 
-    // we still add hte windowId page param to support lazy windowId dropping for some clients
-    newUrl = setUrlParam(newUrl, "dswid", urlId);
+            if (window.name && oldBody) {
+                document.body.innerHTML = oldBody;
 
-    document.cookie = 'dsrwid-' + requestToken + '=' + windowId + expires+"; path=/";
+                //X TODO should restore all attributes of the body tag
+                document.body.setAttribute("class", getOldBodyAttrs());
+                document.body.setAttribute("style", " cursor: wait !important;");
 
-    window.location = newUrl;
-}
-</script>
+                localStorage.removeItem(window.name + '_body');
+                localStorage.removeItem(window.name + '_bodyAttrs');
 
-</html>
+                // overlay the doc with an un-clickable full-size div
+                var newDiv = document.createElement("div");
+                newDiv.setAttribute("style", "position:absolute; z-index:1000; background-color:transparent; top:0; left:0; width:100%; height: 100%");
+                newDiv.setAttribute("class", "fulldiv");
+                document.body.appendChild(newDiv);
+            } else {
+                document.getElementById('message').textContent = "Loading...";
+            }
+        }
+
+        replaceContent();
+
+        window.onload = function() {
+            // uncomment the following line to debug the intermediate page
+            // if (!confirm('reload?')) { return true; }
+
+            loadCss(true);
+
+            var windowId = window.name;
+            var urlId = windowId;
+            if (!windowId || windowId.length < 1) {
+                var newWindowId = '$$windowIdValue$$';
+                if (newWindowId !== 'uninitializedWindowId') {
+                    window.name = newWindowId; // set the window.name with our windowId
+                    windowId = newWindowId;
+                    urlId = windowId;
+                }
+                else {
+                    windowId = 'automatedEntryPoint';
+                    urlId = null;
+                }
+            }
+            // occurs with the "duplicate tab" feature of chrome
+            else if (windowId === 'tempWindowId') {
+                window.name = '';
+                windowId = 'automatedEntryPoint';
+                urlId = null;
+            }
 
+            var requestToken = dswh.utils.generateRequestToken();
+
+            var redirectUrl = window.location.href;
+            redirectUrl = dswh.utils.setUrlParam(redirectUrl, "dsrid", requestToken);
+            // we still add the windowId page param to support lazy windowId dropping for some clients
+            redirectUrl = dswh.utils.setUrlParam(redirectUrl, "dswid", urlId);
+
+            dswh.utils.storeCookie('dsrwid-' + requestToken, windowId, 3);
+
+            window.location = redirectUrl;
+        };
+    </script>
+
+</html>