~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/webservices/soap/src/nsSOAPEncoding.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2001
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the NPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the NPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#include "nsString.h"
 
40
#include "nsISOAPParameter.h"
 
41
#include "nsSOAPMessage.h"
 
42
#include "nsISOAPEncoder.h"
 
43
#include "nsISOAPDecoder.h"
 
44
#include "nsSOAPEncoding.h"
 
45
#include "nsSOAPUtils.h"
 
46
#include "nsSOAPException.h"
 
47
#include "nsIServiceManager.h"
 
48
#include "nsIComponentManager.h"
 
49
#include "nsIDOMNodeList.h"
 
50
#include "nsISchema.h"
 
51
#include "nsISchemaLoader.h"
 
52
#include "nsSOAPUtils.h"
 
53
 
 
54
//
 
55
// callback for deleting the encodings from the nsObjectHashtable, mEncodings,
 
56
//   in the nsSOAPEncodingRegistry
 
57
//
 
58
static PRBool PR_CALLBACK
 
59
DeleteEncodingEntry(nsHashKey *aKey, void *aData, void *aClosure)
 
60
{
 
61
  NS_DELETEXPCOM((nsSOAPEncoding*)aData);
 
62
  return PR_TRUE;
 
63
}
 
64
 
 
65
//
 
66
//  First the registry, which is shared between associated encodings 
 
67
//    but is never seen by xpconnect.
 
68
//
 
69
 
 
70
NS_IMPL_ISUPPORTS1(nsSOAPEncodingRegistry, nsISOAPEncodingRegistry)
 
71
 
 
72
nsSOAPEncodingRegistry::nsSOAPEncodingRegistry(nsISOAPEncoding *aEncoding)
 
73
: mEncodings(nsnull, nsnull, DeleteEncodingEntry, nsnull, 4)
 
74
{
 
75
  nsAutoString style;
 
76
  aEncoding->GetStyleURI(style);
 
77
  NS_ASSERTION(!style.IsEmpty(), "nsSOAPEncoding Regsitry constructed without style");
 
78
 
 
79
  nsStringKey styleKey(style);
 
80
  mEncodings.Put(&styleKey, aEncoding);
 
81
}
 
82
 
 
83
nsresult
 
84
nsSOAPEncodingRegistry::GetAssociatedEncoding(const nsAString & aStyleURI,
 
85
                                              PRBool aCreateIf,
 
86
                                              nsISOAPEncoding **aEncoding)
 
87
{
 
88
  NS_SOAP_ENSURE_ARG_STRING(aStyleURI);
 
89
  NS_ENSURE_ARG_POINTER(aEncoding);
 
90
 
 
91
  nsStringKey styleKey(aStyleURI);
 
92
  *aEncoding = (nsISOAPEncoding *) mEncodings.Get(&styleKey);
 
93
  if (!*aEncoding) {
 
94
    nsCOMPtr < nsISOAPEncoding > defaultEncoding;
 
95
    nsCAutoString encodingContractid;
 
96
    encodingContractid.Assign(NS_SOAPENCODING_CONTRACTID_PREFIX);
 
97
    encodingContractid.Append(NS_ConvertUCS2toUTF8(aStyleURI));
 
98
    defaultEncoding = do_GetService(encodingContractid.get());
 
99
    if (defaultEncoding || aCreateIf) {
 
100
      nsCOMPtr < nsISOAPEncoding > encoding = new nsSOAPEncoding(aStyleURI,this,defaultEncoding);
 
101
      *aEncoding = encoding;
 
102
      if (encoding) {
 
103
        NS_ADDREF(*aEncoding);
 
104
        mEncodings.Put(&styleKey, encoding);
 
105
      }
 
106
      else {
 
107
        return NS_ERROR_FAILURE;
 
108
      }
 
109
    }
 
110
  }
 
111
  else {
 
112
    // need to AddRef the *-style pointer coming from mEncodings
 
113
    NS_ADDREF(*aEncoding);
 
114
  }
 
115
  return NS_OK;
 
116
}
 
