Back to index

lightning-sunbird  0.9+nobinonly
Classes | Enumerations | Functions
nsDocumentEncoder.cpp File Reference
#include "nsIDocumentEncoder.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIDocument.h"
#include "nsIHTMLDocument.h"
#include "nsISelection.h"
#include "nsCOMPtr.h"
#include "nsIContentSerializer.h"
#include "nsIUnicodeEncoder.h"
#include "nsIOutputStream.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMComment.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMRange.h"
#include "nsIDOMDocument.h"
#include "nsICharsetConverterManager.h"
#include "nsHTMLAtoms.h"
#include "nsITextContent.h"
#include "nsIEnumerator.h"
#include "nsISelectionPrivate.h"
#include "nsIFrameSelection.h"
#include "nsISupportsArray.h"
#include "nsIParserService.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptSecurityManager.h"
#include "nsContentUtils.h"
#include "nsUnicharUtils.h"
#include "nsReadableUtils.h"

Go to the source code of this file.

Classes

class  nsDocumentEncoder
class  nsHTMLCopyEncoder

Enumerations

enum  nsRangeIterationDirection { kDirectionOut = -1, kDirectionIn = 1 }

Functions

nsresult NS_NewDomSelection (nsISelection **aDomSelection)
static nsresult ConvertAndWrite (const nsAString &aString, nsIOutputStream *aStream, nsIUnicodeEncoder *aEncoder)
static PRBool IsTextNode (nsIDOMNode *aNode)
static nsresult GetLengthOfDOMNode (nsIDOMNode *aNode, PRUint32 &aCount)
nsresult NS_NewTextEncoder (nsIDocumentEncoder **aResult)
nsresult NS_NewHTMLCopyTextEncoder (nsIDocumentEncoder **aResult)

Enumeration Type Documentation

Enumerator:
kDirectionOut 
kDirectionIn 

Definition at line 79 of file nsDocumentEncoder.cpp.

                               {
  kDirectionOut = -1,
  kDirectionIn = 1
};

Function Documentation

static nsresult ConvertAndWrite ( const nsAString &  aString,
nsIOutputStream aStream,
nsIUnicodeEncoder aEncoder 
) [static]

Definition at line 404 of file nsDocumentEncoder.cpp.

{
  NS_ENSURE_ARG_POINTER(aStream);
  NS_ENSURE_ARG_POINTER(aEncoder);
  nsresult rv;
  PRInt32 charLength, startCharLength;
  const nsPromiseFlatString& flat = PromiseFlatString(aString);
  const PRUnichar* unicodeBuf = flat.get();
  PRInt32 unicodeLength = aString.Length();
  PRInt32 startLength = unicodeLength;

  rv = aEncoder->GetMaxLength(unicodeBuf, unicodeLength, &charLength);
  startCharLength = charLength;
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString charXferString;
  if (!EnsureStringLength(charXferString, charLength))
    return NS_ERROR_OUT_OF_MEMORY;

  char* charXferBuf = charXferString.BeginWriting();
  nsresult convert_rv = NS_OK;

  do {
    unicodeLength = startLength;
    charLength = startCharLength;

    convert_rv = aEncoder->Convert(unicodeBuf, &unicodeLength, charXferBuf, &charLength);
    NS_ENSURE_SUCCESS(convert_rv, convert_rv);

    // Make sure charXferBuf is null-terminated before we call
    // Write().

    charXferBuf[charLength] = '\0';

    PRUint32 written;
    rv = aStream->Write(charXferBuf, charLength, &written);
    NS_ENSURE_SUCCESS(rv, rv);

    // If the converter couldn't convert a chraacer we replace the
    // character with a characre entity.
    if (convert_rv == NS_ERROR_UENC_NOMAPPING) {
      // Finishes the conversion. 
      // The converter has the possibility to write some extra data and flush its final state.
      char finish_buf[33];
      charLength = sizeof(finish_buf) - 1;
      rv = aEncoder->Finish(finish_buf, &charLength);
      NS_ENSURE_SUCCESS(rv, rv);

      // Make sure finish_buf is null-terminated before we call
      // Write().

      finish_buf[charLength] = '\0';

      rv = aStream->Write(finish_buf, charLength, &written);
      NS_ENSURE_SUCCESS(rv, rv);

      nsCAutoString entString("&#");
      if (IS_HIGH_SURROGATE(unicodeBuf[unicodeLength - 1]) && 
          unicodeLength < startLength && IS_LOW_SURROGATE(unicodeBuf[unicodeLength]))  {
        entString.AppendInt(SURROGATE_TO_UCS4(unicodeBuf[unicodeLength - 1],
                                              unicodeBuf[unicodeLength]));
        unicodeLength += 1;
      }
      else
        entString.AppendInt(unicodeBuf[unicodeLength - 1]);
      entString.Append(';');

      // Since entString is an nsCAutoString we know entString.get()
      // returns a null-terminated string, so no need for extra
      // null-termination before calling Write() here.

      rv = aStream->Write(entString.get(), entString.Length(), &written);
      NS_ENSURE_SUCCESS(rv, rv);

      unicodeBuf += unicodeLength;
      startLength -= unicodeLength;
    }
  } while (convert_rv == NS_ERROR_UENC_NOMAPPING);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult GetLengthOfDOMNode ( nsIDOMNode aNode,
PRUint32 aCount 
) [static]

Definition at line 622 of file nsDocumentEncoder.cpp.

{
  aCount = 0;
  if (!aNode) { return NS_ERROR_NULL_POINTER; }
  nsresult result=NS_OK;
  nsCOMPtr<nsIDOMCharacterData>nodeAsChar;
  nodeAsChar = do_QueryInterface(aNode);
  if (nodeAsChar) {
    nodeAsChar->GetLength(&aCount);
  }
  else
  {
    PRBool hasChildNodes;
    aNode->HasChildNodes(&hasChildNodes);
    if (PR_TRUE==hasChildNodes)
    {
      nsCOMPtr<nsIDOMNodeList>nodeList;
      result = aNode->GetChildNodes(getter_AddRefs(nodeList));
      if (NS_SUCCEEDED(result) && nodeList) {
        nodeList->GetLength(&aCount);
      }
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool IsTextNode ( nsIDOMNode aNode) [static]

Definition at line 611 of file nsDocumentEncoder.cpp.

{
  if (!aNode) return PR_FALSE;
  PRUint16 nodeType;
  aNode->GetNodeType(&nodeType);
  if (nodeType == nsIDOMNode::TEXT_NODE ||
      nodeType == nsIDOMNode::CDATA_SECTION_NODE)
    return PR_TRUE;
  return PR_FALSE;
}

Here is the caller graph for this function:

nsresult NS_NewDomSelection ( nsISelection **  aDomSelection)

Definition at line 743 of file nsSelection.cpp.

{
  nsTypedSelection *rlist = new nsTypedSelection;
  if (!rlist)
    return NS_ERROR_OUT_OF_MEMORY;
  *aDomSelection = (nsISelection *)rlist;
  NS_ADDREF(rlist);
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 1763 of file nsDocumentEncoder.cpp.

{
  *aResult = new nsHTMLCopyEncoder;
  if (!*aResult)
    return NS_ERROR_OUT_OF_MEMORY;
 NS_ADDREF(*aResult);
 return NS_OK;
}

Here is the call graph for this function:

Definition at line 1004 of file nsDocumentEncoder.cpp.

{
  *aResult = new nsDocumentEncoder;
  if (!*aResult)
    return NS_ERROR_OUT_OF_MEMORY;
 NS_ADDREF(*aResult);
 return NS_OK;
}

Here is the call graph for this function: