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 234 var applyVST = _Lang.hitch(this, function(elem) { 235 this._setVSTForm(context, elem); 236 }); 237 238 try { 239 _Lang.arrForEach(replacedForms, applyVST, 0, this); 240 } finally { 241 applyVST = null; 242 } 243 }, 244 245 /** 246 * processes an incoming error from the response 247 * which is hosted under the <error> tag 248 * @param request the current request 249 * @param context the contect object 250 * @param node the node in the xml hosting the error message 251 */ 252 processError : function(request, context, node) { 253 /** 254 * <error> 255 * <error-name>String</error-name> 256 * <error-message><![CDATA[message]]></error-message> 257 * <error> 258 */ 259 var errorName = node.firstChild.textContent || "", 260 errorMessage = node.childNodes[1].firstChild.data || ""; 261 262 this.attr("impl").sendError(request, context, this.attr("impl").SERVER_ERROR, errorName, errorMessage, "myfaces._impl.xhrCore._AjaxResponse", "processError"); 263 }, 264 265 /** 266 * processes an incoming xml redirect directive from the ajax response 267 * @param request the request object 268 * @param context the context 269 * @param node the node hosting the redirect data 270 */ 271 processRedirect : function(request, context, node) { 272 /** 273 * <redirect url="url to redirect" /> 274 */ 275 var _Lang = this._Lang; 276 var redirectUrl = node.getAttribute("url"); 277 if (!redirectUrl) { 278 throw this._raiseError(new Error(),_Lang.getMessage("ERR_RED_URL", null, "_AjaxResponse.processRedirect"),"processRedirect"); 279 } 280 redirectUrl = _Lang.trim(redirectUrl); 281 if (redirectUrl == "") { 282 return false; 283 } 284 window.location = redirectUrl; 285 return true; 286 } 287 , 288 289 /** 290 * main entry point for processing the changes 291 * it deals with the <changes> node of the 292 * response 293 * 294 * @param request the xhr request object 295 * @param context the context map 296 * @param node the changes node to be processed 297 */ 298 processChanges : function(request, context, node) { 299 var changes = node.childNodes; 300 var _Lang = this._Lang; 301 //note we need to trace the changes which could affect our insert update or delete 302 //se that we can realign our ViewStates afterwards 303 //the realignment must happen post change processing 304 305 for (var i = 0; i < changes.length; i++) { 306 307 switch (changes[i].tagName) { 308 309 case this.CMD_UPDATE: 310 this.processUpdate(request, context, changes[i]); 311 break; 312 case this.CMD_EVAL: 313 _Lang.globalEval(changes[i].firstChild.data); 314 break; 315 case this.CMD_INSERT: 316 this.processInsert(request, context, changes[i]); 317 break; 318 case this.CMD_DELETE: 319 this.processDelete(request, context, changes[i]); 320 break; 321 case this.CMD_ATTRIBUTES: 322 this.processAttributes(request, context, changes[i]); 323 break; 324 case this.CMD_EXTENSION: 325 break; 326 default: 327 throw this._raiseError(new Error(),"_AjaxResponse.processChanges: Illegal Command Issued","processChanges"); 328 } 329 } 330 331 return true; 332 } 333 , 334 335 /** 336 * First sub-step process a pending update tag 337 * 338 * @param request the xhr request object 339 * @param context the context map 340 * @param node the changes node to be processed 341 */ 342 processUpdate : function(request, context, node) { 343 if (node.getAttribute('id') == this.P_VIEWSTATE) { 344 //update the submitting forms viewstate to the new value 345 // The source form has to be pulled out of the CURRENT document first because the context object 346 // may refer to an invalid document if an update of the entire body has occurred before this point. 347 var mfInternal = context._mfInternal, 348 fuzzyFormDetection = this._Lang.hitch(this._Dom, this._Dom.fuzzyFormDetection); 349 var elemId = (mfInternal._mfSourceControlId)? mfInternal._mfSourceControlId: 350 ((context.source)?context.source.id: null); 351 352 //theoretically a source of null can be given, then our form detection fails for 353 //the source element case and hence updateviewstate is skipped for the source 354 //form, but still render targets still can get the viewstate 355 var sourceForm = (mfInternal && mfInternal["_mfSourceFormId"] && 356 document.forms[mfInternal["_mfSourceFormId"]]) ? 357 document.forms[mfInternal["_mfSourceFormId"]] : ((elemId)? fuzzyFormDetection(elemId): null); 358 359 mfInternal.appliedViewState = node.firstChild.nodeValue; 360 //source form could not be determined either over the form identifer or the element 361 //we now skip this phase and just add everything we need for the fixup code 362 363 if (!sourceForm) { 364 //no source form found is not an error because 365 //we might be able to recover one way or the other 366 return true; 367 } 368 369 mfInternal._updateForms.push(sourceForm.id); 370 //this._setVSTForm(sourceForm); 371 } 372 else { 373 // response may contain several blocks 374 var cDataBlock = this._Dom.concatCDATABlocks(node), 375 resultNode = null, 376 pushOpRes = this._Lang.hitch(this, this._pushOperationResult); 377 378 switch (node.getAttribute('id')) { 379 case this.P_VIEWROOT: 380 381 cDataBlock = cDataBlock.substring(cDataBlock.indexOf("<html")); 382 383 var parsedData = this._replaceHead(request, context, cDataBlock); 384 385 resultNode = ('undefined' != typeof parsedData && null != parsedData) ? this._replaceBody(request, context, cDataBlock, parsedData) : this._replaceBody(request, context, cDataBlock); 386 if (resultNode) { 387 pushOpRes(context, resultNode); 388 } 389 break; 390 case this.P_VIEWHEAD: 391 //we cannot replace the head, almost no browser allows this, some of them throw errors 392 //others simply ignore it or replace it and destroy the dom that way! 393 this._replaceHead(request, context, cDataBlock); 394 395 break; 396 case this.P_VIEWBODY: 397 //we assume the cdata block is our body including the tag 398 resultNode = this._replaceBody(request, context, cDataBlock); 399 if (resultNode) { 400 pushOpRes(context, resultNode); 401 } 402 break; 403 404 default: 405 resultNode = this.replaceHtmlItem(request, context, node.getAttribute('id'), cDataBlock); 406 if (resultNode) { 407 pushOpRes(context, resultNode); 408 } 409 break; 410 } 411 } 412 413 return true; 414 } 415 , 416 417 _pushOperationResult: function(context, resultNode) { 418 var mfInternal = context._mfInternal; 419 var pushSubnode = this._Lang.hitch(this, function(currNode) { 420 var parentForm = this._Dom.getParent(currNode, "form"); 421 //if possible we work over the ids 422 //so that elements later replaced are referenced 423 //at the latest possibility 424 if (null != parentForm) { 425 mfInternal._updateForms.push(parentForm.id || parentForm); 426 } 427 else { 428 mfInternal._updateElems.push(currNode.id || currNode); 429 } 430 }); 431 var isArr = 'undefined' != typeof resultNode.length && 'undefined' == typeof resultNode.nodeType; 432 if (isArr && resultNode.length) { 433 for (var cnt = 0; cnt < resultNode.length; cnt++) { 434 pushSubnode(resultNode[cnt]); 435 } 436 } else if (!isArr) { 437 pushSubnode(resultNode); 438 } 439 440 } 441 , 442 443 /** 444 * replaces a current head theoretically, 445 * pratically only the scripts are evaled anew since nothing else 446 * can be changed. 447 * 448 * @param request the current request 449 * @param context the ajax context 450 * @param newData the data to be processed 451 * 452 * @return an xml representation of the page for further processing if possible 453 */ 454 _replaceHead: function(request, context, newData) { 455 456 var _Lang = this._Lang, 457 _Dom = this._Dom, 458 isWebkit = this._RT.browser.isWebKit, 459 //we have to work around an xml parsing bug in Webkit 460 //see https://issues.apache.org/jira/browse/MYFACES-3061 461 doc = (!isWebkit) ? _Lang.parseXML(newData) : null, 462 newHead = null; 463 464 if (!isWebkit && _Lang.isXMLParseError(doc)) { 465 doc = _Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]*\/\/-->/g, "//-->")); 466 } 467 468 if (isWebkit || _Lang.isXMLParseError(doc)) { 469 //the standard xml parser failed we retry with the stripper 470 var parser = new (this._RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))(); 471 var headData = parser.parse(newData, "head"); 472 //We cannot avoid it here, but we have reduced the parsing now down to the bare minimum 473 //for further processing 474 newHead = _Lang.parseXML("<head>" + headData + "</head>"); 475 //last and slowest option create a new head element and let the browser 476 //do its slow job 477 if (_Lang.isXMLParseError(newHead)) { 478 try { 479 newHead = _Dom.createElement("head"); 480 newHead.innerHTML = headData; 481 } catch (e) { 482 //we give up no further fallbacks 483 throw this._raiseError(new Error(),"Error head replacement failed reason:" + e.toString(),"_replaceHead"); 484 } 485 } 486 } else { 487 //parser worked we go on 488 newHead = doc.getElementsByTagName("head")[0]; 489 } 490 491 var oldTags = _Dom.findByTagNames(document.getElementsByTagName("head")[0], {"link": true, "style":true}); 492 _Dom.runCss(newHead, true); 493 _Dom.deleteItems(oldTags); 494 495 //var oldTags = _Dom.findByTagNames(document.getElementsByTagName("head")[0], {"script": true}); 496 //_Dom.deleteScripts(oldTags); 497 _Dom.runScripts(newHead, true); 498 499 return doc; 500 }, 501 502 503 /** 504 * special method to handle the body dom manipulation, 505 * replacing the entire body does not work fully by simply adding a second body 506 * and by creating a range instead we have to work around that by dom creating a second 507 * body and then filling it properly! 508 * 509 * @param {Object} request our request object 510 * @param {Object} context (Map) the response context 511 * @param {String} newData the markup which replaces the old dom node! 512 * @param {Node} parsedData (optional) preparsed XML representation data of the current document 513 */ 514 _replaceBody : function(request, context, newData /*varargs*/) { 515 var _RT = this._RT, 516 _Dom = this._Dom, 517 _Lang = this._Lang, 518 519 oldBody = document.getElementsByTagName("body")[0], 520 placeHolder = document.createElement("div"), 521 isWebkit = _RT.browser.isWebKit; 522 523 placeHolder.id = "myfaces_bodyplaceholder"; 524 525 _Dom._removeChildNodes(oldBody); 526 oldBody.innerHTML = ""; 527 oldBody.appendChild(placeHolder); 528 529 var bodyData, doc = null, parser; 530 531 //we have to work around an xml parsing bug in Webkit 532 //see https://issues.apache.org/jira/browse/MYFACES-3061 533 if (!isWebkit) { 534 doc = (arguments.length > 3) ? arguments[3] : _Lang.parseXML(newData); 535 } 536 537 if (!isWebkit && _Lang.isXMLParseError(doc)) { 538 doc = _Lang.parseXML(newData.replace(/<!\-\-[\s\n]*<!\-\-/g, "<!--").replace(/\/\/-->[\s\n]*\/\/-->/g, "//-->")); 539 } 540 541 if (isWebkit || _Lang.isXMLParseError(doc)) { 542 //the standard xml parser failed we retry with the stripper 543 544 parser = new (_RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))(); 545 546 bodyData = parser.parse(newData, "body"); 547 } else { 548 //parser worked we go on 549 var newBodyData = doc.getElementsByTagName("body")[0]; 550 551 //speedwise we serialize back into the code 552 //for code reduction, speedwise we will take a small hit 553 //there which we will clean up in the future, but for now 554 //this is ok, I guess, since replace body only is a small subcase 555 //bodyData = _Lang.serializeChilds(newBodyData); 556 var browser = _RT.browser; 557 if (!browser.isIEMobile || browser.isIEMobile >= 7) { 558 //TODO check what is failing there 559 for (var cnt = 0; cnt < newBodyData.attributes.length; cnt++) { 560 var value = newBodyData.attributes[cnt].value; 561 if (value) 562 _Dom.setAttribute(oldBody, newBodyData.attributes[cnt].name, value); 563 } 564 } 565 } 566 //we cannot serialize here, due to escape problems 567 //we must parse, this is somewhat unsafe but should be safe enough 568 parser = new (_RT.getGlobalConfig("updateParser", myfaces._impl._util._HtmlStripper))(); 569 bodyData = parser.parse(newData, "body"); 570 571 var returnedElement = this.replaceHtmlItem(request, context, placeHolder, bodyData); 572 573 if (returnedElement) { 574 this._pushOperationResult(context, returnedElement); 575 } 576 return returnedElement; 577 } 578 , 579 580 /** 581 * Replaces HTML elements through others and handle errors if the occur in the replacement part 582 * 583 * @param {Object} request (xhrRequest) 584 * @param {Object} context (Map) 585 * @param {Object} itemIdToReplace (String|Node) - ID of the element to replace 586 * @param {String} markup - the new tag 587 */ 588 replaceHtmlItem : function(request, context, itemIdToReplace, markup) { 589 var _Lang = this._Lang, _Dom = this._Dom; 590 591 var item = (!_Lang.isString(itemIdToReplace)) ? itemIdToReplace : 592 _Dom.byIdOrName(itemIdToReplace); 593 594 if (!item) { 595 throw this._raiseError(_Lang.getMessage("ERR_ITEM_ID_NOTFOUND", null, "_AjaxResponse.replaceHtmlItem", (itemIdToReplace) ? itemIdToReplace.toString() : "undefined")); 596 } 597 return _Dom.outerHTML(item, markup); 598 }, 599 600 /** 601 * xml insert command handler 602 * 603 * @param request the ajax request element 604 * @param context the context element holding the data 605 * @param node the xml node holding the insert data 606 * @return true upon successful completion, false otherwise 607 * 608 **/ 609 processInsert: function(request, context, node) { 610 /*remapping global namespaces for speed and readability reasons*/ 611 var _Dom = this._Dom, 612 _Lang = this._Lang, 613 //determine which path to go: 614 insertData = this._parseInsertData(request, context, node); 615 616 if (!insertData) return false; 617 618 var opNode = _Dom.byIdOrName(insertData.opId); 619 if (!opNode) { 620 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_INSERTBEFID_1", null, "_AjaxResponse.processInsert", insertData.opId),"processInsert"); 621 } 622 623 //call insertBefore or insertAfter in our dom routines 624 var replacementFragment = _Dom[insertData.insertType](opNode, insertData.cDataBlock); 625 if (replacementFragment) { 626 this._pushOperationResult(context, replacementFragment); 627 } 628 return true; 629 }, 630 631 /** 632 * determines the corner data from the insert tag parsing process 633 * 634 * 635 * @param request request 636 * @param context context 637 * @param node the current node pointing to the insert tag 638 * @return false if the parsing failed, otherwise a map with follwing attributes 639 * <ul> 640 * <li>inserType - a ponter to a constant which maps the direct function name for the insert operation </li> 641 * <li>opId - the before or after id </li> 642 * <li>cDataBlock - the html cdata block which needs replacement </li> 643 * </ul> 644 * 645 * TODO we have to find a mechanism to replace the direct sendError calls with a javascript exception 646 * which we then can use for cleaner error code handling 647 */ 648 _parseInsertData: function(request, context, node) { 649 var _Lang = this._Lang, 650 _Dom = this._Dom, 651 concatCDATA = _Dom.concatCDATABlocks, 652 653 INSERT_TYPE_BEFORE = "insertBefore", 654 INSERT_TYPE_AFTER = "insertAfter", 655 656 id = node.getAttribute("id"), 657 beforeId = node.getAttribute("before"), 658 afterId = node.getAttribute("after"), 659 ret = {}; 660 661 //now we have to make a distinction between two different parsing paths 662 //due to a spec malalignment 663 //a <insert id="... beforeId|AfterId ="... 664 //b <insert><before id="..., <insert> <after id=".... 665 //see https://issues.apache.org/jira/browse/MYFACES-3318 666 //simple id, case1 667 if (id && beforeId && !afterId) { 668 ret.insertType = INSERT_TYPE_BEFORE; 669 ret.opId = beforeId; 670 ret.cDataBlock = concatCDATA(node); 671 672 //<insert id=".. afterId=".. 673 } else if (id && !beforeId && afterId) { 674 ret.insertType = INSERT_TYPE_AFTER; 675 ret.opId = afterId; 676 ret.cDataBlock = concatCDATA(node); 677 678 //<insert><before id="... <insert><after id="... 679 } else if (!id) { 680 var opType = node.childNodes[0].tagName; 681 682 if (opType != "before" && opType != "after") { 683 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_INSERTBEFID"),"_parseInsertData"); 684 } 685 opType = opType.toLowerCase(); 686 var beforeAfterId = node.childNodes[0].getAttribute("id"); 687 ret.insertType = (opType == "before") ? INSERT_TYPE_BEFORE : INSERT_TYPE_AFTER; 688 ret.opId = beforeAfterId; 689 ret.cDataBlock = concatCDATA(node.childNodes[0]); 690 } else { 691 throw this._raiseError(new Error(),[_Lang.getMessage("ERR_PPR_IDREQ"), 692 "\n ", 693 _Lang.getMessage("ERR_PPR_INSERTBEFID")].join(""),"_parseInsertData"); 694 } 695 ret.opId = _Lang.trim(ret.opId); 696 return ret; 697 }, 698 699 processDelete : function(request, context, node) { 700 701 var _Lang = this._Lang, 702 _Dom = this._Dom, 703 deleteId = node.getAttribute('id'); 704 705 if (!deleteId) { 706 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_UNKNOWNCID", null, "_AjaxResponse.processDelete", ""),"processDelete"); 707 } 708 709 var item = _Dom.byIdOrName(deleteId); 710 if (!item) { 711 throw this._raiseError(new Error(),_Lang.getMessage("ERR_PPR_UNKNOWNCID", null, "_AjaxResponse.processDelete", deleteId),"processDelete"); 712 } 713 714 var parentForm = this._Dom.getParent(item, "form"); 715 if (null != parentForm) { 716 context._mfInternal._updateForms.push(parentForm); 717 } 718 _Dom.deleteItem(item); 719 720 return true; 721 } 722 , 723 724 processAttributes : function(request, context, node) { 725 //we now route into our attributes function to bypass 726 //IE quirks mode incompatibilities to the biggest possible extent 727 //most browsers just have to do a setAttributes but IE 728 //behaves as usual not like the official standard 729 //myfaces._impl._util.this._Dom.setAttribute(domNode, attribute, value; 730 731 var _Lang = this._Lang, 732 //<attributes id="id of element"> <attribute name="attribute name" value="attribute value" />* </attributes> 733 elemId = node.getAttribute('id'); 734 735 if (!elemId) { 736 throw this._raiseError(new Error(),"Error in attributes, id not in xml markup","processAttributes"); 737 } 738 var childNodes = node.childNodes; 739 740 if (!childNodes) { 741 return false; 742 } 743 for (var loop2 = 0; loop2 < childNodes.length; loop2++) { 744 var attributesNode = childNodes[loop2], 745 attrName = attributesNode.getAttribute("name"), 746 attrValue = attributesNode.getAttribute("value"); 747 748 if (!attrName) { 749 continue; 750 } 751 752 attrName = _Lang.trim(attrName); 753 /*no value means reset*/ 754 //value can be of boolean value hence full check 755 if ('undefined' == typeof attrValue || null == attrValue) { 756 attrValue = ""; 757 } 758 759 switch (elemId) { 760 case this.P_VIEWROOT: 761 throw this._raiseError(new Error(),_Lang.getMessage("ERR_NO_VIEWROOTATTR", null, "_AjaxResponse.processAttributes"),"processAttributes"); 762 763 case this.P_VIEWHEAD: 764 throw this._raiseError(new Error(),_Lang.getMessage("ERR_NO_HEADATTR", null, "_AjaxResponse.processAttributes"),"processAttributes"); 765 766 case this.P_VIEWBODY: 767 var element = document.getElementsByTagName("body")[0]; 768 this._Dom.setAttribute(element, attrName, attrValue); 769 break; 770 771 default: 772 this._Dom.setAttribute(document.getElementById(elemId), attrName, attrValue); 773 break; 774 } 775 } 776 return true; 777 }, 778 779 /** 780 * internal helper which raises an error in the 781 * format we need for further processing 782 * 783 * @param message the message 784 * @param title the title of the error (optional) 785 * @param name the name of the error (optional) 786 */ 787 _raiseError: function(error, message, caller, title, name) { 788 var _Impl = this.attr("impl"); 789 var finalTitle = title || _Impl.MALFORMEDXML; 790 var finalName = name || _Impl.MALFORMEDXML; 791 var finalMessage = message || ""; 792 793 return this._Lang.makeException(error, finalTitle, finalName, this._nameSpace, caller || ( (arguments.caller) ? arguments.caller.toString() : "_raiseError"), finalMessage); 794 } 795 }); 796