117
 
 
118
nsresult
 
119
    nsSOAPEncodingRegistry::SetSchemaCollection(nsISchemaCollection *
 
120
                                                aSchemaCollection)
 
121
{
 
122
  NS_ENSURE_ARG(aSchemaCollection);
 
123
  mSchemaCollection = aSchemaCollection;
 
124
  return NS_OK;
 
125
}
 
126
 
 
127
nsresult
 
128
    nsSOAPEncodingRegistry::GetSchemaCollection(nsISchemaCollection **
 
129
                                                aSchemaCollection)
 
130
{
 
131
  NS_ENSURE_ARG_POINTER(aSchemaCollection);
 
132
  if (!mSchemaCollection) {
 
133
    nsresult rv;
 
134
    nsCOMPtr < nsISchemaLoader > loader =
 
135
        do_CreateInstance(NS_SCHEMALOADER_CONTRACTID, &rv);
 
136
    if (NS_FAILED(rv))
 
137
      return rv;
 
138
    mSchemaCollection = do_QueryInterface(loader);
 
139
    if (!mSchemaCollection)
 
140
      return NS_ERROR_FAILURE;
 
141
  }
 
142
  *aSchemaCollection = mSchemaCollection;
 
143
  NS_ADDREF(*aSchemaCollection);
 
144
  return NS_OK;
 
145
}
 
146
 
 
147
//
 
148
//  Second, the encodings themselves.
 
149
//
 
150
NS_IMPL_CI_INTERFACE_GETTER1(nsSOAPEncoding, nsISOAPEncoding)
 
151
NS_IMPL_QUERY_INTERFACE1_CI(nsSOAPEncoding, nsISOAPEncoding)
 
152
 
 
153
// Due to circular referencing with the registry we abdicate all ref counting
 
154
//   to the registry itself. When the registry reaches zero it destroys all
 
155
//   the encodings with itself.
 
156
NS_IMETHODIMP_(nsrefcnt) 
 
157
nsSOAPEncoding::AddRef(void)
 
158
{
 
159
  if(mRegistry)
 
160
    return mRegistry->AddRef();
 
161
  return 1;
 
162
}
 
163
 
 
164
NS_IMETHODIMP_(nsrefcnt) 
 
165
nsSOAPEncoding::Release()
 
166
{
 
167
  if(mRegistry)
 
168
    return mRegistry->Release();
 
169
  return 1;
 
170
}
 
171
 
 
172
nsSOAPEncoding::nsSOAPEncoding() : mEncoders(), 
 
173
                                   mDecoders(), 
 
174
                                   mMappedInternal(), 
 
175
                                   mMappedExternal()
 
176
{
 
177
  mStyleURI.Assign(gSOAPStrings->kSOAPEncURI11);
 
178
  mRegistry = new nsSOAPEncodingRegistry(this);
 
179
  mDefaultEncoding = do_GetService(NS_DEFAULTSOAPENCODING_1_1_CONTRACTID);
 
180
}
 
181
 
 
182
nsSOAPEncoding::nsSOAPEncoding(const nsAString & aStyleURI, 
 
183
                               nsSOAPEncodingRegistry * aRegistry, 
 
184
                               nsISOAPEncoding * aDefaultEncoding) 
 
185
                              : mEncoders(),
 
186
                                mDecoders(), 
 
187
                                mMappedInternal(), 
 
188
                                mMappedExternal()
 
189
{
 
190
  mStyleURI.Assign(aStyleURI);
 
191
  mRegistry = aRegistry;
 
192
  mDefaultEncoding = aDefaultEncoding;
 
193
}
 
194
 
 
195
nsresult
 
196
    nsSOAPEncoding::SetSchemaCollection(nsISchemaCollection *
 
197
                                        aSchemaCollection)
 
