1 /* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to you under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @class 19 * @name _AjaxResponse 20 * @memberOf myfaces._impl.xhrCore 21 * @extends myfaces._impl.core.Object 22 * @description 23 * This singleton is responsible for handling the standardized xml ajax response 24 * Note: since the semantic processing can be handled about 90% in a functional 25 * style we make this class stateless. Every state information is stored 26 * temporarily in the context. 27 * 28 * The singleton approach also improves performance 29 * due to less object gc compared to the old instance approach. 30 * 31 */ 32 _MF_SINGLTN(_PFX_XHR + "_AjaxResponse", _MF_OBJECT, /** @lends myfaces._impl.xhrCore._AjaxResponse.prototype */ { 33 34 /*partial response types*/ 35 RESP_PARTIAL : "partial-response", 36 RESP_TYPE_ERROR : "error", 37 RESP_TYPE_REDIRECT : "redirect", 38 RESP_TYPE_CHANGES : "changes", 39 40 /*partial commands*/ 41 CMD_CHANGES : "changes", 42 CMD_UPDATE : "update", 43 CMD_DELETE : "delete", 44 CMD_INSERT : "insert", 45 CMD_EVAL : "eval", 46 CMD_ERROR : "error", 47 CMD_ATTRIBUTES : "attributes", 48 CMD_EXTENSION : "extension", 49 CMD_REDIRECT : "redirect", 50 51 /*other constants*/ 52 P_VIEWSTATE: "javax.faces.ViewState", 53 P_VIEWROOT: "javax.faces.ViewRoot", 54 P_VIEWHEAD: "javax.faces.ViewHead", 55 P_VIEWBODY: "javax.faces.ViewBody", 56 57 58 /** 59 * uses response to start Html element replacement 60 * 61 * @param {Object} request (xhrRequest) - xhr request object 62 * @param {Object} context (Map) - AJAX context 63 * 64 * A special handling has to be added to the update cycle 65 * according to the JSDoc specs if the CDATA block contains html tags the outer rim must be stripped 66 * if the CDATA block contains a head section the document head must be replaced 67 * and if the CDATA block contains a body section the document body must be replaced! 68 * 69 */ 70 processResponse : function(request, context) { 71 //mfinternal handling, note, the mfinternal is only optional 72 //according to the spec 73 context._mfInternal = context._mfInternal || {}; 74 var mfInternal = context._mfInternal; 75 76 //the temporary data is hosted here 77 mfInternal._updateElems = []; 78 mfInternal._updateForms = []; 79 mfInternal.appliedViewState = null; 80 81 try { 82 var _Impl = this.attr("impl"), _Lang = this._Lang; 83 // TODO: 84 // Solution from 85 // http://www.codingforums.com/archive/index.php/t-47018.html 86 // to solve IE error 1072896658 when a Java server sends iso88591 87 // istead of ISO-8859-1 88 89 if (!request || !_Lang.exists(request, "responseXML")) { 90 throw this.makeException(new Error(), _Impl.EMPTY_RESPONSE, _Impl.EMPTY_RESPONSE, this._nameSpace, "processResponse", ""); 91 } 92 //check for a parseError under certain browsers 93 94 var xmlContent = request.responseXML; 95 //ie6+ keeps the parsing response under xmlContent.parserError 96 //while the rest of the world keeps it as element under the first node 97 var xmlErr = _Lang.fetchXMLErrorMessage(request.responseText || request.response, xmlContent) 98 if (xmlErr) { 99 throw this._raiseError(new Error(),xmlErr.errorMessage+"\n"+xmlErr.sourceText+"\n"+xmlErr.visualError+"\n", "processResponse"); 100 } 101 var partials = xmlContent.childNodes[0]; 102 if ('undefined' == typeof partials || partials == null) { 103 throw this._raiseError(new Error(),"No child nodes for response", "processResponse"); 104 105 } else { 106 if (partials.tagName != this.RESP_PARTIAL) { 107 // IE 8 sees XML Header as first sibling ... 108 partials = partials.nextSibling; 109 if (!partials || partials.tagName != this.RESP_PARTIAL) { 110 throw this._raiseError(new Error(), "Partial response not set","processResponse"); 111 } 112 } 113 } 114 115 var childNodesLength = partials.childNodes.length; 116 117 for (var loop = 0; loop < childNodesLength; loop++) { 118 var childNode = partials.childNodes[loop]; 119 var tagName = childNode.tagName; 120 /** 121 * <eval> 122 * <![CDATA[javascript]]> 123 * </eval> 124 */ 125 126 //this ought to be enough for eval 127 //however the run scripts still makes sense 128 //in the update and insert area for components 129 //which do not use the response writer properly 130 //we might add this one as custom option in update and 131 //insert! 132 if (tagName == this.CMD_ERROR) { 133 this.processError(request, context, childNode); 134 } else if (tagName == this.CMD_REDIRECT) { 135 this.processRedirect(request, context, childNode); 136 } else if (tagName == this.CMD_CHANGES) { 137 this.processChanges(request, context, childNode); 138 } 139 } 140 141 //fixup missing viewStates due to spec deficiencies 142 this.fixViewStates(context); 143 144 //spec jsdoc, the success event must be sent from response 145 _Impl.sendEvent(request, context, _Impl["SUCCESS"]); 146 147 } finally { 148 delete mfInternal._updateElems; 149 delete mfInternal._updateForms; 150 delete mfInternal.appliedViewState; 151 } 152 }, 153 154 /** 155 * fixes the viewstates in the current page 156 * 157 * @param context 158 */ 159 fixViewStates : function(context) { 160 var _Lang = this._Lang; 161 var mfInternal = context._mfInternal; 162 163 if (null == mfInternal.appliedViewState) { 164 return; 165 } 166 167 //if we set our no portlet env we safely can update all forms with 168 //the new viewstate 169 if (this._RT.getLocalOrGlobalConfig(context, "no_portlet_env", false)) { 170 for (var cnt = document.forms.length - 1; cnt >= 0; cnt --) { 171 this._setVSTForm(context, document.forms[cnt]); 172 } 173 return; 174 } 175 176 // Now update the forms that were not replaced but forced to be updated, because contains child ajax tags 177 // we should only update forms with view state hidden field. If by some reason, the form was set to be 178 // updated but the form was replaced, it does not have hidden view state, so later in changeTrace processing the 179 // view state is updated. 180 181 //set the viewstates of all outer forms parents of our updated elements 182 var _T = this; 183 _Lang.arrForEach(mfInternal._updateForms, function(elem) { 184 _T._setVSTForm(context, elem); 185 }, 0, this); 186 187 //set the viewstate of all forms within our updated elements 188 _Lang.arrForEach(mfInternal._updateElems, function(elem) { 189 _T._setVSTInnerForms(context, elem); 190 }, 0, this); 191 } 192 , 193 194 /** 195 * sets the viewstate element in a given form 196 * 197 * @param theForm the form to which the element has to be set to 198 * @param context the current request context 199 */ 200 _setVSTForm: function(context, theForm) { 201 theForm = this._Lang.byId(theForm); 202 var mfInternal = context._mfInternal; 203 204 if (!theForm) return; 205 206 var viewStateField = (theForm.elements) ? theForm.elements[this.P_VIEWSTATE] : null;//this._Dom.findFormElement(elem, this.P_VIEWSTATE); 207 208 if (viewStateField) { 209 this._Dom.setAttribute(viewStateField, "value", mfInternal.appliedViewState); 210 } else if (!viewStateField) { 211 var element = this._Dom.getDummyPlaceHolder(); 212 //spec error, two elements with the same id should not be there, TODO recheck the space if the name does not suffice alone 213 element.innerHTML = ["<input type='hidden'", "id='", this.P_VIEWSTATE ,"' name='", this.P_VIEWSTATE ,"' value='" , mfInternal.appliedViewState , "' />"].join(""); 214 //now we go to proper dom handling after having to deal with another ie screwup 215 try { 216 theForm.appendChild(element.childNodes[0]); 217 } finally { 218 element.innerHTML = ""; 219 } 220 } 221 } 222 , 223 224 _setVSTInnerForms: function(context, elem) { 225 226 var _Lang = this._Lang, _Dom = this._Dom; 227 elem = _Dom.byIdOrName(elem); 228 //elem not found for whatever reason 229 //https://issues.apache.org/jira/browse/MYFACES-3544 230 if(!elem) return; 231 232 var replacedForms = _Dom.findByTagName(elem, "form", false); 233 var applyVST = _Lang.hitch(this, function(elem) { 234 this._setVSTForm(context, elem); 235 }); 236 237 try { 238 _Lang.arrForEach(replacedForms, applyVST, 0, this); 239 } finally { 240 applyVST = null; 241 } 242 }, 243 244 /** 245 * processes an incoming error from the response 246 * which is hosted under the <error> tag 247 * @param request the current request 248 * @param context the contect object 249 * @param node the node in the xml hosting the error message 250 */ 251 processError : function(request, context, node) { 252 /** 253 * <error> 254 * <error-name>String</error-name> 255 * <error-message><![CDATA[message]]></error-message> 256 * <error> 257 */ 258 var errorName = node.firstChild.textContent || "", 259 errorMessage = node.childNodes[1].firstChild.data || ""; 260 261 this.attr("impl").sendError(request, context, this.attr("impl").SERVER_ERROR, errorName, errorMessage, "myfaces._impl.xhrCore._AjaxResponse", "processError"); 262 }, 263 264 /** 265 * processes an incoming xml redirect directive from the ajax response 266 * @param request the request object 267 * @param context the context 268 * @param node the node hosting the redirect data 269 */ 270 processRedirect : function(request, context, node) { 271 /** 272 * <redirect url="url to redirect" /> 273 */ 274 var _Lang = this._Lang; 275 var redirectUrl = node.getAttribute("url"); 276 if (!redirectUrl) { 277 throw this._raiseError(new Error(),_Lang.getMessage("ERR_RED_URL", null, "_AjaxResponse.processRedirect"),"processRedirect"); 278 } 279 redirectUrl = _Lang.trim(redirectUrl); 280 if (redirectUrl == "") { 281 return false; 282 } 283 window.location = redirectUrl; 284 return true; 285 } 286 , 287 288 /** 289 * main entry point for processing the changes 290 * it deals with the <changes> node of the 291 * response 292 * 293 * @param request the xhr request object 294 * @param context the context map 295 * @param node the changes node to be processed 296 */ 297 processChanges : function(request, context, node) { 298 var changes = node.childNodes; 299 var _Lang = this._Lang; 300 //note we need to trace the changes which could affect our insert update or delete 301 //se that we can realign our ViewStates afterwards 302 //the realignment must happen post change processing 303 304 for (var i = 0; i < changes.length; i++) { 305 306 switch (changes[i].tagName) { 307 308 case this.CMD_UPDATE: 309 this.processUpdate(request, context, changes[i]); 310 break; 311 case this.CMD_EVAL: 312 _Lang.globalEval(changes[i].firstChild.data); 313 break; 314 case this.CMD_INSERT: 315 this.processInsert(request, context, changes[i]); 316 break; 317 case this.CMD_DELETE: 318 this.processDelete(request, context, changes[i]); 319 break; 320 case this.CMD_ATTRIBUTES: 321 this.processAttributes(request, context, changes[i]); 322 break; 323 case this.CMD_EXTENSION: 324 break; 325 default: 326 throw this._raiseError(new Error(),"_AjaxResponse.processChanges: Illegal Command Issued","processChanges"); 327 } 328 } 329 330 return true; 331 } 332 , 333 334 /** 335 * First sub-step process a pending update tag 336 * 337 * @param request the xhr request object 338 * @param context the context map 339 * @param node the changes node to be processed 340 */ 341 processUpdate : function(request, context, node) { 342 if (node.getAttribute('id') == this.P_VIEWSTATE) { 343 //update the submitting forms viewstate to the new value 344 // The source form has to be pulled out of the CURRENT document first because the context object 345 // may refer to an invalid document if an update of the entire body has occurred before this point. 346 var mfInternal = context._mfInternal, 347 fuzzyFormDetection = this._Lang.hitch(this._Dom, this._Dom.fuzzyFormDetection); 348 var elemId = (mfInternal._mfSourceControlId)? mfInternal._mfSourceControlId: 349 ((context.source)?context.source.id: null); 350 351 //theoretically a source of null can be given, then our form detection fails for 352 //the source element case and hence updateviewstate is skipped for the source 353 //form, but still render targets still can get the viewstate 354 var sourceForm = (mfInternal && mfInternal["_mfSourceFormId"] && 355 document.forms[mfInternal["_mfSourceFormId"]]) ? 356 document.forms[mfInternal["_mfSourceFormId"]] : ((elemId)? fuzzyFormDetection(elemId): null); 357 358 mfInternal.appliedViewState = node.firstChild.nodeValue; 359 //source form could not be determined either over the form identifer or the element 360 //we now skip this phase and just add everything we need for the fixup code 361 362 if (!sourceForm) { 363 //no source form found is not an error because 364 //we might be able to recover one way or the other 365 return true; 366 } 367 368 mfInternal._updateForms.push(sourceForm.id); 369 //this._setVSTForm(sourceForm); 370 } 371 else { 372 // response may contain several blocks 373 var cDataBlock = this._Dom.concatCDATABlocks(node), 374 resultNode = null, 375 pushOpRes = this._Lang.hitch(this, this._pushOperationResult); 376 377 switch (node.getAttribute('id')) { 378 case this.P_VIEWROOT: 379 380 cDataBlock = cDataBlock.substring(cDataBlock.indexOf("<html")); 381 382 var parsedData = this._replaceHead(request, context, cDataBlock); 383 384 resultNode = ('undefined' != typeof parsedData && null != parsedData) ? this._replaceBody(request, context, cDataBlock, parsedData) : this._replaceBody(request, context, cDataBlock); 385 if (resultNode) { 386 pushOpRes(context, resultNode); 387 } 388 break; 389 case this.P_VIEWHEAD: 390 //we cannot replace the head, almost no browser allows this, some of them throw errors 391 //others simply ignore it or replace it and destroy the dom that way! 392 this._replaceHead(request, context, cDataBlock); 393 394 break; 395 case this.P_VIEWBODY: 396 //we assume the cdata block is our body including the tag 397 resultNode = this._replaceBody(request, context, cDataBlock); 398 if (resultNode) { 399 pushOpRes(context, resultNode); 400 } 401 break; 402 403 default: 404 resultNode = this.replaceHtmlItem(request, context, node.getAttribute('id'), cDataBlock); 405 if (resultNode) { 406 pushOpRes(context, resultNode); 407 } 408 break; 409 } 410 } 411 412 return true; 413 } 414 , 415 416 _pushOperationResult: function(context, resultNode) { 417 var mfInternal = context._mfInternal; 418 var pushSubnode = this._Lang.hitch(this, function(currNode) { 419 var parentForm = this._Dom.getParent(currNode, "form"); 420 //if possible we work over the ids 421 //so that elements later replaced are referenced 422 //at the latest possibility 423 if (null != parentForm) { 424 mfInternal._updateForms.push(parentForm.id || parentForm); 425 } 426 else { 427 mfInternal._updateElems.push(currNode.id || currNode); 428 } 429 }); 430 var isArr = 'undefined' != typeof resultNode.length && 'undefined' == typeof resultNode.nodeType; 431 if (isArr && resultNode.length) { 432 for (var cnt = 0; cnt < resultNode.length; cnt++) { 433 pushSubnode(resultNode[cnt]); 434 } 435 } else if (!isArr) { 436 pushSubnode(resultNode); 437 } 438 439 } 440 , 441 442 /** 443 * replaces a current head theoretically, 444 * pratically only the scripts are evaled anew since nothing else 445 * can be changed. 446 * 447 * @param request the current request 448 * @param context the ajax context 449 * @param newData the data to be processed 450 * 451 * @return an xml representation of the page for further processing if possible 452 */ 453 _replaceHead: function(request, context, newData) { 454 455 var _Lang = this._Lang, 456 _Dom = this._Dom, 457 isWebkit = this._RT.browser.isWebKit, 458 //we have to work around an xml parsing bug in Webkit 459 //see https://issues.apache.org/jira/browse/MYFACES-3061 460 doc = (!isWebkit) ? _Lang.parseXML(newData) : null, 461 newHead = null; 462 463 if (!isWebkit && _Lang.isXMLParseError(doc)) { 464 doc = _Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]*\/\/-->/g, "//-->")); 465 } 466 467 if (isWebkit || _Lang.isXMLParseError(doc)) { 468 //the standard xml parser failed we retry with the stripper 469 var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))(); 470 var headData = parser.parse(newData, "head"); 471 //We cannot avoid it here, but we have reduced the parsing now down to the bare minimum 472 //for further processing 473 newHead = _Lang.parseXML("<head>" + headData + "</head>"); 474 //last and slowest option create a new head element and let the browser 475 //do its slow job 476 if (_Lang.isXMLParseError(newHead)) { 477 try { 478 newHead = _Dom.createElement("head"); 479 newHead.innerHTML = headData; 480 } catch (e) { 481 //we give up no further fallbacks 482 throw this._raiseError(new Error(),"Error head replacement failed reason:" + e.toString(),"_replaceHead"); 483 } 484 } 485 } else { 486 //parser worked we go on 487 newHead = doc.getElementsByTagName("head")[0]; 488 } 489 490 var oldTags = _Dom.findByTagNames(document.getElementsByTagName("head")[0], {"link": true, "style":true}); 491 _Dom.runCss(newHead, true); 492 _Dom.deleteItems(oldTags); 493 494 //var oldTags = _Dom.findByTagNames(document.getElementsByTagName("head")[0], {"script": true}); 495 //_Dom.deleteScripts(oldTags); 496 _Dom.runScripts(newHead, true); 497 498 return doc; 499 }, 500 501 502 /** 503 * special method to handle the body dom manipulation, 504 * replacing the entire body does not work fully by simply adding a second body 505 * and by creating a range instead we have to work around that by dom creating a second 506 * body and then filling it properly! 507 * 508 * @param {Object} request our request object 509 * @param {Object} context (Map) the response context 510 * @param {String} newData the markup which replaces the old dom node! 511 * @param {Node} parsedData (optional) preparsed XML representation data of the current document 512 */ 513 _replaceBody : function(request, context, newData /*varargs*/) { 514 var _RT = this._RT, 515 _Dom = this._Dom, 516 _Lang = this._Lang, 517 518 oldBody = document.getElementsByTagName("body")[0], 519 placeHolder = document.createElement("div"), 520 isWebkit = _RT.browser.isWebKit; 521 522 placeHolder.id = "myfaces_bodyplaceholder"; 523 524 _Dom._removeChildNodes(oldBody); 525 oldBody.innerHTML = ""; 526 oldBody.appendChild(placeHolder); 527 528 var bodyData, doc = null, parser; 529 530 //we have to work around an xml parsing bug in Webkit 531 //see https://issues.apache.org/jira/browse/MYFACES-3061 532 if (!isWebkit) { 533 doc = (arguments.length > 3) ? arguments[3] : _Lang.parseXML(newData); 534 } 535 536 if (!isWebkit && _Lang.isXMLParseError(doc)) { 537 doc = _Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]*\/\/-->/g, "//-->")); 538 } 539 540 if (isWebkit || _Lang.isXMLParseError(doc)) { 541 //the standard xml parser failed we retry with the stripper 542 543 parser = new (_RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))(); 544 545 bodyData = parser.parse(newData, "body"); 546 } else { 547 //parser worked we go on 548 var newBodyData = doc.getElementsByTagName("body")[0]; 549 550 //speedwise we serialize back into the code 551 //for code reduction, speedwise we will take a small hit 552 //there which we will clean up in the future, but for now 553 //this is ok, I guess, since replace body only is a small subcase 554 //bodyData = _Lang.serializeChilds(newBodyData); 555 var browser = _RT.browser; 556 if (!browser.isIEMobile || browser.isIEMobile >= 7) { 557 //TODO check what is failing there 558 for (var cnt = 0; cnt < newBodyData.attributes.length; cnt++) { 559 var value = newBodyData.attributes[cnt].value; 560 if (value) 561 _Dom.setAttribute(oldBody, newBodyData.attributes[cnt].name, value); 562 } 563 } 564 } 565 //we cannot serialize here, due to escape problems 566 //we must parse, this is somewhat unsafe but should be safe enough 567 parser = new (_RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))(); 568 bodyData = parser.parse(newData, "body"); 569 570 var returnedElement = this.replaceHtmlItem(request, context, placeHolder, bodyData); 571 572 if (returnedElement) { 573 this._pushOperationResult(context, returnedElement); 574 } 575 return returnedElement; 576 } 577 , 578 579 /** 580 * Replaces HTML elements through others and handle errors if the occur in the replacement part 581 * 582 * @param {Object} request (xhrRequest) 583 * @param {Object} context (Map) 584 * @param {Object} itemIdToReplace (String|Node) - ID of the element to replace 585 * @param {String} markup - the new tag 586 */ 587 replaceHtmlItem : function(request, context, itemIdToReplace, markup) { 588 var _Lang = this._Lang, _Dom = this._Dom; 589 590 var item = (!_Lang.isString(itemIdToReplace)) ? itemIdToReplace : 591 _Dom.byIdOrName(itemIdToReplace); 592 593 if (!item) { 594 throw this._raiseError(_Lang.getMessage("ERR_ITEM_ID_NOTFOUND", null, "_AjaxResponse.replaceHtmlItem", (itemIdToReplace) ? itemIdToReplace.toString() : "undefined")); 595 } 596 return _Dom.outerHTML(item, markup); 597 }, 598 599 /** 600 * xml insert command handler 601 * 602 * @param request the ajax request element 603 * @param context the context element holding the data 604 * @param node the xml node holding the insert data 605 * @return true upon successful completion, false otherwise 606 * 607 **/ 608 processInsert: function(request, context, node) { 609 /*remapping global namespaces for speed and readability reasons*/ 610 var _Dom = this._Dom, 611 _Lang = this._Lang, 612 //determine which path to go: 613 insertData = this._parseInsertData(request, context, node); 614 615 if (!insertData) return false; 616 617 var opNode = _Dom.byIdOrName(insertData.opId); 618 if (!opNode) { 619 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_INSERTBEFID_1", null, "_AjaxResponse.processInsert", insertData.opId),"processInsert"); 620 } 621 622 //call insertBefore or insertAfter in our dom routines 623 var replacementFragment = _Dom[insertData.insertType](opNode, insertData.cDataBlock); 624 if (replacementFragment) { 625 this._pushOperationResult(context, replacementFragment); 626 } 627 return true; 628 }, 629 630 /** 631 * determines the corner data from the insert tag parsing process 632 * 633 * 634 * @param request request 635 * @param context context 636 * @param node the current node pointing to the insert tag 637 * @return false if the parsing failed, otherwise a map with follwing attributes 638 * <ul> 639 * <li>inserType - a ponter to a constant which maps the direct function name for the insert operation </li> 640 * <li>opId - the before or after id </li> 641 * <li>cDataBlock - the html cdata block which needs replacement </li> 642 * </ul> 643 * 644 * TODO we have to find a mechanism to replace the direct sendError calls with a javascript exception 645 * which we then can use for cleaner error code handling 646 */ 647 _parseInsertData: function(request, context, node) { 648 var _Lang = this._Lang, 649 _Dom = this._Dom, 650 concatCDATA = _Dom.concatCDATABlocks, 651 652 INSERT_TYPE_BEFORE = "insertBefore", 653 INSERT_TYPE_AFTER = "insertAfter", 654 655 id = node.getAttribute("id"), 656 beforeId = node.getAttribute("before"), 657 afterId = node.getAttribute("after"), 658 ret = {}; 659 660 //now we have to make a distinction between two different parsing paths 661 //due to a spec malalignment 662 //a <insert id="... beforeId|AfterId ="... 663 //b <insert><before id="..., <insert> <after id=".... 664 //see https://issues.apache.org/jira/browse/MYFACES-3318 665 //simple id, case1 666 if (id && beforeId && !afterId) { 667 ret.insertType = INSERT_TYPE_BEFORE; 668 ret.opId = beforeId; 669 ret.cDataBlock = concatCDATA(node); 670 671 //<insert id=".. afterId=".. 672 } else if (id && !beforeId && afterId) { 673 ret.insertType = INSERT_TYPE_AFTER; 674 ret.opId = afterId; 675 ret.cDataBlock = concatCDATA(node); 676 677 //<insert><before id="... <insert><after id="... 678 } else if (!id) { 679 var opType = node.childNodes[0].tagName; 680 681 if (opType != "before" && opType != "after") { 682 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_INSERTBEFID"),"_parseInsertData"); 683 } 684 opType = opType.toLowerCase(); 685 var beforeAfterId = node.childNodes[0].getAttribute("id"); 686 ret.insertType = (opType == "before") ? INSERT_TYPE_BEFORE : INSERT_TYPE_AFTER; 687 ret.opId = beforeAfterId; 688 ret.cDataBlock = concatCDATA(node.childNodes[0]); 689 } else { 690 throw this._raiseError(new Error(),[_Lang.getMessage("ERR_PPR_IDREQ"), 691 "\n ", 692 _Lang.getMessage("ERR_PPR_INSERTBEFID")].join(""),"_parseInsertData"); 693 } 694 ret.opId = _Lang.trim(ret.opId); 695 return ret; 696 }, 697 698 processDelete : function(request, context, node) { 699 700 var _Lang = this._Lang, 701 _Dom = this._Dom, 702 deleteId = node.getAttribute('id'); 703 704 if (!deleteId) { 705 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_UNKNOWNCID", null, "_AjaxResponse.processDelete", ""),"processDelete"); 706 } 707 708 var item = _Dom.byIdOrName(deleteId); 709 if (!item) { 710 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_UNKNOWNCID", null, "_AjaxResponse.processDelete", deleteId),"processDelete"); 711 } 712 713 var parentForm = this._Dom.getParent(item, "form"); 714 if (null != parentForm) { 715 context._mfInternal._updateForms.push(parentForm); 716 } 717 _Dom.deleteItem(item); 718 719 return true; 720 } 721 , 722 723 processAttributes : function(request, context, node) { 724 //we now route into our attributes function to bypass 725 //IE quirks mode incompatibilities to the biggest possible extent 726 //most browsers just have to do a setAttributes but IE 727 //behaves as usual not like the official standard 728 //myfaces._impl._util.this._Dom.setAttribute(domNode, attribute, value; 729 730 var _Lang = this._Lang, 731 //<attributes id="id of element"> <attribute name="attribute name" value="attribute value" />* </attributes> 732 elemId = node.getAttribute('id'); 733 734 if (!elemId) { 735 throw this._raiseError(new Error(),"Error in attributes, id not in xml markup","processAttributes"); 736 } 737 var childNodes = node.childNodes; 738 739 if (!childNodes) { 740 return false; 741 } 742 for (var loop2 = 0; loop2 < childNodes.length; loop2++) { 743 var attributesNode = childNodes[loop2], 744 attrName = attributesNode.getAttribute("name"), 745 attrValue = attributesNode.getAttribute("value"); 746 747 if (!attrName) { 748 continue; 749 } 750 751 attrName = _Lang.trim(attrName); 752 /*no value means reset*/ 753 //value can be of boolean value hence full check 754 if ('undefined' == typeof attrValue || null == attrValue) { 755 attrValue = ""; 756 } 757 758 switch (elemId) { 759 case this.P_VIEWROOT: 760 throw this._raiseError(new Error(),_Lang.getMessage("ERR_NO_VIEWROOTATTR", null, "_AjaxResponse.processAttributes"),"processAttributes"); 761 762 case this.P_VIEWHEAD: 763 throw this._raiseError(new Error(),_Lang.getMessage("ERR_NO_HEADATTR", null, "_AjaxResponse.processAttributes"),"processAttributes"); 764 765 case this.P_VIEWBODY: 766 var element = document.getElementsByTagName("body")[0]; 767 this._Dom.setAttribute(element, attrName, attrValue); 768 break; 769 770 default: 771 this._Dom.setAttribute(document.getElementById(elemId), attrName, attrValue); 772 break; 773 } 774 } 775 return true; 776 }, 777 778 /** 779 * internal helper which raises an error in the 780 * format we need for further processing 781 * 782 * @param message the message 783 * @param title the title of the error (optional) 784 * @param name the name of the error (optional) 785 */ 786 _raiseError: function(error, message, caller, title, name) { 787 var _Impl = this.attr("impl"); 788 var finalTitle = title || _Impl.MALFORMEDXML; 789 var finalName = name || _Impl.MALFORMEDXML; 790 var finalMessage = message || ""; 791 792 return this._Lang.makeException(error, finalTitle, finalName, this._nameSpace, caller || ( (arguments.caller) ? arguments.caller.toString() : "_raiseError"), finalMessage); 793 } 794 }); 795