Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
triplescat.cpp File Reference
#include <stdio.h>
#include "nsXPCOM.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.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"
#include "rdf.h"
#include "rdfIDataSource.h"
#include "rdfITripleVisitor.h"
#include "rdfISerializer.h"

Go to the source code of this file.

Classes

class  ConsoleOutputStreamImpl

Defines

#define RETURN_IF_FAILED(rv, step)
 A simple test program that reads in RDF/XML into an in-memory data source, then serializes NTriples format back to stdout (or none).

Functions

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

A simple test program that reads in RDF/XML into an in-memory data source, then serializes NTriples format back to stdout (or none).

The program takes a single parameter: the URL from which to read, plus an optional parameter -q

Definition at line 80 of file triplescat.cpp.


Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 140 of file triplescat.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(NS_EVENTQUEUESERVICE_CONTRACTID, &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(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource",
                          &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);
    }

    nsCOMPtr<rdfIDataSource> rdfds = do_QueryInterface(ds, &rv);
    RETURN_IF_FAILED(rv, "QI to rdIDataSource");
    {
        nsCOMPtr<nsIOutputStream> out = new ConsoleOutputStreamImpl();
        nsCOMPtr<rdfISerializer> ser =
            do_CreateInstance(NS_RDF_SERIALIZER "ntriples", &rv);
        RETURN_IF_FAILED(rv, "Creation of NTriples Serializer");
        rv = ser->Serialize(rdfds, out);
        RETURN_IF_FAILED(rv, "Serialization to NTriples");
        out->Close();
    }

    theEventQueueService->DestroyThreadEventQueue();

    return NS_OK;
}

Here is the call graph for this function: