diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp
index 9d9c1f95bbd..65613d9a293 100644
--- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp
+++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp
@@ -71,6 +71,8 @@ static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
+static void SetTextStringOnTextNode(const nsString& aTextString, nsIContent* aTextNode);
+
#define XML_PSEUDO_ELEMENT 0
// XXX Open Issues:
@@ -719,22 +721,125 @@ nsXMLContentSink::AddLeaf(const nsIParserNode& aNode)
return NS_OK;
}
-NS_IMETHODIMP
-nsXMLContentSink::NotifyError(const nsParserError* aError)
-{
- nsString errorText("XML Parser Error: '");
+nsresult nsXMLContentSink::CreateErrorText(const nsParserError* aError, nsString& aErrorString)
+{
+ nsString errorText("XML Parsing Error: ");
if (aError) {
errorText.Append(aError->description);
- errorText.Append("', Line: ");
+ errorText.Append("\nLine Number ");
errorText.Append(aError->lineNumber, 10);
- errorText.Append(", Column: ");
+ errorText.Append(", Column ");
errorText.Append(aError->colNumber, 10);
+ errorText.Append(":");
+ }
+
+ aErrorString = errorText;
+
+ return NS_OK;
+}
+
+nsresult nsXMLContentSink::CreateSourceText(const nsParserError* aError, nsString& aSourceString)
+{
+ nsString sourceText;
+ PRInt32 errorPosition = aError->colNumber;
+
+ sourceText.Append(aError->sourceLine);
+ sourceText.Append("\n");
+ for (int i = 0; i < errorPosition - 1; i++)
+ sourceText.Append("-");
+ sourceText.Append("^");
+
+ aSourceString = sourceText;
+
+ return NS_OK;
+}
+
+static void SetTextStringOnTextNode(const nsString& aTextString, nsIContent* aTextNode)
+{
+ nsITextContent* text = nsnull;
+ PRUnichar *tempUnicode = aTextString.ToNewUnicode();
+ static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
+
+ aTextNode->QueryInterface(kITextContentIID, (void**) &text);
+ text->SetText(tempUnicode, aTextString.Length(), PR_FALSE);
+ delete [] tempUnicode;
+ NS_RELEASE(text);
+}
+
+
+/*
+ * We create the following XML snippet programmatically and
+ * insert it into the content model:
+ *
+ *
+ * XML Error: "contents of aError->description"
+ * Line Number: "contents of aError->lineNumber"
+ *
+ * "Contents of aError->sourceLine"
+ * "^ pointing at the error location"
+ *
+ *
+ *
+ */
+NS_IMETHODIMP
+nsXMLContentSink::NotifyError(const nsParserError* aError)
+{
+ nsresult result = NS_OK;
+ nsAutoString parserErrorTag = "parsererror";
+ nsAutoString sourceTextTag = "sourcetext";
+ nsString errorText;
+ nsString sourceText;
+ nsIHTMLContent* errorContainerNode = nsnull;
+ nsIHTMLContent* sourceContainerNode = nsnull;
+ nsIContent* errorTextNode = nsnull;
+ nsIContent* sourceTextNode = nsnull;
+
+ /* Create container and text content nodes */
+ result = NS_CreateHTMLElement(&errorContainerNode, parserErrorTag);
+ if (NS_OK == result) {
+ result = NS_NewTextNode(&errorTextNode);
+ if (NS_OK == result) {
+ result = NS_CreateHTMLElement(&sourceContainerNode, sourceTextTag);
+ if (NS_OK == result) {
+ result = NS_NewTextNode(&sourceTextNode);
+ }
+ }
}
- AddText(errorText);
- FlushText();
- return NS_OK;
+ /* Create the error text string and source text string
+ and set the text strings into the text nodes. */
+ result = CreateErrorText(aError, errorText);
+ if (NS_OK == result) {
+ SetTextStringOnTextNode(errorText, errorTextNode);
+ }
+
+ result = CreateSourceText(aError, sourceText);
+ if (NS_OK == result) {
+ SetTextStringOnTextNode(sourceText, sourceTextNode);
+ }
+
+ /* Hook the content nodes up to the document and to each other */
+ if (NS_OK == result) {
+ errorContainerNode->SetDocument(mDocument, PR_FALSE);
+ errorTextNode->SetDocument(mDocument, PR_FALSE);
+ sourceContainerNode->SetDocument(mDocument, PR_FALSE);
+ sourceTextNode->SetDocument(mDocument, PR_FALSE);
+
+ if (nsnull == mDocElement) {
+ mDocElement = errorContainerNode;
+ NS_ADDREF(mDocElement);
+ mDocument->SetRootContent(mDocElement);
+ }
+ else {
+ mDocElement->AppendChildTo(errorContainerNode, PR_FALSE);
+ }
+ errorContainerNode->AppendChildTo(errorTextNode, PR_FALSE);
+ errorContainerNode->AppendChildTo(sourceContainerNode, PR_FALSE);
+ sourceContainerNode->AppendChildTo(sourceTextNode, PR_FALSE);
+ }
+
+ return result;
}
// nsIXMLContentSink
diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.h b/mozilla/content/xml/document/src/nsXMLContentSink.h
index f9a820ffeb1..ee2c0f97655 100644
--- a/mozilla/content/xml/document/src/nsXMLContentSink.h
+++ b/mozilla/content/xml/document/src/nsXMLContentSink.h
@@ -121,6 +121,8 @@ protected:
#endif
nsresult AddText(const nsString& aString);
+ nsresult CreateErrorText(const nsParserError* aError, nsString& aErrorString);
+ nsresult CreateSourceText(const nsParserError* aError, nsString& aSourceString);
nsIDocument* mDocument;
nsIURL* mDocumentURL;
diff --git a/mozilla/layout/xml/document/src/nsXMLContentSink.cpp b/mozilla/layout/xml/document/src/nsXMLContentSink.cpp
index 9d9c1f95bbd..65613d9a293 100644
--- a/mozilla/layout/xml/document/src/nsXMLContentSink.cpp
+++ b/mozilla/layout/xml/document/src/nsXMLContentSink.cpp
@@ -71,6 +71,8 @@ static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
+static void SetTextStringOnTextNode(const nsString& aTextString, nsIContent* aTextNode);
+
#define XML_PSEUDO_ELEMENT 0
// XXX Open Issues:
@@ -719,22 +721,125 @@ nsXMLContentSink::AddLeaf(const nsIParserNode& aNode)
return NS_OK;
}
-NS_IMETHODIMP
-nsXMLContentSink::NotifyError(const nsParserError* aError)
-{
- nsString errorText("XML Parser Error: '");
+nsresult nsXMLContentSink::CreateErrorText(const nsParserError* aError, nsString& aErrorString)
+{
+ nsString errorText("XML Parsing Error: ");
if (aError) {
errorText.Append(aError->description);
- errorText.Append("', Line: ");
+ errorText.Append("\nLine Number ");
errorText.Append(aError->lineNumber, 10);
- errorText.Append(", Column: ");
+ errorText.Append(", Column ");
errorText.Append(aError->colNumber, 10);
+ errorText.Append(":");
+ }
+
+ aErrorString = errorText;
+
+ return NS_OK;
+}
+
+nsresult nsXMLContentSink::CreateSourceText(const nsParserError* aError, nsString& aSourceString)
+{
+ nsString sourceText;
+ PRInt32 errorPosition = aError->colNumber;
+
+ sourceText.Append(aError->sourceLine);
+ sourceText.Append("\n");
+ for (int i = 0; i < errorPosition - 1; i++)
+ sourceText.Append("-");
+ sourceText.Append("^");
+
+ aSourceString = sourceText;
+
+ return NS_OK;
+}
+
+static void SetTextStringOnTextNode(const nsString& aTextString, nsIContent* aTextNode)
+{
+ nsITextContent* text = nsnull;
+ PRUnichar *tempUnicode = aTextString.ToNewUnicode();
+ static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
+
+ aTextNode->QueryInterface(kITextContentIID, (void**) &text);
+ text->SetText(tempUnicode, aTextString.Length(), PR_FALSE);
+ delete [] tempUnicode;
+ NS_RELEASE(text);
+}
+
+
+/*
+ * We create the following XML snippet programmatically and
+ * insert it into the content model:
+ *
+ *
+ * XML Error: "contents of aError->description"
+ * Line Number: "contents of aError->lineNumber"
+ *
+ * "Contents of aError->sourceLine"
+ * "^ pointing at the error location"
+ *
+ *
+ *
+ */
+NS_IMETHODIMP
+nsXMLContentSink::NotifyError(const nsParserError* aError)
+{
+ nsresult result = NS_OK;
+ nsAutoString parserErrorTag = "parsererror";
+ nsAutoString sourceTextTag = "sourcetext";
+ nsString errorText;
+ nsString sourceText;
+ nsIHTMLContent* errorContainerNode = nsnull;
+ nsIHTMLContent* sourceContainerNode = nsnull;
+ nsIContent* errorTextNode = nsnull;
+ nsIContent* sourceTextNode = nsnull;
+
+ /* Create container and text content nodes */
+ result = NS_CreateHTMLElement(&errorContainerNode, parserErrorTag);
+ if (NS_OK == result) {
+ result = NS_NewTextNode(&errorTextNode);
+ if (NS_OK == result) {
+ result = NS_CreateHTMLElement(&sourceContainerNode, sourceTextTag);
+ if (NS_OK == result) {
+ result = NS_NewTextNode(&sourceTextNode);
+ }
+ }
}
- AddText(errorText);
- FlushText();
- return NS_OK;
+ /* Create the error text string and source text string
+ and set the text strings into the text nodes. */
+ result = CreateErrorText(aError, errorText);
+ if (NS_OK == result) {
+ SetTextStringOnTextNode(errorText, errorTextNode);
+ }
+
+ result = CreateSourceText(aError, sourceText);
+ if (NS_OK == result) {
+ SetTextStringOnTextNode(sourceText, sourceTextNode);
+ }
+
+ /* Hook the content nodes up to the document and to each other */
+ if (NS_OK == result) {
+ errorContainerNode->SetDocument(mDocument, PR_FALSE);
+ errorTextNode->SetDocument(mDocument, PR_FALSE);
+ sourceContainerNode->SetDocument(mDocument, PR_FALSE);
+ sourceTextNode->SetDocument(mDocument, PR_FALSE);
+
+ if (nsnull == mDocElement) {
+ mDocElement = errorContainerNode;
+ NS_ADDREF(mDocElement);
+ mDocument->SetRootContent(mDocElement);
+ }
+ else {
+ mDocElement->AppendChildTo(errorContainerNode, PR_FALSE);
+ }
+ errorContainerNode->AppendChildTo(errorTextNode, PR_FALSE);
+ errorContainerNode->AppendChildTo(sourceContainerNode, PR_FALSE);
+ sourceContainerNode->AppendChildTo(sourceTextNode, PR_FALSE);
+ }
+
+ return result;
}
// nsIXMLContentSink
diff --git a/mozilla/layout/xml/document/src/nsXMLContentSink.h b/mozilla/layout/xml/document/src/nsXMLContentSink.h
index f9a820ffeb1..ee2c0f97655 100644
--- a/mozilla/layout/xml/document/src/nsXMLContentSink.h
+++ b/mozilla/layout/xml/document/src/nsXMLContentSink.h
@@ -121,6 +121,8 @@ protected:
#endif
nsresult AddText(const nsString& aString);
+ nsresult CreateErrorText(const nsParserError* aError, nsString& aErrorString);
+ nsresult CreateSourceText(const nsParserError* aError, nsString& aSourceString);
nsIDocument* mDocument;
nsIURL* mDocumentURL;