198
{
 
199
  NS_ENSURE_ARG(aSchemaCollection);
 
200
  if (!mRegistry)
 
201
    return NS_ERROR_FAILURE;
 
202
  return mRegistry->SetSchemaCollection(aSchemaCollection);
 
203
}
 
204
 
 
205
nsresult
 
206
    nsSOAPEncoding::GetSchemaCollection(nsISchemaCollection **
 
207
                                        aSchemaCollection)
 
208
{
 
209
  NS_ENSURE_ARG_POINTER(aSchemaCollection);
 
210
  if (!mRegistry)
 
211
    return NS_ERROR_FAILURE;
 
212
  return mRegistry->GetSchemaCollection(aSchemaCollection);
 
213
}
 
214
 
 
215
/* readonly attribute AString styleURI; */
 
216
NS_IMETHODIMP nsSOAPEncoding::GetStyleURI(nsAString & aStyleURI)
 
217
{
 
218
  NS_ENSURE_ARG_POINTER(&aStyleURI);
 
219
  aStyleURI.Assign(mStyleURI);
 
220
  return NS_OK;
 
221
}
 
222
 
 
223
/* nsISOAPEncoding getAssociatedEncoding (in AString aStyleURI, in boolean aCreateIf); */
 
224
NS_IMETHODIMP
 
225
    nsSOAPEncoding::GetAssociatedEncoding(const nsAString & aStyleURI,
 
226
                                          PRBool aCreateIf,
 
227
                                          nsISOAPEncoding ** _retval)
 
228
{
 
229
  NS_SOAP_ENSURE_ARG_STRING(aStyleURI);
 
230
  NS_ENSURE_ARG_POINTER(_retval);
 
231
  if (!mRegistry)
 
232
    return NS_ERROR_FAILURE;
 
233
  return mRegistry->GetAssociatedEncoding(aStyleURI, aCreateIf, _retval);
 
234
}
 
235
 
 
236
/* nsISOAPEncoder setEncoder (in AString aKey, in nsISOAPEncoder aEncoder); */
 
237
NS_IMETHODIMP
 
238
    nsSOAPEncoding::SetEncoder(const nsAString & aKey,
 
239
                               nsISOAPEncoder * aEncoder)
 
240
{
 
241
  NS_SOAP_ENSURE_ARG_STRING(aKey);
 
242
  NS_ENSURE_ARG(aEncoder);
 
243
  nsStringKey nameKey(aKey);
 
244
  if (aEncoder) {
 
245
    mEncoders.Put(&nameKey, aEncoder, nsnull);
 
246
  } else {
 
247
    mEncoders.Remove(&nameKey, nsnull);
 
248
  }
 
249
  return NS_OK;
 
250
}
 
251
 
 
252
/* nsISOAPEncoder getEncoder (in AString aKey); */
 
253
NS_IMETHODIMP
 
254
    nsSOAPEncoding::GetEncoder(const nsAString & aKey,
 
255
                               nsISOAPEncoder ** _retval)
 
256
{
 
257
  NS_SOAP_ENSURE_ARG_STRING(aKey);
 
258
  NS_ENSURE_ARG_POINTER(_retval);
 
259
  nsStringKey nameKey(aKey);
 
260
  *_retval = (nsISOAPEncoder *) mEncoders.Get(&nameKey);
 
261
  if (*_retval == nsnull && mDefaultEncoding) {
 
262
    return mDefaultEncoding->GetEncoder(aKey, _retval);
 
263
  }
 
264
  return NS_OK;
 
265
}
 
266
 
 
267
/* nsISOAPDecoder setDecoder (in AString aKey, in nsISOAPDecoder aDecoder); */
 
268
NS_IMETHODIMP
 
269
    nsSOAPEncoding::SetDecoder(const nsAString & aKey,
 
270
                               nsISOAPDecoder * aDecoder)
 
