nsresult rv;    if (aFormatType == "text/plain") { PRBool docEmpty; rv = GetDocumentIsEmpty(&docEmpty); if (NS_FAILED(rv)) return rv;  if (docEmpty) return NS_OK; }  nsCOMPtr<nsIDocumentEncoder> encoder; char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1); if (! progid) return NS_ERROR_OUT_OF_MEMORY;  strcpy(progid, NS_DOC_ENCODER_PROGID_BASE); char* type = aFormatType.ToNewCString(); strcat(progid, type); nsCRT::free(type); rv = nsComponentManager::CreateInstance(progid, nsnull, NS_GET_IID(nsIDocumentEncoder), getter_AddRefs(encoder));  nsCRT::free(progid); if (NS_FAILED(rv)) { printf("Couldn't get progid %s\n", progid); return rv; }  nsCOMPtr<nsIDOMDocument> domdoc; rv = GetDocument(getter_AddRefs(domdoc)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);  if (aCharset && aCharset->Length() != 0 && aCharset->Equals("null")==PR_FALSE) encoder->SetCharset(*aCharset);  rv = encoder->Init(doc, aFormatType, aFlags); if (NS_FAILED(rv)) return rv;   if (aFlags & nsIDocumentEncoder::OutputSelectionOnly) { nsCOMPtr<nsIDOMSelection> selection; rv = GetSelection(getter_AddRefs(selection)); if (NS_SUCCEEDED(rv) && selection) encoder->SetSelection(selection); }     PRInt32 wrapColumn; if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn))) { if (wrapColumn != 0) { PRUint32 wc; if (wrapColumn < 0) wc = 0; else wc = (PRUint32)wrapColumn; if (wrapColumn > 0) (void)encoder->SetWrapColumn(wc); } }  return encoder->EncodeToStream(aOutputStream);
return nsTextEditor::OutputToStream(aOutputStream, aFormatType, aCharset, aFlags);
NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,                                           const nsString& aFormatType,                                           const nsString* aCharset,                                           PRUint32 aFlags){  nsresult rv;  // special-case for empty document when requesting plain text,  // to account for the bogus text node  if (aFormatType == "text/plain")  {    PRBool docEmpty;    rv = GetDocumentIsEmpty(&docEmpty);    if (NS_FAILED(rv)) return rv;        if (docEmpty)       return NS_OK;    // output nothing  }  nsCOMPtr<nsIDocumentEncoder> encoder;  char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1);  if (! progid)      return NS_ERROR_OUT_OF_MEMORY;  strcpy(progid, NS_DOC_ENCODER_PROGID_BASE);  char* type = aFormatType.ToNewCString();  strcat(progid, type);  nsCRT::free(type);  rv = nsComponentManager::CreateInstance(progid,                                          nsnull,                                          NS_GET_IID(nsIDocumentEncoder),                                          getter_AddRefs(encoder));  nsCRT::free(progid);  if (NS_FAILED(rv))  {    printf("Couldn't get progid %s\n", progid);    return rv;  }  nsCOMPtr<nsIDOMDocument> domdoc;  rv = GetDocument(getter_AddRefs(domdoc));  if (NS_FAILED(rv))    return rv;  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);  if (aCharset && aCharset->Length() != 0 && aCharset->Equals("null")==PR_FALSE)    encoder->SetCharset(*aCharset);    rv = encoder->Init(doc, aFormatType, aFlags);    if (NS_FAILED(rv))      return rv;  // Set the selection, if appropriate:  if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)  {    nsCOMPtr<nsIDOMSelection> selection;    rv = GetSelection(getter_AddRefs(selection));    if (NS_SUCCEEDED(rv) && selection)      encoder->SetSelection(selection);  }      // Set the wrap column.  If our wrap column is 0,  // i.e. wrap to body width, then don't set it, let the  // document encoder use its own default.  PRInt32 wrapColumn;  if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))  {    if (wrapColumn != 0)    {      PRUint32 wc;      if (wrapColumn < 0)        wc = 0;      else        wc = (PRUint32)wrapColumn;      if (wrapColumn > 0)        (void)encoder->SetWrapColumn(wc);    }  }  return encoder->EncodeToStream(aOutputStream);}