Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsRDFXMLDataSource.cpp File Reference
#include "nsIFileStreams.h"
#include "nsIOutputStream.h"
#include "nsIFile.h"
#include "nsIFileChannel.h"
#include "nsIDTD.h"
#include "nsIRDFPurgeableDataSource.h"
#include "nsIInputStream.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFNode.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLParser.h"
#include "nsIRDFXMLSerializer.h"
#include "nsIRDFXMLSink.h"
#include "nsIRDFXMLSource.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsIFileURL.h"
#include "nsNetUtil.h"
#include "nsIChannel.h"
#include "nsRDFCID.h"
#include "nsRDFBaseDataSources.h"
#include "nsCOMArray.h"
#include "nsXPIDLString.h"
#include "plstr.h"
#include "prio.h"
#include "prthread.h"
#include "rdf.h"
#include "rdfutil.h"
#include "prlog.h"
#include "nsNameSpaceMap.h"
#include "nsCRT.h"
#include "rdfIDataSource.h"
#include "nsITimelineService.h"

Go to the source code of this file.

Classes

class  ProxyStream
class  RDFXMLDataSourceImpl

Functions

static NS_DEFINE_CID (kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID)
static NS_DEFINE_CID (kRDFServiceCID, NS_RDFSERVICE_CID)
nsresult NS_NewRDFXMLDataSource (nsIRDFDataSource **aResult)
 NS_IMPL_ISUPPORTS7 (RDFXMLDataSourceImpl, nsIRDFDataSource, nsIRDFRemoteDataSource, nsIRDFXMLSink, nsIRDFXMLSource, nsIRequestObserver, nsIStreamListener, rdfIDataSource) nsresult RDFXMLDataSourceImpl

Variables

static const char kFileURIPrefix [] = "file:"
static const char kResourceURIPrefix [] = "resource:"

Function Documentation

static NS_DEFINE_CID ( kRDFInMemoryDataSourceCID  ,
NS_RDFINMEMORYDATASOURCE_CID   
) [static]
static NS_DEFINE_CID ( kRDFServiceCID  ,
NS_RDFSERVICE_CID   
) [static]

Definition at line 540 of file nsRDFXMLDataSource.cpp.

{
    nsresult rv;

    // XXX I really hate the way that we're spoon-feeding this stuff
    // to the parser: it seems like this is something that netlib
    // should be able to do by itself.
    
    nsCOMPtr<nsIChannel> channel;
    nsCOMPtr<nsIRequest> request;

    // Null LoadGroup ?
    rv = NS_NewChannel(getter_AddRefs(channel), aURL, nsnull);
    if (NS_FAILED(rv)) return rv;
    nsIInputStream* in;
    PRUint32 sourceOffset = 0;
    rv = channel->Open(&in);

    // Report success if the file doesn't exist, but propagate other errors.
    if (rv == NS_ERROR_FILE_NOT_FOUND) return NS_OK;
    if (NS_FAILED(rv)) return rv;

    NS_ASSERTION(in != nsnull, "no input stream");
    if (! in) return NS_ERROR_FAILURE;

    rv = NS_ERROR_OUT_OF_MEMORY;
    ProxyStream* proxy = new ProxyStream();
    if (! proxy)
        goto done;

    // Notify load observers
    PRInt32 i;
    for (i = mObservers.Count() - 1; i >= 0; --i) {
        // Make sure to hold a strong reference to the observer so
        // that it doesn't go away in this call if it removes itself
        // as an observer
        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];

        if (obs) {
            obs->OnBeginLoad(this);
        }
    }

    request = do_QueryInterface(channel);

    aConsumer->OnStartRequest(request, nsnull);
    while (PR_TRUE) {
        char buf[4096];
        PRUint32 readCount;

        if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))
            break; // error

        if (readCount == 0)
            break; // eof

        proxy->SetBuffer(buf, readCount);

        rv = aConsumer->OnDataAvailable(request, nsnull, proxy, sourceOffset, readCount);
        sourceOffset += readCount;
        if (NS_FAILED(rv))
            break;
    }

    aConsumer->OnStopRequest(channel, nsnull, rv);

    // Notify load observers
    for (i = mObservers.Count() - 1; i >= 0; --i) {
        // Make sure to hold a strong reference to the observer so
        // that it doesn't go away in this call if it removes itself
        // as an observer
        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];

        if (obs) {
            if (NS_FAILED(rv))
                obs->OnError(this, rv, nsnull);

            obs->OnEndLoad(this);
        }
    }

       // don't leak proxy!
       proxy->Close();
       delete proxy;
       proxy = nsnull;

done:
    NS_RELEASE(in);
    return rv;
}

Here is the call graph for this function:

Definition at line 465 of file nsRDFXMLDataSource.cpp.

{
    NS_PRECONDITION(aResult != nsnull, "null ptr");
    if (! aResult)
        return NS_ERROR_NULL_POINTER;

    RDFXMLDataSourceImpl* datasource = new RDFXMLDataSourceImpl();
    if (! datasource)
        return NS_ERROR_OUT_OF_MEMORY;

    nsresult rv;
    rv = datasource->Init();

    if (NS_FAILED(rv)) {
        delete datasource;
        return rv;
    }

    NS_ADDREF(datasource);
    *aResult = datasource;
    return NS_OK;
}

Here is the call graph for this function:


Variable Documentation

const char kFileURIPrefix[] = "file:" [static]

Definition at line 458 of file nsRDFXMLDataSource.cpp.

const char kResourceURIPrefix[] = "resource:" [static]

Definition at line 459 of file nsRDFXMLDataSource.cpp.