You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/01/16 15:13:13 UTC
git commit: WICKET-4332 FileUpload: Using IE9 in IE8 compatibility
mode, ajax-response cannot be parsed
Updated Branches:
refs/heads/wicket-1.5.x 2eae2bb8b -> 2b456a865
WICKET-4332
FileUpload: Using IE9 in IE8 compatibility mode, ajax-response cannot be parsed
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2b456a86
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2b456a86
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2b456a86
Branch: refs/heads/wicket-1.5.x
Commit: 2b456a865f184421f23010f2b65c6f8323d81db0
Parents: 2eae2bb
Author: martin-g <mg...@apache.org>
Authored: Mon Jan 16 15:13:06 2012 +0100
Committer: martin-g <mg...@apache.org>
Committed: Mon Jan 16 15:13:06 2012 +0100
----------------------------------------------------------------------
.../java/org/apache/wicket/ajax/wicket-ajax.js | 84 ++++++++++++---
1 files changed, 69 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/2b456a86/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js b/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
index 37f3049..c828658 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
@@ -1201,7 +1201,7 @@ Wicket.Ajax.Call.prototype = {
form.method="post";
form.enctype="multipart/form-data";
form.encoding="multipart/form-data";
-
+
// create submitting button element
if (submitButton!=null) {
try {
@@ -1249,7 +1249,7 @@ Wicket.Ajax.Call.prototype = {
var envelope=iframe.contentWindow.document;
if (envelope.XMLDocument!=null) { envelope=envelope.XMLDocument; }
-
+
// process the response
this.loadedCallback(envelope);
@@ -1286,7 +1286,12 @@ Wicket.Ajax.Call.prototype = {
// loaded.
try {
var root = envelope.getElementsByTagName("ajax-response")[0];
-
+
+ if (root == null && envelope.compatMode == 'BackCompat') {
+ envelope = Wicket._htmlToDomDocument(envelope);
+ root = envelope.getElementsByTagName("ajax-response")[0];
+ }
+
// the root element must be <ajax-response
if (root == null || root.tagName != "ajax-response") {
this.failure("Could not find root <ajax-response> element");
@@ -1530,18 +1535,8 @@ Wicket.Head.Contributor.prototype = {
}
// build a DOM tree of the contribution
- var xmldoc;
- if (window.DOMParser) {
- var parser = new DOMParser();
- xmldoc = parser.parseFromString(text, "text/xml");
- } else if (window.ActiveXObject) {
- xmldoc = new ActiveXObject("Microsoft.XMLDOM");
- if (!xmldoc.loadXML(text)) {
- Wicket.Log.error("Error parsing response: "+text);
- }
- }
-
- return xmldoc;
+ var xmldoc = Wicket._createXmlDocument(text);
+ return xmldoc;
},
// checks whether the passed node is the special "parsererror"
@@ -2548,3 +2543,62 @@ Wicket._getAjaxBaseUrl = function() {
var baseUrl = Wicket.Ajax.baseUrl || '.';
return baseUrl;
}
+
+/**
+ * Helper method that serializes HtmlDocument to string and then
+ * creates a DOMDocument by parsing this string.
+ * It is used as a workaround for the problem described at https://issues.apache.org/jira/browse/WICKET-4332
+ * @param envelope (DispHtmlDocument) the document object created by IE from the XML response in the iframe
+ */
+Wicket._htmlToDomDocument = function (envelope) {
+ var xmlAsString = envelope.body.outerText;
+ xmlAsString = xmlAsString.replace(/^\s+|\s+$/g, ''); // trim
+ xmlAsString = xmlAsString.replace(/(\n|\r)-*/g, ''); // remove '\r\n-'. The dash is optional.
+ var xmldoc = Wicket._createXmlDocument(xmlAsString);
+ xmldoc.async = "false";
+ if (!xmldoc.loadXML(xmlAsString)) {
+ Wicket.Log.error("Error parsing response: "+xmlAsString);
+ }
+ return xmldoc;
+};
+
+/**
+ * Helper method that creates a DOM Document using the best parser available.
+ *
+ * @param text {String} the text to parse and create Document from.
+ */
+Wicket._createXmlDocument = function (text) {
+ var xmlDocument;
+ if (window.DOMParser) {
+ var parser = new DOMParser();
+ xmlDocument = parser.parseFromString(text, "text/xml");
+ } else if (window.ActiveXObject) {
+ try {
+ xmlDocument = new ActiveXObject("Msxml2.DOMDocument.6.0");
+ } catch (err6) {
+ try {
+ xmlDocument = new ActiveXObject("Msxml2.DOMDocument.5.0");
+ } catch (err5) {
+ try {
+ xmlDocument = new ActiveXObject("Msxml2.DOMDocument.4.0");
+ } catch (err4) {
+ try {
+ xmlDocument = new ActiveXObject("MSXML2.DOMDocument.3.0");
+ } catch (err3) {
+ try {
+ xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
+ } catch (err2) {
+ Wicket.Log.error("Cannot create DOM document: " + err2);
+ }
+ }
+ }
+ }
+ }
+
+ if (xmlDocument && !xmlDocument.loadXML(text)) {
+ Wicket.Log.error("Error parsing response: "+text);
+ }
+ }
+
+ return xmlDocument;
+};
\ No newline at end of file