You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/09/08 21:55:47 UTC

svn commit: r995232 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/_Lang.js xhrCore/_AjaxResponse.js

Author: werpu
Date: Wed Sep  8 19:55:47 2010
New Revision: 995232

URL: http://svn.apache.org/viewvc?rev=995232&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2876

blackberry support now more or less done for blackberry 5,  4.7.1 needs testing though

Modified:
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js?rev=995232&r1=995231&r2=995232&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js Wed Sep  8 19:55:47 2010
@@ -44,7 +44,7 @@ myfaces._impl.core._Runtime.singletonDel
 
     clearExceptionProcessed: function() {
         //ie again
-        for(var key in this._processedExceptions) {
+        for (var key in this._processedExceptions) {
             this._processedExceptions[key] = null;
         }
         this._processedExceptions = {};
@@ -81,16 +81,16 @@ myfaces._impl.core._Runtime.singletonDel
     getEventTarget: function(evt) {
         //ie6 and 7 fallback
         evt = (!evt) ? window.event || {} : evt;
-       /**
-        * evt source is defined in the jsf events
-        * seems like some component authors use our code
-        * so we add it here see also
-        * https://issues.apache.org/jira/browse/MYFACES-2458
-        * not entirely a bug but makes sense to add this
-        * behavior. I dont use it that way but nevertheless it
-        * does not break anything so why not
-        * */
-        var t = evt.srcElement || evt.target  || evt.source || null;
+        /**
+         * evt source is defined in the jsf events
+         * seems like some component authors use our code
+         * so we add it here see also
+         * https://issues.apache.org/jira/browse/MYFACES-2458
+         * not entirely a bug but makes sense to add this
+         * behavior. I dont use it that way but nevertheless it
+         * does not break anything so why not
+         * */
+        var t = evt.srcElement || evt.target || evt.source || null;
         while ((t) && (t.nodeType != 1)) {
             t = t.parentNode;
         }
@@ -104,7 +104,7 @@ myfaces._impl.core._Runtime.singletonDel
     consumeEvent: function(event) {
         //w3c model vs ie model again
         event = event || window.event;
-        (event.stopPropagation)? event.stopPropagation(): event.cancelBubble = true;
+        (event.stopPropagation) ? event.stopPropagation() : event.cancelBubble = true;
     },
 
     /**
@@ -636,18 +636,23 @@ myfaces._impl.core._Runtime.singletonDel
 
 
     parseXML: function(txt) {
-        var parser = null, xmlDoc = null;
-        if (window.DOMParser) {
-            parser = new DOMParser();
-            xmlDoc = parser.parseFromString(txt, "text/xml");
-        }
-        else // Internet Explorer
-        {
-            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
-            xmlDoc.async = "false";
-            xmlDoc.loadXML(txt);
+        try {
+            var parser = null, xmlDoc = null;
+            if (window.DOMParser) {
+                parser = new DOMParser();
+                xmlDoc = parser.parseFromString(txt, "text/xml");
+            }
+            else // Internet Explorer
+            {
+                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
+                xmlDoc.async = "false";
+                xmlDoc.loadXML(txt);
+            }
+            return xmlDoc;
+        } catch (e) {
+            //undefined internal parser error
+            return null;
         }
-        return xmlDoc;
     }
     ,
 
@@ -668,6 +673,10 @@ myfaces._impl.core._Runtime.singletonDel
     }
     ,
     isXMLParseError: function(xmlContent) {
+
+        //no xml content
+        if (xmlContent == null) return true;
+
         var findParseError = function(node) {
             if (!node || !node.childNodes) return false;
             for (var cnt = 0; cnt < node.childNodes.length; cnt++) {
@@ -678,7 +687,8 @@ myfaces._impl.core._Runtime.singletonDel
         };
         return !xmlContent ||
                 (this.exists(xmlContent, "parseError.errorCode") && xmlContent.parseError.errorCode != 0) ||
-                findParseError(xmlContent)
+                findParseError(xmlContent);
+
 
     }
     ,

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=995232&r1=995231&r2=995232&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Wed Sep  8 19:55:47 2010
@@ -331,9 +331,13 @@ myfaces._impl.core._Runtime.extendClass(
 
             switch (node.getAttribute('id')) {
                 case this.P_VIEWROOT:
+
+
                     cDataBlock = cDataBlock.substring(cDataBlock.indexOf("<html"));
+
                     var parsedData = this._replaceHead(request, context, cDataBlock);
-                    var resultNode = (parsedData) ? this._replaceBody(request, context, cDataBlock, parsedData) : this._replaceBody(request, context, cDataBlock);
+
+                    var resultNode = ('undefined' != typeof parsedData &&  null != parsedData) ? this._replaceBody(request, context, cDataBlock, parsedData) : this._replaceBody(request, context, cDataBlock);
                     if (resultNode) {
                         this._pushOperationResult(resultNode);
                     }
@@ -396,32 +400,39 @@ myfaces._impl.core._Runtime.extendClass(
      * @return an xml representation of the page for further processing if possible
      */
     _replaceHead: function(request, context, newData) {
+
         var _Impl = this._Impl;
+
         var doc = this._Lang.parseXML(newData);
+
         var newHead = null;
         if (this._Lang.isXMLParseError(doc)) {
-            doc = this._Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]\/\/-->/g, "//-->"));
+            doc = this._Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]*\/\/-->/g, "//-->"));
         }
 
         if (this._Lang.isXMLParseError(doc)) {
             //the standard xml parser failed we retry with the stripper
             var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
             var headData = parser.parse(newData, "head");
-            newHead = this._Lang.parseXML("<root>" + headData + "</root>");
+
+            newHead = this._Lang.parseXML("<head>" + headData + "</head>");
+            //last and slowest option create a new head element and let the browser
+            //do its slow job
             if (this._Lang.isXMLParseError(newHead)) {
-                //we give up no further fallbacks
-                _Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML, "Error in PPR Insert, before id or after id must be present");
-                return null;
+                try {
+                    newHead = document.createElement("head");
+                    newHead.innerHTML = headData;
+                } catch (e) {
+                    //we give up no further fallbacks
+                    _Impl.sendError(request, context, _Impl.MALFORMEDXML, _Impl.MALFORMEDXML, "Error head replacement failed reason:"+e.toString());
+                    return null;
+                }
             }
         } else {
             //parser worked we go on
             newHead = doc.getElementsByTagName("head")[0];
         }
 