271
{
 
272
  NS_SOAP_ENSURE_ARG_STRING(aKey);
 
273
  NS_ENSURE_ARG(aDecoder);
 
274
  nsStringKey nameKey(aKey);
 
275
  if (aDecoder) {
 
276
    mDecoders.Put(&nameKey, aDecoder, nsnull);
 
277
  } else {
 
278
    mDecoders.Remove(&nameKey, nsnull);
 
279
  }
 
280
  return NS_OK;
 
281
}
 
282
 
 
283
/* nsISOAPDecoder getDecoder (in AString aKey); */
 
284
NS_IMETHODIMP
 
285
    nsSOAPEncoding::GetDecoder(const nsAString & aKey,
 
286
                               nsISOAPDecoder ** _retval)
 
287
{
 
288
  NS_SOAP_ENSURE_ARG_STRING(aKey);
 
289
  NS_ENSURE_ARG_POINTER(_retval);
 
290
  nsStringKey nameKey(aKey);
 
291
  *_retval = (nsISOAPDecoder *) mDecoders.Get(&nameKey);
 
292
  if (*_retval == nsnull && mDefaultEncoding) {
 
293
    return mDefaultEncoding->GetDecoder(aKey, _retval);
 
294
  }
 
295
  return NS_OK;
 
296
}
 
297
 
 
298
/* nsIDOMElement encode (in nsIVariant aSource, in AString aNamespaceURI, in AString aName, in nsISchemaType aSchemaType, in nsISOAPAttachments aAttachments, in nsIDOMElement aDestination); */
 
299
NS_IMETHODIMP
 
300
    nsSOAPEncoding::Encode(nsIVariant * aSource,
 
301
                           const nsAString & aNamespaceURI,
 
302
                           const nsAString & aName,
 
303
                           nsISchemaType * aSchemaType,
 
304
                           nsISOAPAttachments * aAttachments,
 
305
                           nsIDOMElement * aDestination,
 
306
                           nsIDOMElement ** _retval)
 
307
{
 
308
  NS_ENSURE_ARG(aSource);
 
309
  NS_ENSURE_ARG_POINTER(_retval);
 
310
 
 
311
  nsCOMPtr < nsISOAPEncoder > encoder;
 
312
  nsresult rv = GetDefaultEncoder(getter_AddRefs(encoder));
 
313
  if (NS_FAILED(rv))
 
314
    return rv;
 
315
  if (encoder) {
 
316
    return encoder->Encode(this, aSource, aNamespaceURI, aName,
 
317
                           aSchemaType, aAttachments, aDestination,
 
318
                           _retval);
 
319
  }
 
320
  *_retval = nsnull;
 
321
  return SOAP_EXCEPTION(NS_ERROR_NOT_IMPLEMENTED,"SOAP_DEFAULT_ENCODER", "Encoding style does not have a default encoder.");
 
322
}
 
323
 
 
324
/* nsIVariant decode (in nsIDOMElement aSource, in nsISchemaType aSchemaType, in nsISOAPAttachments aAttachments); */
 
325
NS_IMETHODIMP
 
326
    nsSOAPEncoding::Decode(nsIDOMElement * aSource,
 
327
                           nsISchemaType * aSchemaType,
 
328
                           nsISOAPAttachments * aAttachments,
 
329
                           nsIVariant ** _retval)
 
330
{
 
331
  NS_ENSURE_ARG(aSource);
 
332
  NS_ENSURE_ARG_POINTER(_retval);
 
333
  nsCOMPtr < nsISOAPDecoder > decoder;
 
334
  nsresult rv = GetDefaultDecoder(getter_AddRefs(decoder));
 
335
  if (NS_FAILED(rv))
 
336
    return rv;
 
337
  if (decoder) {
 
338
    return decoder->Decode(this, aSource, aSchemaType, aAttachments,
 
339
                           _retval);
 
340
  }
 
341
  *_retval = nsnull;
 
342
  return SOAP_EXCEPTION(NS_ERROR_NOT_IMPLEMENTED,"SOAP_DEFAULT_ENCODER", "Encoding style does not have a default decoder.");
 
343
}
 
