Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
rdfcat.cpp File Reference
#include <stdio.h>
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIEventQueueService.h"
#include "nsIIOService.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLSource.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsRDFCID.h"
#include "plevent.h"
#include "plstr.h"
#include "prio.h"
#include "prthread.h"

Go to the source code of this file.

Classes

class  ConsoleOutputStreamImpl

Defines

#define RETURN_IF_FAILED(rv, step)

Functions

static NS_DEFINE_CID (kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID)
static NS_DEFINE_CID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
int main (int argc, char **argv)
 The Xalan testcases app.

Define Documentation

#define RETURN_IF_FAILED (   rv,
  step 
)
Value:
PR_BEGIN_MACRO \
    if (NS_FAILED(rv)) { \
        printf(">>> %s failed: rv=%x\n", step, rv); \
        return rv;\
    } \
    PR_END_MACRO

Definition at line 82 of file rdfcat.cpp.


Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 142 of file rdfcat.cpp.

{
    nsresult rv;

    if (argc < 2) {
        fprintf(stderr, "usage: %s <url>\n", argv[0]);
        return 1;
    }

    NS_InitXPCOM2(nsnull, nsnull, nsnull);

    // Get netlib off the floor...
    nsCOMPtr<nsIEventQueueService> theEventQueueService = 
             do_GetService(kEventQueueServiceCID, &rv);
    RETURN_IF_FAILED(rv, "EventQueueService");

    nsIEventQueue* eq = nsnull;
    rv = theEventQueueService->GetThreadEventQueue(NS_CURRENT_THREAD, &eq);
    RETURN_IF_FAILED(rv, "GetThreadEventQueue");

    // Create a stream data source and initialize it on argv[1], which
    // is hopefully a "file:" URL.
    nsCOMPtr<nsIRDFDataSource> ds = do_CreateInstance(kRDFXMLDataSourceCID,
                                                      &rv);
    RETURN_IF_FAILED(rv, "RDF/XML datasource creation");

    nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds, &rv);
    RETURN_IF_FAILED(rv, "QI to nsIRDFRemoteDataSource");

    rv = remote->Init(argv[1]);
    RETURN_IF_FAILED(rv, "datasource initialization");

    // Okay, this should load the XML file...
    rv = remote->Refresh(PR_FALSE);
    RETURN_IF_FAILED(rv, "datasource refresh");

    // Pump events until the load is finished
    PRBool done = PR_FALSE;
    while (!done) {
        eq->ProcessPendingEvents();
        remote->GetLoaded(&done);
    }

    // And this should write it back out. The do_QI() on the pointer
    // is a hack to make sure that the new object gets AddRef()-ed.
    nsCOMPtr<nsIOutputStream> out =
        do_QueryInterface(new ConsoleOutputStreamImpl, &rv);
    RETURN_IF_FAILED(rv, "creation of console output stream");

    nsCOMPtr<nsIRDFXMLSource> source = do_QueryInterface(ds);
    RETURN_IF_FAILED(rv, "QI to nsIRDFXMLSource");

    rv = source->Serialize(out);
    RETURN_IF_FAILED(rv, "datasoure serialization");

    theEventQueueService->DestroyThreadEventQueue();

    return NS_OK;
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kRDFXMLDataSourceCID  ,
NS_RDFXMLDATASOURCE_CID   
) [static]