-        //since we are xml enabled here we probably can walk over it via xml <head> ... </head> normally is valid xml
-        //the ie tricks with form etc... do not work out, so we have to rely on internal xml parsing
-        //prestripping the body should reduce the failure rate of this method
-        ///var xmlData = this._Lang.parseXML("<root>"+headData+"</root>");
         this._Dom.runScripts(newHead, true);
 
         return doc;
@@ -450,32 +461,25 @@ myfaces._impl.core._Runtime.extendClass(
 
         var bodyParent = oldBody.parentNode;
 
-
-        if (!this._RT.browser.isIEMobile || this._RT.browser.isIEMobile >= 7) {
-            //if possible we replace the entire body to get all the old attributes cleaned up
-            //which works on all new browsers
-            var newBody = document.createElement("body");
-            bodyParent.replaceChild(newBody, oldBody);
-        } else {
-            //now to the problematic engines
-            oldBody.innerHTML = "";
-            //we just clean up the old body
-            var newBody = oldBody;
-        }
+        this._Dom._removeChildNodes(oldBody);
+        var newBody = oldBody;
 
         newBody.appendChild(placeHolder);
 
         var bodyData = null;
 
         var doc = (arguments.length > 3) ? arguments[3] : this._Lang.parseXML(newData);
+
         if (this._Lang.isXMLParseError(doc)) {
-            doc = this._Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]\/\/-->/g, "//-->"));
+            doc = this._Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]*\/\/-->/g, "//-->"));
         }
 
         if (this._Lang.isXMLParseError(doc)) {
             //the standard xml parser failed we retry with the stripper
 
             var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))();
+
+
             bodyData = parser.parse(newData, "body");
         } else {
             //parser worked we go on
@@ -492,7 +496,9 @@ myfaces._impl.core._Runtime.extendClass(
             }
         }
 
+       
         var returnedElement = this.replaceHtmlItem(request, context, placeHolder, bodyData);
+
         if (returnedElement) {
             this._pushOperationResult(returnedElement);
         }