344
 
 
345
/* attribute nsISOAPEncoder defaultEncoder; */
 
346
NS_IMETHODIMP
 
347
    nsSOAPEncoding::GetDefaultEncoder(nsISOAPEncoder * *aDefaultEncoder)
 
348
{
 
349
  NS_ENSURE_ARG_POINTER(aDefaultEncoder);
 
350
  if (mDefaultEncoding && !mDefaultEncoder) {
 
351
    return mDefaultEncoding->GetDefaultEncoder(aDefaultEncoder);
 
352
  }
 
353
  *aDefaultEncoder = mDefaultEncoder;
 
354
  NS_IF_ADDREF(*aDefaultEncoder);
 
355
  return NS_OK;
 
356
}
 
357
 
 
358
NS_IMETHODIMP
 
359
    nsSOAPEncoding::SetDefaultEncoder(nsISOAPEncoder * aDefaultEncoder)
 
360
{
 
361
  mDefaultEncoder = aDefaultEncoder;
 
362
  return NS_OK;
 
363
}
 
364
 
 
365
/* attribute nsISOAPDecoder defaultDecoder; */
 
366
NS_IMETHODIMP
 
367
    nsSOAPEncoding::GetDefaultDecoder(nsISOAPDecoder * *aDefaultDecoder)
 
368
{
 
369
  NS_ENSURE_ARG_POINTER(aDefaultDecoder);
 
370
  if (mDefaultEncoding && !mDefaultDecoder) {
 
371
    return mDefaultEncoding->GetDefaultDecoder(aDefaultDecoder);
 
372
  }
 
373
  *aDefaultDecoder = mDefaultDecoder;
 
374
  NS_IF_ADDREF(*aDefaultDecoder);
 
375
  return NS_OK;
 
376
}
 
377
 
 
378
NS_IMETHODIMP
 
379
    nsSOAPEncoding::SetDefaultDecoder(nsISOAPDecoder * aDefaultDecoder)
 
380
{
 
381
  mDefaultDecoder = aDefaultDecoder;
 
382
  return NS_OK;
 
383
}
 
384
 
 
385
NS_IMETHODIMP
 
386
nsSOAPEncoding::MapSchemaURI(const nsAString & aExternalURI, 
 
387
                             const nsAString & aInternalURI, 
 
388
                             PRBool aOutput, 
 
389
                             PRBool *_retval)
 
390
{
 
391
  NS_ENSURE_ARG_POINTER(&aExternalURI);
 
392
  NS_ENSURE_ARG_POINTER(&aInternalURI);
 
393
  if (aExternalURI.IsEmpty() || aInternalURI.IsEmpty())  //  Permit no empty URIs.
 
394
    return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_SCHEMA_URI_MAPPING", "No schema URI mapping possible of empty strings.");
 
395
  nsStringKey externalKey(aExternalURI);
 
396
  if (mMappedExternal.Exists(&externalKey)) {
 
397
    *_retval = PR_FALSE;  //  Do not permit duplicate external
 
398
    return NS_OK;
 
399
  }
 
400
  if (aOutput) {
 
401
    nsStringKey internalKey(aInternalURI);
 
402
    if (mMappedInternal.Exists(&internalKey)) {
 
403
      *_retval = PR_FALSE;  //  Do not permit duplicate internal
 
404
      return NS_OK;
 
405
    }
 
406
    nsresult rc;
 
407
    nsCOMPtr < nsIWritableVariant > p =
 
408
        do_CreateInstance(NS_VARIANT_CONTRACTID, &rc);
 
409
    if (NS_FAILED(rc))
 
410
      return rc;
 
411
    p->SetAsAString(aExternalURI);
 
412
    if (NS_FAILED(rc))
 
413
      return rc;
 
414
    mMappedInternal.Put(&internalKey, p);
 
415
  }
 
416
  nsresult rc;
 
417
  nsCOMPtr < nsIWritableVariant > p =
 
418
      do_CreateInstance(NS_VARIANT_CONTRACTID, &rc);
 
419
  if (NS_FAILED(rc))
 
420
    return rc;
 
421
  p->SetAsAString(aInternalURI);
 
422
  if (NS_FAILED(rc))
 
423
    return rc;
 
424
  mMappedExternal.Put(&externalKey, p);
 
425
  if (_retval)
 
426
    *_retval = PR_TRUE;
 
427
  return NS_OK;
 
428
}
 
429
 
 
430
/* boolean unmapSchemaURI (in AString aExternalURI); */
 
431
NS_IMETHODIMP nsSOAPEncoding::UnmapSchemaURI(const nsAString & aExternalURI, PRBool *_retval)
 
432
{
 
433
  NS_ENSURE_ARG_POINTER(&aExternalURI);
 
434
  nsStringKey externalKey(aExternalURI);
 
435
  nsCOMPtr<nsIVariant> internal = dont_AddRef(NS_STATIC_CAST(nsIVariant*,mMappedExternal.Get(&externalKey)));
 
436
  if (internal) {
 
437
    nsAutoString internalstr;
 
438
    nsresult rc = internal->GetAsAString(internalstr);
 
439
    if (NS_FAILED(rc))
 
440
      return rc;
 
441
    nsStringKey internalKey(internalstr);
 
442
    mMappedExternal.Remove(&externalKey);
 
443
    mMappedInternal.Remove(&internalKey);
 
444
    if (_retval)
 
445
      *_retval = PR_TRUE;
 
446
  }
 
447
  else {
 
448
    if (_retval)
 
449
      *_retval = PR_FALSE;
 
450
  }
 
451
  return NS_OK;
 
452
}
 
453
 
 
454
/* AString getInternalSchemaURI (in AString aExternalURI); */
 
455
NS_IMETHODIMP nsSOAPEncoding::GetInternalSchemaURI(const nsAString & aExternalURI, nsAString & _retval)
 
456
{
 
457
  NS_ENSURE_ARG_POINTER(&aExternalURI);
 
458
  NS_ENSURE_ARG_POINTER(&_retval);
 
459
  if (mMappedExternal.Count()) {
 
460
    nsStringKey externalKey(aExternalURI);
 
461
    nsCOMPtr<nsIVariant> internal = dont_AddRef(NS_STATIC_CAST(nsIVariant*,mMappedExternal.Get(&externalKey)));
 
462
    if (internal) {
 
463
      return internal->GetAsAString(_retval);
 
464
    }
 
465
  }
 
466
  if (mDefaultEncoding) {
 
467
    return mDefaultEncoding->GetInternalSchemaURI(aExternalURI, _retval);
 
468
  }
 
469
  _retval.Assign(aExternalURI);
 
470
  return NS_OK;
 
471
}
 
472
 
 
473
/* AString getExternalSchemaURI (in AString aInternalURI); */
 
474
NS_IMETHODIMP nsSOAPEncoding::GetExternalSchemaURI(const nsAString & aInternalURI, nsAString & _retval)
 
475
{
 
476
  NS_ENSURE_ARG_POINTER(&aInternalURI);
 
477
  NS_ENSURE_ARG_POINTER(&_retval);
 
478
  if (mMappedInternal.Count()) {
 
479
    nsStringKey internalKey(aInternalURI);
 
480
    nsCOMPtr<nsIVariant> external = dont_AddRef(NS_STATIC_CAST(nsIVariant*,mMappedInternal.Get(&internalKey)));
 
481
    if (external) {
 
482
      return external->GetAsAString(_retval);
 
483
    }
 
484
  }
 
485
  if (mDefaultEncoding) {
 
486
    return mDefaultEncoding->GetExternalSchemaURI(aInternalURI, _retval);
 
487
  }
 
488
  _retval.Assign(aInternalURI);
 
489
  return NS_OK;
 
490
}