1999-01-05 08:36:40 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
1999-01-05 08:38:45 +03:00
|
|
|
/*
|
|
|
|
|
1999-01-06 02:29:50 +03:00
|
|
|
This is a test script that uses the nsStreamDataSource class to read
|
|
|
|
a file from the local file system (using a "file:" URL) and write it
|
|
|
|
back. The idea is that the RDF that gets written out should be
|
|
|
|
equivalent (but not necessarily identical) to the RDF that was read
|
|
|
|
in.
|
|
|
|
|
|
|
|
Currently, the nsFileSpec stuff is _really_ sensitive to Win32 file
|
|
|
|
names: be sure to use a file URL that looks like
|
|
|
|
"file://G:/tmp/foo.rdf"; that is, two forward-slashes after the
|
|
|
|
"file:", a drive letter specification with a colon (not a pipe), and
|
|
|
|
forward-slashes in the path.
|
1999-01-05 08:38:45 +03:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
1999-01-26 05:51:10 +03:00
|
|
|
#ifndef XP_UNIX
|
1999-01-05 08:36:40 +03:00
|
|
|
#include <io.h>
|
1999-01-26 05:51:10 +03:00
|
|
|
#endif
|
|
|
|
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "nsIContent.h"
|
1999-01-06 00:07:41 +03:00
|
|
|
#include "nsIEventQueueService.h"
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "nsIInputStream.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "nsINetService.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#else
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#endif // NECKO
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsIPostToServer.h"
|
1999-01-20 04:42:13 +03:00
|
|
|
#include "nsIRDFXMLDataSource.h"
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "nsIRDFDocument.h"
|
|
|
|
#include "nsIRDFNode.h"
|
|
|
|
#include "nsIRDFService.h"
|
|
|
|
#include "nsIRDFXMLSource.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIURL.h"
|
1999-01-20 04:42:13 +03:00
|
|
|
#include "nsDOMCID.h" // for NS_SCRIPT_NAMESET_REGISTRY_CID
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "nsLayoutCID.h" // for NS_NAMESPACEMANAGER_CID
|
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsRDFCID.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-05 08:36:40 +03:00
|
|
|
#include "plevent.h"
|
|
|
|
#include "plstr.h"
|
1999-01-23 01:04:27 +03:00
|
|
|
#include "rdf.h"
|
1999-01-05 08:36:40 +03:00
|
|
|
|
1999-01-20 04:42:13 +03:00
|
|
|
#if defined(XP_PC)
|
|
|
|
#define DOM_DLL "jsdom.dll"
|
|
|
|
#define LAYOUT_DLL "raptorhtml.dll"
|
1999-01-05 08:36:40 +03:00
|
|
|
#define NETLIB_DLL "netlib.dll"
|
|
|
|
#define PARSER_DLL "raptorhtmlpars.dll"
|
|
|
|
#define RDF_DLL "rdf.dll"
|
1999-01-06 00:07:41 +03:00
|
|
|
#define XPCOM_DLL "xpcom32.dll"
|
1999-01-20 04:42:13 +03:00
|
|
|
#elif defined(XP_UNIX)
|
1999-06-05 02:17:30 +04:00
|
|
|
#define DOM_DLL "libjsdom"MOZ_DLL_SUFFIX
|
|
|
|
#define LAYOUT_DLL "libraptorhtml"MOZ_DLL_SUFFIX
|
|
|
|
#define NETLIB_DLL "libnetlib"MOZ_DLL_SUFFIX
|
|
|
|
#define PARSER_DLL "libraptorhtmlpars"MOZ_DLL_SUFFIX
|
|
|
|
#define RDF_DLL "librdf"MOZ_DLL_SUFFIX
|
|
|
|
#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX
|
1999-01-20 04:42:13 +03:00
|
|
|
#elif defined(XP_MAC)
|
|
|
|
#define DOM_DLL "DOM_DLL"
|
|
|
|
#define LAYOUT_DLL "LAYOUT_DLL"
|
|
|
|
#define NETLIB_DLL "NETLIB_DLL"
|
|
|
|
#define PARSER_DLL "PARSER_DLL"
|
|
|
|
#define RDF_DLL "RDF_DLL"
|
|
|
|
#define XPCOM_DLL "XPCOM_DLL"
|
1999-01-05 08:36:40 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// CIDs
|
|
|
|
|
|
|
|
// netlib
|
1999-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
1999-01-05 08:36:40 +03:00
|
|
|
static NS_DEFINE_CID(kNetServiceCID, NS_NETSERVICE_CID);
|
1999-06-18 21:34:08 +04:00
|
|
|
#else
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
#endif // NECKO
|
1999-01-05 08:36:40 +03:00
|
|
|
|
|
|
|
// rdf
|
|
|
|
static NS_DEFINE_CID(kRDFBookMarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
1999-01-22 01:24:32 +03:00
|
|
|
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
|
1999-01-20 04:42:13 +03:00
|
|
|
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
1999-01-05 08:36:40 +03:00
|
|
|
|
|
|
|
// parser
|
|
|
|
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID);
|
|
|
|
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
|
|
|
|
|
|
|
// layout
|
|
|
|
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
|
|
|
|
1999-01-20 04:42:13 +03:00
|
|
|
// dom
|
|
|
|
static NS_DEFINE_IID(kScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID);
|
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
// xpcom
|
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
|
|
|
|
1999-01-05 08:36:40 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// IIDs
|
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
1999-01-05 08:36:40 +03:00
|
|
|
NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
|
|
|
NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
|
|
|
NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
1999-01-20 04:42:13 +03:00
|
|
|
NS_DEFINE_IID(kIRDFXMLDataSourceIID, NS_IRDFXMLDATASOURCE_IID);
|
1999-01-05 08:36:40 +03:00
|
|
|
|
|
|
|
static nsresult
|
|
|
|
SetupRegistry(void)
|
|
|
|
{
|
1999-01-06 00:07:41 +03:00
|
|
|
// netlib
|
1999-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::RegisterComponent(kNetServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
1999-06-18 21:34:08 +04:00
|
|
|
#else
|
|
|
|
nsComponentManager::RegisterComponent(kIOServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
#endif // NECKO
|
1999-01-05 08:36:40 +03:00
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
// parser
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::RegisterComponent(kParserCID, NULL, NULL, PARSER_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponent(kWellFormedDTDCID, NULL, NULL, PARSER_DLL, PR_FALSE, PR_FALSE);
|
1999-01-05 08:36:40 +03:00
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
// layout
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::RegisterComponent(kNameSpaceManagerCID, NULL, NULL, LAYOUT_DLL, PR_FALSE, PR_FALSE);
|
1999-01-05 08:36:40 +03:00
|
|
|
|
1999-01-20 04:42:13 +03:00
|
|
|
// dom
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::RegisterComponent(kScriptNameSetRegistryCID, NULL, NULL, DOM_DLL, PR_FALSE, PR_FALSE);
|
1999-01-20 04:42:13 +03:00
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
// xpcom
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
1999-01-06 00:07:41 +03:00
|
|
|
|
1999-01-05 08:36:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "usage: %s [url]\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupRegistry();
|
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
nsIEventQueueService* theEventQueueService = nsnull;
|
1999-05-05 03:32:25 +04:00
|
|
|
nsIEventQueue* mainQueue = nsnull;
|
1999-01-06 00:07:41 +03:00
|
|
|
nsIRDFService* theRDFService = nsnull;
|
1999-01-22 01:24:32 +03:00
|
|
|
nsIRDFXMLDataSource* ds = nsnull;
|
1999-01-06 00:07:41 +03:00
|
|
|
nsIRDFResource* theHomePage = nsnull;
|
|
|
|
nsIRDFResource* NC_title = nsnull;
|
|
|
|
nsIRDFLiteral* theTitle = nsnull;
|
1999-01-05 08:36:40 +03:00
|
|
|
|
1999-01-06 01:58:13 +03:00
|
|
|
// Get netlib off the floor...
|
1999-01-06 00:07:41 +03:00
|
|
|
if (NS_FAILED(rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
|
|
|
kIEventQueueServiceIID,
|
|
|
|
(nsISupports**) &theEventQueueService)))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = theEventQueueService->CreateThreadEventQueue()))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = theEventQueueService->GetThreadEventQueue(PR_GetCurrentThread(),
|
|
|
|
&mainQueue)))
|
|
|
|
goto done;
|
|
|
|
|
1999-05-05 03:32:25 +04:00
|
|
|
NS_IF_RELEASE(mainQueue);
|
|
|
|
|
1999-01-06 01:58:13 +03:00
|
|
|
// 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.)
|
1999-03-09 12:44:27 +03:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
|
1999-01-05 08:36:40 +03:00
|
|
|
nsnull,
|
1999-01-20 04:42:13 +03:00
|
|
|
kIRDFXMLDataSourceIID,
|
1999-01-05 08:36:40 +03:00
|
|
|
(void**) &ds)))
|
|
|
|
goto done;
|
|
|
|
|
1999-01-22 01:24:32 +03:00
|
|
|
if (NS_FAILED(rv = ds->SetSynchronous(PR_TRUE)))
|
1999-01-05 08:36:40 +03:00
|
|
|
goto done;
|
|
|
|
|
1999-01-22 01:24:32 +03:00
|
|
|
// Okay, this should load the XML file...
|
|
|
|
if (NS_FAILED(rv = ds->Init(argv[1])))
|
|
|
|
goto done;
|
1999-01-05 08:36:40 +03:00
|
|
|
|
1999-01-06 01:58:13 +03:00
|
|
|
// Now take the graph and munge it a little bit...
|
1999-01-05 08:36:40 +03:00
|
|
|
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFServiceCID,
|
|
|
|
kIRDFServiceIID,
|
1999-01-06 00:07:41 +03:00
|
|
|
(nsISupports**) &theRDFService)))
|
1999-01-05 08:36:40 +03:00
|
|
|
goto done;
|
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
if (NS_FAILED(rv = theRDFService->GetResource("http://home.netscape.com", &theHomePage)))
|
1999-01-05 08:36:40 +03:00
|
|
|
goto done;
|
|
|
|
|
1999-01-22 09:48:25 +03:00
|
|
|
if (NS_FAILED(rv = theRDFService->GetResource(NC_NAMESPACE_URI "title", &NC_title)))
|
1999-01-05 08:36:40 +03:00
|
|
|
goto done;
|
|
|
|
|
1999-01-06 00:07:41 +03:00
|
|
|
if (NS_FAILED(rv = theRDFService->GetLiteral(nsAutoString("Netscape's Home Page"), &theTitle)))
|
1999-01-05 08:36:40 +03:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = ds->Assert(theHomePage, NC_title, theTitle, PR_TRUE)))
|
|
|
|
goto done;
|
|
|
|
|
1999-01-06 01:58:13 +03:00
|
|
|
// And finally, write it back out.
|
1999-01-05 08:36:40 +03:00
|
|
|
if (NS_FAILED(rv = ds->Flush()))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
done:
|
|
|
|
NS_IF_RELEASE(theTitle);
|
|
|
|
NS_IF_RELEASE(NC_title);
|
|
|
|
NS_IF_RELEASE(theHomePage);
|
|
|
|
NS_IF_RELEASE(ds);
|
1999-01-06 00:07:41 +03:00
|
|
|
if (theRDFService) {
|
|
|
|
nsServiceManager::ReleaseService(kRDFServiceCID, theRDFService);
|
|
|
|
theRDFService = nsnull;
|
|
|
|
}
|
|
|
|
if (theEventQueueService) {
|
|
|
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, theEventQueueService);
|
|
|
|
theEventQueueService = nsnull;
|
1999-01-05 08:36:40 +03:00
|
|
|
}
|
|
|
|
return (NS_FAILED(rv) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|