зеркало из https://github.com/mozilla/gecko-dev.git
bug 778777 - kill off most of rdf/tests/ irc-r=ted
This commit is contained in:
Родитель
edbbde54c3
Коммит
ffe70cba70
|
@ -4,6 +4,4 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
TEST_DIRS += ['rdfcat', 'rdfpoll', 'triplescat']
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
GeckoProgram('rdfcat', linkage='dependent')
|
||||
|
||||
SOURCES += [
|
||||
'rdfcat.cpp',
|
||||
]
|
||||
|
||||
CXXFLAGS += CONFIG['TK_CFLAGS']
|
|
@ -1,156 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
|
||||
A simple test program that reads in RDF/XML into an in-memory data
|
||||
source, then uses the RDF/XML serialization API to write an
|
||||
equivalent (but not identical) RDF/XML file back to stdout.
|
||||
|
||||
The program takes a single parameter: the URL from which to read.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.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 "nsThreadUtils.h"
|
||||
#include "plstr.h"
|
||||
#include "prio.h"
|
||||
#include "prthread.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// CIDs
|
||||
|
||||
// rdf
|
||||
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Blatantly stolen from netwerk/test/
|
||||
#define RETURN_IF_FAILED(rv, step) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_FAILED(rv)) { \
|
||||
printf(">>> %s failed: rv=%x\n", step, static_cast<uint32_t>(rv)); \
|
||||
return 1;\
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ConsoleOutputStreamImpl : public nsIOutputStream
|
||||
{
|
||||
protected:
|
||||
virtual ~ConsoleOutputStreamImpl(void) {}
|
||||
|
||||
public:
|
||||
ConsoleOutputStreamImpl(void) {}
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIOutputStream interface
|
||||
NS_IMETHOD Close(void) override {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD Write(const char* aBuf, uint32_t aCount, uint32_t *aWriteCount) override {
|
||||
PR_Write(PR_GetSpecialFD(PR_StandardOutput), aBuf, aCount);
|
||||
*aWriteCount = aCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
WriteFrom(nsIInputStream *inStr, uint32_t count, uint32_t *_retval) override {
|
||||
NS_NOTREACHED("WriteFrom");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
WriteSegments(nsReadSegmentFun reader, void * closure, uint32_t count, uint32_t *_retval) override {
|
||||
NS_NOTREACHED("WriteSegments");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
IsNonBlocking(bool *aNonBlocking) override {
|
||||
NS_NOTREACHED("IsNonBlocking");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) override {
|
||||
PR_Sync(PR_GetSpecialFD(PR_StandardOutput));
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, nsIOutputStream)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <url>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
|
||||
// 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(false);
|
||||
RETURN_IF_FAILED(rv, "datasource refresh");
|
||||
|
||||
// Pump events until the load is finished
|
||||
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
NS_ENSURE_TRUE(NS_ProcessNextEvent(thread), 1);
|
||||
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");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
GeckoProgram('rdfpoll', linkage='dependent')
|
||||
|
||||
SOURCES += [
|
||||
'rdfpoll.cpp',
|
||||
]
|
|
@ -1,272 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
|
||||
A simple test program that reads in RDF/XML into an in-memory data
|
||||
source, then periodically updates it. It prints the messages
|
||||
indicating assert and unassert activity to the console.
|
||||
|
||||
The program takes two parameters: the URL from which to read, and
|
||||
the poll-interval at which to re-load the .
|
||||
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFRemoteDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFXMLSource.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "prthread.h"
|
||||
#include "plstr.h"
|
||||
#include "nsEmbedString.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "prtime.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// CIDs
|
||||
|
||||
// rdf
|
||||
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// IIDs
|
||||
|
||||
|
||||
#include "nsIMemory.h" // for the CID
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Observer : public nsIRDFObserver
|
||||
{
|
||||
protected:
|
||||
virtual ~Observer() {}
|
||||
|
||||
public:
|
||||
Observer();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFObserver interface
|
||||
NS_DECL_NSIRDFOBSERVER
|
||||
};
|
||||
|
||||
Observer::Observer()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(Observer, nsIRDFObserver)
|
||||
|
||||
static nsresult
|
||||
rdf_WriteOp(const char* aOp,
|
||||
nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCString source;
|
||||
rv = aSource->GetValue(getter_Copies(source));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCString property;
|
||||
rv = aProperty->GetValue(getter_Copies(property));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
nsCOMPtr<nsIRDFLiteral> literal;
|
||||
nsCOMPtr<nsIRDFDate> date;
|
||||
nsCOMPtr<nsIRDFInt> number;
|
||||
|
||||
printf("%.8s [%s]\n", aOp, source.get());
|
||||
printf(" --[%s]--\n", property.get());
|
||||
|
||||
if ((resource = do_QueryInterface(aTarget)) != nullptr) {
|
||||
nsCString target;
|
||||
rv = resource->GetValue(getter_Copies(target));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
printf(" ->[%s]\n", target.get());
|
||||
}
|
||||
else if ((literal = do_QueryInterface(aTarget)) != nullptr) {
|
||||
nsString target;
|
||||
rv = literal->GetValue(getter_Copies(target));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
printf(" ->\"%s\"\n", NS_ConvertUTF16toUTF8(target).get());
|
||||
}
|
||||
else if ((date = do_QueryInterface(aTarget)) != nullptr) {
|
||||
PRTime value;
|
||||
date->GetValue(&value);
|
||||
|
||||
PRExplodedTime t;
|
||||
PR_ExplodeTime(value, PR_GMTParameters, &t);
|
||||
|
||||
printf(" -> %02d/%02d/%04d %02d:%02d:%02d +%06d\n",
|
||||
t.tm_month + 1,
|
||||
t.tm_mday,
|
||||
t.tm_year,
|
||||
t.tm_hour,
|
||||
t.tm_min,
|
||||
t.tm_sec,
|
||||
t.tm_usec);
|
||||
}
|
||||
else if ((number = do_QueryInterface(aTarget)) != nullptr) {
|
||||
int32_t value;
|
||||
number->GetValue(&value);
|
||||
|
||||
printf(" -> %d\n", value);
|
||||
}
|
||||
else {
|
||||
printf(" -> (unknown node type)\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Observer::OnAssert(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return rdf_WriteOp("assert", aSource, aProperty, aTarget);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
Observer::OnUnassert(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return rdf_WriteOp("unassert", aSource, aProperty, aTarget);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
Observer::OnChange(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aOldTarget,
|
||||
nsIRDFNode* aNewTarget)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_WriteOp("chg-from", aSource, aProperty, aOldTarget);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = rdf_WriteOp("chg-to", aSource, aProperty, aNewTarget);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Observer::OnMove(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aOldSource,
|
||||
nsIRDFResource* aNewSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_WriteOp("mv-from", aOldSource, aProperty, aTarget);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = rdf_WriteOp("mv-to", aNewSource, aProperty, aTarget);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Observer::OnBeginUpdateBatch(nsIRDFDataSource* aDataSource)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Observer::OnEndUpdateBatch(nsIRDFDataSource* aDataSource)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <url> [<poll-interval>]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv)) {
|
||||
fprintf(stderr, "NS_InitXPCOM2 failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a stream data source and initialize it on argv[1], which
|
||||
// is hopefully a "file:" URL. (Actually, we can do _any_ kind of
|
||||
// URL, but only a "file:" URL will be written back to disk.)
|
||||
nsCOMPtr<nsIRDFDataSource> ds = do_CreateInstance(kRDFXMLDataSourceCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("unable to create RDF/XML data source");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds);
|
||||
if (! remote)
|
||||
return 1;
|
||||
|
||||
rv = remote->Init(argv[1]);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to initialize data source");
|
||||
if (NS_FAILED(rv)) return 1;
|
||||
|
||||
// The do_QI() on the pointer is a hack to make sure that the new
|
||||
// object gets AddRef()-ed.
|
||||
nsCOMPtr<nsIRDFObserver> observer = do_QueryInterface(new Observer);
|
||||
if (! observer)
|
||||
return 1;
|
||||
|
||||
rv = ds->AddObserver(observer);
|
||||
if (NS_FAILED(rv)) return 1;
|
||||
|
||||
while (1) {
|
||||
// Okay, this should load the XML file...
|
||||
rv = remote->Refresh(true);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to open datasource");
|
||||
if (NS_FAILED(rv)) return 1;
|
||||
|
||||
if (argc <= 2)
|
||||
break;
|
||||
|
||||
int32_t pollinterval = atol(argv[2]);
|
||||
if (! pollinterval)
|
||||
break;
|
||||
|
||||
PR_Sleep(PR_SecondsToInterval(pollinterval));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
GeckoProgram('triplescat', linkage='dependent')
|
||||
|
||||
SOURCES += [
|
||||
'triplescat.cpp',
|
||||
]
|
||||
|
||||
CXXFLAGS += CONFIG['TK_CFLAGS']
|
|
@ -1,155 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsCOMPtr.h"
|
||||
//#include "nsString.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsThreadUtils.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 "plstr.h"
|
||||
#include "prio.h"
|
||||
#include "prthread.h"
|
||||
|
||||
#include "rdf.h"
|
||||
#include "rdfIDataSource.h"
|
||||
#include "rdfITripleVisitor.h"
|
||||
#include "rdfISerializer.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Blatantly stolen from netwerk/test/
|
||||
#define RETURN_IF_FAILED(rv, step) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_FAILED(rv)) { \
|
||||
printf(">>> %s failed: rv=%x\n", step, static_cast<uint32_t>(rv)); \
|
||||
return 1;\
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ConsoleOutputStreamImpl : public nsIOutputStream
|
||||
{
|
||||
protected:
|
||||
virtual ~ConsoleOutputStreamImpl(void) {}
|
||||
|
||||
public:
|
||||
ConsoleOutputStreamImpl(void) {}
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIOutputStream interface
|
||||
NS_IMETHOD Close(void) override {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD Write(const char* aBuf, uint32_t aCount, uint32_t *aWriteCount) override {
|
||||
PR_Write(PR_GetSpecialFD(PR_StandardOutput), aBuf, aCount);
|
||||
*aWriteCount = aCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
WriteFrom(nsIInputStream *inStr, uint32_t count, uint32_t *_retval) override {
|
||||
NS_NOTREACHED("WriteFrom");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
WriteSegments(nsReadSegmentFun reader, void * closure, uint32_t count, uint32_t *_retval) override {
|
||||
NS_NOTREACHED("WriteSegments");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
IsNonBlocking(bool *aNonBlocking) override {
|
||||
NS_NOTREACHED("IsNonBlocking");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) override {
|
||||
PR_Sync(PR_GetSpecialFD(PR_StandardOutput));
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, nsIOutputStream)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <url>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
|
||||
// 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(false);
|
||||
RETURN_IF_FAILED(rv, "datasource refresh");
|
||||
|
||||
// Pump events until the load is finished
|
||||
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
NS_ENSURE_TRUE(NS_ProcessNextEvent(thread), 1);
|
||||
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();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче