2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-19 02:42:30 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-01-19 02:42:30 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-01-19 02:42:30 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
A data source that can read itself from and write itself to an
|
|
|
|
RDF/XML stream.
|
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
For more information on the RDF/XML syntax,
|
|
|
|
see http://www.w3.org/TR/REC-rdf-syntax/.
|
|
|
|
|
|
|
|
This code is based on the final W3C Recommendation,
|
|
|
|
http://www.w3.org/TR/1999/REC-rdf-syntax-19990222.
|
|
|
|
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
TO DO
|
|
|
|
-----
|
|
|
|
|
1999-01-21 22:24:32 +00:00
|
|
|
1) Right now, the only kind of stream data sources that are _really_
|
1999-06-20 00:19:23 +00:00
|
|
|
writable are "file:" URIs. (In fact, _all_ "file:" URIs are
|
2000-03-28 04:53:57 +00:00
|
|
|
writable, modulo file system permissions; this may lead to some
|
1999-06-20 00:19:23 +00:00
|
|
|
surprising behavior.) Eventually, it'd be great if we could open
|
|
|
|
an arbitrary nsIOutputStream on *any* URL, and Netlib could just
|
|
|
|
do the magic.
|
1999-01-21 22:24:32 +00:00
|
|
|
|
1999-01-22 06:48:25 +00:00
|
|
|
2) Implement a more terse output for "typed" nodes; that is, instead
|
1999-04-21 00:09:41 +00:00
|
|
|
of "RDF:Description type='ns:foo'", just output "ns:foo".
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
3) When re-serializing, we "cheat" for Descriptions that talk about
|
|
|
|
inline resources (i.e.., using the `ID' attribute specified in
|
|
|
|
[6.21]). Instead of writing an `ID="foo"' for the first instance,
|
|
|
|
and then `about="#foo"' for each subsequent instance, we just
|
|
|
|
_always_ write `about="#foo"'.
|
1999-01-26 01:24:34 +00:00
|
|
|
|
1999-06-20 00:19:23 +00:00
|
|
|
We do this so that we can handle the case where an RDF container
|
|
|
|
has been assigned arbitrary properties: the spec says we can't
|
|
|
|
dangle the attributes directly off the container, so we need to
|
|
|
|
refer to it. Of course, with a little cleverness, we could fix
|
|
|
|
this. But who cares?
|
|
|
|
|
|
|
|
4) When re-serializing containers. We have to cheat on some
|
|
|
|
containers, and use an illegal "about=" construct. We do this to
|
|
|
|
handle containers that have been assigned URIs outside of the
|
|
|
|
local document.
|
1999-06-16 05:11:05 +00:00
|
|
|
|
2001-02-16 20:34:30 +00:00
|
|
|
|
|
|
|
Logging
|
|
|
|
-------
|
|
|
|
|
|
|
|
To turn on logging for this module, set
|
|
|
|
|
|
|
|
NSPR_LOG_MODULES=nsRDFXMLDataSource:5
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
*/
|
|
|
|
|
2002-02-01 00:24:27 +00:00
|
|
|
#include "nsIFileStreams.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsIFileChannel.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsIDTD.h"
|
1999-05-05 03:09:12 +00:00
|
|
|
#include "nsIRDFPurgeableDataSource.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
1999-04-27 05:54:18 +00:00
|
|
|
#include "nsIRDFContainerUtils.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsIRDFNode.h"
|
1999-06-24 00:22:58 +00:00
|
|
|
#include "nsIRDFRemoteDataSource.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsIRDFService.h"
|
2001-05-15 19:56:28 +00:00
|
|
|
#include "nsIRDFXMLParser.h"
|
|
|
|
#include "nsIRDFXMLSerializer.h"
|
1999-06-24 00:22:58 +00:00
|
|
|
#include "nsIRDFXMLSink.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsIRDFXMLSource.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIURL.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsIFileURL.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-07-02 06:15:00 +00:00
|
|
|
#include "nsIChannel.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsRDFCID.h"
|
1999-06-24 00:22:58 +00:00
|
|
|
#include "nsRDFBaseDataSources.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "nsVoidArray.h"
|
1999-03-29 19:52:54 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
#include "plstr.h"
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prthread.h"
|
1999-04-22 03:16:55 +00:00
|
|
|
#include "rdf.h"
|
1999-01-21 22:24:32 +00:00
|
|
|
#include "rdfutil.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "prlog.h"
|
2001-05-15 19:56:28 +00:00
|
|
|
#include "nsNameSpaceMap.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|
|
|
|
1999-10-13 08:00:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gLog;
|
|
|
|
#endif
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ProxyStream
|
|
|
|
//
|
|
|
|
// A silly little stub class that lets us do blocking parses
|
|
|
|
//
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
class ProxyStream : public nsIInputStream
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const char* mBuffer;
|
|
|
|
PRUint32 mSize;
|
|
|
|
PRUint32 mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ProxyStream(void) : mBuffer(nsnull)
|
|
|
|
{
|
2002-09-07 17:13:19 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ProxyStream(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIBaseStream
|
|
|
|
NS_IMETHOD Close(void) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIInputStream
|
1999-09-09 22:05:05 +00:00
|
|
|
NS_IMETHOD Available(PRUint32 *aLength) {
|
1999-01-19 02:42:30 +00:00
|
|
|
*aLength = mSize - mIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-05 03:09:12 +00:00
|
|
|
|
1999-03-05 22:53:56 +00:00
|
|
|
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
|
2000-12-12 21:58:13 +00:00
|
|
|
PRUint32 readCount = PR_MIN(aCount, (mSize-mIndex));
|
|
|
|
|
2002-01-12 03:18:55 +00:00
|
|
|
memcpy(aBuf, mBuffer+mIndex, readCount);
|
2000-12-12 21:58:13 +00:00
|
|
|
mIndex += readCount;
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
*aReadCount = readCount;
|
2000-12-12 21:58:13 +00:00
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-22 07:03:33 +00:00
|
|
|
NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) {
|
2000-12-12 21:58:13 +00:00
|
|
|
PRUint32 readCount = PR_MIN(count, (mSize-mIndex));
|
|
|
|
|
|
|
|
*_retval = 0;
|
|
|
|
nsresult rv = writer (this, closure, mBuffer+mIndex, mIndex, readCount, _retval);
|
|
|
|
mIndex += *_retval;
|
|
|
|
|
|
|
|
return rv;
|
2000-08-22 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 00:59:06 +00:00
|
|
|
NS_IMETHOD IsNonBlocking(PRBool *aNonBlocking) {
|
|
|
|
*aNonBlocking = PR_TRUE;
|
|
|
|
return NS_OK;
|
2000-08-22 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
// Implementation
|
|
|
|
void SetBuffer(const char* aBuffer, PRUint32 aSize) {
|
|
|
|
mBuffer = aBuffer;
|
|
|
|
mSize = aSize;
|
|
|
|
mIndex = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2000-11-17 20:54:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(ProxyStream, nsIInputStream);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-01-19 02:42:30 +00:00
|
|
|
// RDFXMLDataSourceImpl
|
2000-01-27 02:24:20 +00:00
|
|
|
//
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-06-24 00:22:58 +00:00
|
|
|
class RDFXMLDataSourceImpl : public nsIRDFDataSource,
|
|
|
|
public nsIRDFRemoteDataSource,
|
|
|
|
public nsIRDFXMLSink,
|
2000-01-27 02:24:20 +00:00
|
|
|
public nsIRDFXMLSource,
|
|
|
|
public nsIStreamListener
|
1999-01-19 02:42:30 +00:00
|
|
|
{
|
|
|
|
protected:
|
2000-01-27 02:24:20 +00:00
|
|
|
enum LoadState {
|
|
|
|
eLoadState_Unloaded,
|
|
|
|
eLoadState_Pending,
|
|
|
|
eLoadState_Loading,
|
|
|
|
eLoadState_Loaded
|
|
|
|
};
|
|
|
|
|
|
|
|
nsIRDFDataSource* mInner; // OWNER
|
|
|
|
PRPackedBool mIsWritable; // true if the document can be written back
|
|
|
|
PRPackedBool mIsDirty; // true if the document should be written back
|
|
|
|
LoadState mLoadState; // what we're doing now
|
|
|
|
nsVoidArray mObservers; // OWNER
|
|
|
|
nsCOMPtr<nsIURI> mURL;
|
2001-05-15 19:56:28 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsNameSpaceMap mNameSpaces;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-04-22 03:16:55 +00:00
|
|
|
// pseudo-constants
|
|
|
|
static PRInt32 gRefCnt;
|
2001-05-15 19:56:28 +00:00
|
|
|
static nsIRDFService* gRDFService;
|
1999-04-22 03:16:55 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
nsresult Init();
|
1999-01-19 02:42:30 +00:00
|
|
|
RDFXMLDataSourceImpl(void);
|
|
|
|
virtual ~RDFXMLDataSourceImpl(void);
|
2002-11-22 07:55:59 +00:00
|
|
|
nsresult rdfXMLFlush(nsIURI *aURI);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
friend nsresult
|
1999-06-24 00:22:58 +00:00
|
|
|
NS_NewRDFXMLDataSource(nsIRDFDataSource** aResult);
|
1999-06-09 08:29:51 +00:00
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
inline PRBool IsLoading() {
|
|
|
|
return (mLoadState == eLoadState_Pending) ||
|
|
|
|
(mLoadState == eLoadState_Loading);
|
|
|
|
}
|
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
public:
|
1999-01-19 02:42:30 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIRDFDataSource
|
1999-06-24 00:22:58 +00:00
|
|
|
NS_IMETHOD GetURI(char* *uri);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
NS_IMETHOD GetSource(nsIRDFResource* property,
|
|
|
|
nsIRDFNode* target,
|
|
|
|
PRBool tv,
|
|
|
|
nsIRDFResource** source) {
|
|
|
|
return mInner->GetSource(property, target, tv, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetSources(nsIRDFResource* property,
|
|
|
|
nsIRDFNode* target,
|
|
|
|
PRBool tv,
|
1999-04-24 02:41:02 +00:00
|
|
|
nsISimpleEnumerator** sources) {
|
1999-01-19 02:42:30 +00:00
|
|
|
return mInner->GetSources(property, target, tv, sources);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
|
|
|
nsIRDFResource* property,
|
|
|
|
PRBool tv,
|
|
|
|
nsIRDFNode** target) {
|
|
|
|
return mInner->GetTarget(source, property, tv, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
|
|
|
nsIRDFResource* property,
|
|
|
|
PRBool tv,
|
1999-04-24 02:41:02 +00:00
|
|
|
nsISimpleEnumerator** targets) {
|
1999-01-19 02:42:30 +00:00
|
|
|
return mInner->GetTargets(source, property, tv, targets);
|
|
|
|
}
|
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
NS_IMETHOD Assert(nsIRDFResource* aSource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aTarget,
|
1999-01-19 02:42:30 +00:00
|
|
|
PRBool tv);
|
|
|
|
|
|
|
|
NS_IMETHOD Unassert(nsIRDFResource* source,
|
|
|
|
nsIRDFResource* property,
|
|
|
|
nsIRDFNode* target);
|
|
|
|
|
1999-06-24 00:22:58 +00:00
|
|
|
NS_IMETHOD Change(nsIRDFResource* aSource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aOldTarget,
|
|
|
|
nsIRDFNode* aNewTarget);
|
|
|
|
|
|
|
|
NS_IMETHOD Move(nsIRDFResource* aOldSource,
|
|
|
|
nsIRDFResource* aNewSource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aTarget);
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
NS_IMETHOD HasAssertion(nsIRDFResource* source,
|
|
|
|
nsIRDFResource* property,
|
|
|
|
nsIRDFNode* target,
|
|
|
|
PRBool tv,
|
|
|
|
PRBool* hasAssertion) {
|
|
|
|
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
|
|
|
|
}
|
|
|
|
|
1999-07-06 23:36:44 +00:00
|
|
|
NS_IMETHOD AddObserver(nsIRDFObserver* aObserver) {
|
|
|
|
return mInner->AddObserver(aObserver);
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
1999-07-06 23:36:44 +00:00
|
|
|
NS_IMETHOD RemoveObserver(nsIRDFObserver* aObserver) {
|
|
|
|
return mInner->RemoveObserver(aObserver);
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
2000-07-19 03:58:25 +00:00
|
|
|
NS_IMETHOD HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *_retval) {
|
|
|
|
return mInner->HasArcIn(aNode, aArc, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *_retval) {
|
|
|
|
return mInner->HasArcOut(aSource, aArc, _retval);
|
|
|
|
}
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
1999-04-24 02:41:02 +00:00
|
|
|
nsISimpleEnumerator** labels) {
|
1999-01-19 02:42:30 +00:00
|
|
|
return mInner->ArcLabelsIn(node, labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
1999-04-24 02:41:02 +00:00
|
|
|
nsISimpleEnumerator** labels) {
|
1999-01-19 02:42:30 +00:00
|
|
|
return mInner->ArcLabelsOut(source, labels);
|
|
|
|
}
|
|
|
|
|
1999-04-24 02:41:02 +00:00
|
|
|
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) {
|
|
|
|
return mInner->GetAllResources(aResult);
|
1999-01-21 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-06-26 01:09:02 +00:00
|
|
|
NS_IMETHOD GetAllCmds(nsIRDFResource* source,
|
|
|
|
nsISimpleEnumerator/*<nsIRDFResource>*/** commands) {
|
|
|
|
return mInner->GetAllCmds(source, commands);
|
|
|
|
}
|
|
|
|
|
1999-03-12 21:28:34 +00:00
|
|
|
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
|
|
|
nsIRDFResource* aCommand,
|
1999-03-29 19:52:54 +00:00
|
|
|
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
|
|
|
PRBool* aResult) {
|
|
|
|
return mInner->IsCommandEnabled(aSources, aCommand, aArguments, aResult);
|
1999-03-12 21:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
1999-03-11 10:01:25 +00:00
|
|
|
nsIRDFResource* aCommand,
|
1999-03-12 21:28:34 +00:00
|
|
|
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
|
1999-01-19 02:42:30 +00:00
|
|
|
// XXX Uh oh, this could cause problems wrt. the "dirty" flag
|
|
|
|
// if it changes the in-memory store's internal state.
|
1999-03-11 10:01:25 +00:00
|
|
|
return mInner->DoCommand(aSources, aCommand, aArguments);
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
1999-06-24 00:22:58 +00:00
|
|
|
// nsIRDFRemoteDataSource interface
|
1999-08-24 09:11:48 +00:00
|
|
|
NS_DECL_NSIRDFREMOTEDATASOURCE
|
1999-06-24 00:22:58 +00:00
|
|
|
|
|
|
|
// nsIRDFXMLSink interface
|
1999-08-24 09:11:48 +00:00
|
|
|
NS_DECL_NSIRDFXMLSINK
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
// nsIRDFXMLSource interface
|
1999-08-24 09:11:48 +00:00
|
|
|
NS_DECL_NSIRDFXMLSOURCE
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2001-04-10 06:01:08 +00:00
|
|
|
// nsIRequestObserver
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2000-01-27 02:24:20 +00:00
|
|
|
|
|
|
|
// nsIStreamListener
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
// Implementation methods
|
1999-01-21 22:24:32 +00:00
|
|
|
PRBool
|
|
|
|
MakeQName(nsIRDFResource* aResource,
|
|
|
|
nsString& property,
|
|
|
|
nsString& nameSpacePrefix,
|
|
|
|
nsString& nameSpaceURI);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SerializeAssertion(nsIOutputStream* aStream,
|
|
|
|
nsIRDFResource* aResource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aValue);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SerializeProperty(nsIOutputStream* aStream,
|
|
|
|
nsIRDFResource* aResource,
|
|
|
|
nsIRDFResource* aProperty);
|
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
PRBool
|
|
|
|
IsContainerProperty(nsIRDFResource* aProperty);
|
|
|
|
|
1999-01-21 22:24:32 +00:00
|
|
|
nsresult
|
|
|
|
SerializeDescription(nsIOutputStream* aStream,
|
|
|
|
nsIRDFResource* aResource);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SerializeMember(nsIOutputStream* aStream,
|
|
|
|
nsIRDFResource* aContainer,
|
1999-06-09 08:29:51 +00:00
|
|
|
nsIRDFNode* aMember);
|
1999-01-21 22:24:32 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
SerializeContainer(nsIOutputStream* aStream,
|
|
|
|
nsIRDFResource* aContainer);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SerializePrologue(nsIOutputStream* aStream);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SerializeEpilogue(nsIOutputStream* aStream);
|
1999-09-01 00:50:01 +00:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType);
|
2001-02-20 03:31:24 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsresult
|
|
|
|
BlockingParse(nsIURI* aURL, nsIStreamListener* aConsumer);
|
1999-01-19 02:42:30 +00:00
|
|
|
};
|
|
|
|
|
1999-04-22 03:16:55 +00:00
|
|
|
PRInt32 RDFXMLDataSourceImpl::gRefCnt = 0;
|
1999-08-06 20:24:29 +00:00
|
|
|
nsIRDFService* RDFXMLDataSourceImpl::gRDFService;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2002-11-22 07:55:59 +00:00
|
|
|
static const char kFileURIPrefix[] = "file:";
|
|
|
|
static const char kResourceURIPrefix[] = "resource:";
|
|
|
|
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
nsresult
|
1999-06-24 00:22:58 +00:00
|
|
|
NS_NewRDFXMLDataSource(nsIRDFDataSource** aResult)
|
1999-01-19 02:42:30 +00:00
|
|
|
{
|
1999-06-09 08:29:51 +00:00
|
|
|
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
|
|
|
if (! aResult)
|
1999-01-19 02:42:30 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
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;
|
1999-01-19 02:42:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RDFXMLDataSourceImpl::RDFXMLDataSourceImpl(void)
|
1999-02-02 07:06:56 +00:00
|
|
|
: mInner(nsnull),
|
1999-01-20 19:56:34 +00:00
|
|
|
mIsWritable(PR_TRUE),
|
1999-01-20 01:42:13 +00:00
|
|
|
mIsDirty(PR_FALSE),
|
2001-05-15 19:56:28 +00:00
|
|
|
mLoadState(eLoadState_Unloaded)
|
1999-01-19 02:42:30 +00:00
|
|
|
{
|
2002-09-07 17:13:19 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
1999-10-13 08:00:14 +00:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gLog)
|
|
|
|
gLog = PR_NewLogModule("nsRDFXMLDataSource");
|
|
|
|
#endif
|
1999-06-09 08:29:51 +00:00
|
|
|
}
|
|
|
|
|
1999-04-22 03:16:55 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
nsresult
|
|
|
|
RDFXMLDataSourceImpl::Init()
|
|
|
|
{
|
1999-01-19 02:42:30 +00:00
|
|
|
nsresult rv;
|
1999-06-09 08:29:51 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
|
|
|
nsnull,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIRDFDataSource),
|
1999-06-09 08:29:51 +00:00
|
|
|
(void**) &mInner);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-04-22 03:16:55 +00:00
|
|
|
if (gRefCnt++ == 0) {
|
1999-08-06 20:24:29 +00:00
|
|
|
rv = nsServiceManager::GetService(kRDFServiceCID,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIRDFService),
|
1999-08-06 20:24:29 +00:00
|
|
|
NS_REINTERPRET_CAST(nsISupports**, &gRDFService));
|
|
|
|
|
1999-04-22 03:16:55 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
|
1999-06-09 08:29:51 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-22 03:16:55 +00:00
|
|
|
}
|
1999-06-09 08:29:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RDFXMLDataSourceImpl::~RDFXMLDataSourceImpl(void)
|
|
|
|
{
|
1999-05-13 20:53:07 +00:00
|
|
|
nsresult rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-08-06 20:24:29 +00:00
|
|
|
// Unregister first so that nobody else tries to get us.
|
|
|
|
rv = gRDFService->UnregisterDataSource(this);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-08-06 20:24:29 +00:00
|
|
|
// Now flush contents
|
|
|
|
rv = Flush();
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
// Release RDF/XML sink observers
|
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIRDFXMLSinkObserver* obs = NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
1999-02-02 07:06:56 +00:00
|
|
|
NS_RELEASE(mInner);
|
1999-04-22 03:16:55 +00:00
|
|
|
|
|
|
|
if (--gRefCnt == 0) {
|
1999-08-06 20:24:29 +00:00
|
|
|
if (gRDFService) {
|
|
|
|
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
|
|
|
gRDFService = nsnull;
|
|
|
|
}
|
1999-04-22 03:16:55 +00:00
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
NS_IMPL_ISUPPORTS6(RDFXMLDataSourceImpl,
|
|
|
|
nsIRDFDataSource,
|
|
|
|
nsIRDFRemoteDataSource,
|
|
|
|
nsIRDFXMLSink,
|
|
|
|
nsIRDFXMLSource,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsIRequestObserver,
|
2000-01-27 02:24:20 +00:00
|
|
|
nsIStreamListener);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
|
2001-02-20 03:31:24 +00:00
|
|
|
nsresult
|
|
|
|
RDFXMLDataSourceImpl::BlockingParse(nsIURI* aURL, nsIStreamListener* aConsumer)
|
1999-01-19 02:42:30 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-01-20 01:42:13 +00:00
|
|
|
// 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.
|
2001-02-21 20:38:08 +00:00
|
|
|
|
2001-02-12 03:14:23 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIRequest> request;
|
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
// Null LoadGroup ?
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel), aURL, nsnull);
|
1999-11-22 20:53:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-02 06:15:00 +00:00
|
|
|
nsIInputStream* in;
|
|
|
|
PRUint32 sourceOffset = 0;
|
2001-02-21 20:38:08 +00:00
|
|
|
rv = channel->Open(&in);
|
1999-11-22 20:53:09 +00:00
|
|
|
|
2001-12-22 19:08:48 +00:00
|
|
|
// 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;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-03-27 00:28:08 +00:00
|
|
|
NS_ASSERTION(in != nsnull, "no input stream");
|
|
|
|
if (! in) return NS_ERROR_FAILURE;
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
ProxyStream* proxy = new ProxyStream();
|
|
|
|
if (! proxy)
|
|
|
|
goto done;
|
|
|
|
|
2001-02-20 03:31:24 +00:00
|
|
|
// Notify load observers
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = mObservers.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
|
|
|
obs->OnBeginLoad(this);
|
|
|
|
}
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
request = do_QueryInterface(channel);
|
|
|
|
|
|
|
|
aConsumer->OnStartRequest(request, nsnull);
|
1999-01-19 02:42:30 +00:00
|
|
|
while (PR_TRUE) {
|
2002-01-17 00:45:03 +00:00
|
|
|
char buf[4096];
|
1999-01-19 02:42:30 +00:00
|
|
|
PRUint32 readCount;
|
|
|
|
|
1999-03-05 22:53:56 +00:00
|
|
|
if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))
|
1999-09-09 22:05:05 +00:00
|
|
|
break; // error
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
if (readCount == 0)
|
|
|
|
break; // eof
|
|
|
|
|
|
|
|
proxy->SetBuffer(buf, readCount);
|
1999-05-05 03:09:12 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
rv = aConsumer->OnDataAvailable(request, nsnull, proxy, sourceOffset, readCount);
|
1999-07-02 06:15:00 +00:00
|
|
|
sourceOffset += readCount;
|
1999-06-26 06:36:26 +00:00
|
|
|
if (NS_FAILED(rv))
|
1999-01-19 02:42:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-01-28 00:29:42 +00:00
|
|
|
|
2001-04-10 06:01:08 +00:00
|
|
|
aConsumer->OnStopRequest(channel, nsnull, rv);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2001-02-20 03:31:24 +00:00
|
|
|
// Notify load observers
|
|
|
|
for (i = mObservers.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
obs->OnError(this, rv, nsnull);
|
|
|
|
|
|
|
|
obs->OnEndLoad(this);
|
|
|
|
}
|
|
|
|
|
1999-08-05 20:10:08 +00:00
|
|
|
// don't leak proxy!
|
|
|
|
proxy->Close();
|
|
|
|
delete proxy;
|
|
|
|
proxy = nsnull;
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
done:
|
|
|
|
NS_RELEASE(in);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::GetLoaded(PRBool* _result)
|
|
|
|
{
|
|
|
|
*_result = (mLoadState == eLoadState_Loaded);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Init(const char* uri)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mInner != nsnull, "not initialized");
|
|
|
|
if (! mInner)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(mURL), nsDependentCString(uri));
|
1999-05-05 03:09:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-04-10 08:18:20 +00:00
|
|
|
// XXX this is a hack: any "file:" URI is considered writable. All
|
|
|
|
// others are considered read-only.
|
2002-12-11 05:40:14 +00:00
|
|
|
if ((PL_strncmp(uri, kFileURIPrefix, sizeof(kFileURIPrefix) - 1) != 0) &&
|
|
|
|
(PL_strncmp(uri, kResourceURIPrefix, sizeof(kResourceURIPrefix) - 1) != 0)) {
|
1999-04-10 08:18:20 +00:00
|
|
|
mIsWritable = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-08-06 20:24:29 +00:00
|
|
|
rv = gRDFService->RegisterDataSource(this, PR_FALSE);
|
1999-05-05 03:09:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
|
1999-06-24 00:22:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::GetURI(char* *aURI)
|
|
|
|
{
|
|
|
|
*aURI = nsnull;
|
2002-12-11 05:40:14 +00:00
|
|
|
if (!mURL) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString spec;
|
|
|
|
mURL->GetSpec(spec);
|
|
|
|
*aURI = ToNewCString(spec);
|
|
|
|
if (!*aURI) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-24 00:22:58 +00:00
|
|
|
}
|
2002-12-11 05:40:14 +00:00
|
|
|
|
1999-06-24 00:22:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Assert(nsIRDFResource* aSource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aTarget,
|
|
|
|
PRBool aTruthValue)
|
|
|
|
{
|
|
|
|
// We don't accept assertions unless we're writable (except in the
|
|
|
|
// case that we're actually _reading_ the datasource in).
|
|
|
|
nsresult rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
if (IsLoading()) {
|
1999-05-05 03:09:12 +00:00
|
|
|
PRBool hasAssertion = PR_FALSE;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
nsCOMPtr<nsIRDFPurgeableDataSource> gcable = do_QueryInterface(mInner);
|
|
|
|
if (gcable) {
|
|
|
|
rv = gcable->Mark(aSource, aProperty, aTarget, aTruthValue, &hasAssertion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
rv = NS_RDF_ASSERTION_ACCEPTED;
|
1999-04-27 21:33:36 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
if (! hasAssertion) {
|
|
|
|
rv = mInner->Assert(aSource, aProperty, aTarget, aTruthValue);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && gcable) {
|
|
|
|
// Now mark the new assertion, so it doesn't get
|
|
|
|
// removed when we sweep. Ignore rv, because we want
|
|
|
|
// to return what mInner->Assert() gave us.
|
|
|
|
PRBool didMark;
|
|
|
|
(void) gcable->Mark(aSource, aProperty, aTarget, aTruthValue, &didMark);
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else if (mIsWritable) {
|
|
|
|
rv = mInner->Assert(aSource, aProperty, aTarget, aTruthValue);
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
if (rv == NS_RDF_ASSERTION_ACCEPTED)
|
|
|
|
mIsDirty = PR_TRUE;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
return rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-04-07 06:29:41 +00:00
|
|
|
return NS_RDF_ASSERTION_REJECTED;
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-05-05 03:09:12 +00:00
|
|
|
RDFXMLDataSourceImpl::Unassert(nsIRDFResource* source,
|
|
|
|
nsIRDFResource* property,
|
1999-01-19 02:42:30 +00:00
|
|
|
nsIRDFNode* target)
|
|
|
|
{
|
1999-04-07 06:29:41 +00:00
|
|
|
// We don't accept assertions unless we're writable (except in the
|
|
|
|
// case that we're actually _reading_ the datasource in).
|
1999-01-19 02:42:30 +00:00
|
|
|
nsresult rv;
|
1999-09-29 20:25:41 +00:00
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
if (IsLoading() || mIsWritable) {
|
1999-09-29 20:25:41 +00:00
|
|
|
rv = mInner->Unassert(source, property, target);
|
2000-01-27 02:24:20 +00:00
|
|
|
if (!IsLoading() && rv == NS_RDF_ASSERTION_ACCEPTED)
|
1999-01-19 02:42:30 +00:00
|
|
|
mIsDirty = PR_TRUE;
|
|
|
|
}
|
1999-09-29 20:25:41 +00:00
|
|
|
else {
|
|
|
|
rv = NS_RDF_ASSERTION_REJECTED;
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-24 00:22:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Change(nsIRDFResource* aSource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aOldTarget,
|
|
|
|
nsIRDFNode* aNewTarget)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
if (IsLoading() || mIsWritable) {
|
1999-06-24 00:22:58 +00:00
|
|
|
rv = mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
if (!IsLoading() && rv == NS_RDF_ASSERTION_ACCEPTED)
|
1999-06-24 00:22:58 +00:00
|
|
|
mIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
1999-09-29 20:25:41 +00:00
|
|
|
rv = NS_RDF_ASSERTION_REJECTED;
|
1999-06-24 00:22:58 +00:00
|
|
|
}
|
1999-09-29 20:25:41 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-06-24 00:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Move(nsIRDFResource* aOldSource,
|
|
|
|
nsIRDFResource* aNewSource,
|
|
|
|
nsIRDFResource* aProperty,
|
|
|
|
nsIRDFNode* aTarget)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
if (IsLoading() || mIsWritable) {
|
1999-06-24 00:22:58 +00:00
|
|
|
rv = mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
|
2000-01-27 02:24:20 +00:00
|
|
|
if (!IsLoading() && rv == NS_RDF_ASSERTION_ACCEPTED)
|
1999-06-24 00:22:58 +00:00
|
|
|
mIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
1999-09-29 20:25:41 +00:00
|
|
|
rv = NS_RDF_ASSERTION_REJECTED;
|
1999-06-24 00:22:58 +00:00
|
|
|
}
|
1999-09-29 20:25:41 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-06-24 00:22:58 +00:00
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
|
2002-11-22 07:55:59 +00:00
|
|
|
nsresult
|
|
|
|
RDFXMLDataSourceImpl::rdfXMLFlush(nsIURI *aURI)
|
|
|
|
{
|
1999-10-13 08:00:14 +00:00
|
|
|
|
1999-07-03 03:19:28 +00:00
|
|
|
nsresult rv;
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2000-08-30 00:57:59 +00:00
|
|
|
{
|
|
|
|
// Quick and dirty check to see if we're in XPCOM shutdown. If
|
|
|
|
// we are, we're screwed: it's too late to serialize because
|
|
|
|
// many of the services that we'll need to acquire to properly
|
|
|
|
// write the file will be unaquirable.
|
|
|
|
nsCOMPtr<nsIRDFService> dummy = do_GetService(kRDFServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("unable to Flush() diry datasource during XPCOM shutdown");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-01 00:24:27 +00:00
|
|
|
// Is it a file? If so, we can write to it. Some day, it'd be nice
|
|
|
|
// if we didn't care what kind of stream this was...
|
2002-11-22 07:55:59 +00:00
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aURI);
|
2002-08-15 18:38:46 +00:00
|
|
|
|
2002-02-01 00:24:27 +00:00
|
|
|
if (fileURL) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
fileURL->GetFile(getter_AddRefs(file));
|
|
|
|
if (file) {
|
|
|
|
// if file doesn't exist, create it
|
|
|
|
(void)file->Create(nsIFile::NORMAL_FILE_TYPE, 0666);
|
2002-01-24 01:29:39 +00:00
|
|
|
|
2002-02-01 00:24:27 +00:00
|
|
|
nsCOMPtr<nsIOutputStream> out;
|
2002-08-15 18:38:46 +00:00
|
|
|
rv = NS_NewLocalFileOutputStream(getter_AddRefs(out), file);
|
2002-02-01 00:24:27 +00:00
|
|
|
nsCOMPtr<nsIOutputStream> bufferedOut;
|
|
|
|
if (out)
|
|
|
|
NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
|
|
|
|
if (bufferedOut) {
|
|
|
|
rv = Serialize(bufferedOut);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
2001-05-03 21:11:45 +00:00
|
|
|
done:
|
1999-01-19 02:42:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-11-22 07:55:59 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::FlushTo(const char *aURI)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURI != nsnull, "not initialized");
|
|
|
|
if (!aURI)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// XXX this is a hack: any "file:" URI is considered writable. All
|
|
|
|
// others are considered read-only.
|
|
|
|
if ((PL_strncmp(aURI, kFileURIPrefix, sizeof(kFileURIPrefix) - 1) != 0) &&
|
|
|
|
(PL_strncmp(aURI, kResourceURIPrefix, sizeof(kResourceURIPrefix) - 1) != 0))
|
|
|
|
{
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(url), aURI);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
rv = rdfXMLFlush(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Flush(void)
|
|
|
|
{
|
|
|
|
if (!mIsWritable || !mIsDirty)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-12-11 00:20:10 +00:00
|
|
|
// while it is not fatal if mOriginalURLSpec is not set,
|
|
|
|
// indicate failure since we can't flush back to an unknown origin
|
2002-12-11 05:40:14 +00:00
|
|
|
if (! mURL)
|
2002-11-22 07:55:59 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2002-12-11 05:40:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCAutoString spec;
|
|
|
|
mURL->GetSpec(spec);
|
2002-11-22 07:55:59 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] flush(%s)", this, spec.get()));
|
|
|
|
#endif
|
2002-11-22 07:55:59 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (NS_SUCCEEDED(rv = rdfXMLFlush(mURL)))
|
|
|
|
{
|
|
|
|
mIsDirty = PR_FALSE;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-01-19 02:42:30 +00:00
|
|
|
// nsIRDFXMLDataSource methods
|
2000-01-27 02:24:20 +00:00
|
|
|
//
|
1999-01-19 02:42:30 +00:00
|
|
|
|
1999-01-20 01:42:13 +00:00
|
|
|
NS_IMETHODIMP
|
1999-05-05 03:09:12 +00:00
|
|
|
RDFXMLDataSourceImpl::GetReadOnly(PRBool* aIsReadOnly)
|
1999-01-20 01:42:13 +00:00
|
|
|
{
|
1999-05-05 03:09:12 +00:00
|
|
|
*aIsReadOnly = !mIsWritable;
|
1999-01-20 01:42:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
|
1999-01-20 01:42:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::SetReadOnly(PRBool aIsReadOnly)
|
|
|
|
{
|
1999-01-20 19:56:34 +00:00
|
|
|
if (mIsWritable && aIsReadOnly)
|
|
|
|
mIsWritable = PR_FALSE;
|
|
|
|
|
1999-01-20 01:42:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-26 22:28:37 +00:00
|
|
|
#include "nsITimelineService.h"
|
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-24 00:22:58 +00:00
|
|
|
RDFXMLDataSourceImpl::Refresh(PRBool aBlocking)
|
1999-05-05 03:09:12 +00:00
|
|
|
{
|
2002-12-11 05:40:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCAutoString spec;
|
|
|
|
if (mURL) {
|
|
|
|
mURL->GetSpec(spec);
|
|
|
|
}
|
1999-10-13 08:00:14 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] refresh(%s) %sblocking", this, spec.get(), (aBlocking ? "" : "non")));
|
|
|
|
#endif
|
|
|
|
|
1999-09-24 19:52:42 +00:00
|
|
|
// If an asynchronous load is already pending, then just let it do
|
|
|
|
// the honors.
|
2000-01-27 02:24:20 +00:00
|
|
|
if (IsLoading()) {
|
1999-10-13 08:00:14 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] refresh(%s) a load was pending", this, spec.get()));
|
1999-10-13 08:00:14 +00:00
|
|
|
|
1999-09-24 19:52:42 +00:00
|
|
|
if (aBlocking) {
|
|
|
|
NS_WARNING("blocking load requested when async load pending");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 05:35:14 +00:00
|
|
|
if (! mURL)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-05-15 19:56:28 +00:00
|
|
|
nsCOMPtr<nsIRDFXMLParser> parser = do_CreateInstance("@mozilla.org/rdf/xml-parser;1");
|
|
|
|
if (! parser)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-05-05 03:09:12 +00:00
|
|
|
|
2002-11-06 05:35:14 +00:00
|
|
|
nsresult rv = parser->ParseAsync(this, mURL, getter_AddRefs(mListener));
|
1999-05-05 03:09:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (aBlocking) {
|
2001-11-26 22:28:37 +00:00
|
|
|
NS_TIMELINE_START_TIMER("rdf blocking parse");
|
2001-02-20 03:31:24 +00:00
|
|
|
rv = BlockingParse(mURL, this);
|
2001-11-26 22:28:37 +00:00
|
|
|
NS_TIMELINE_STOP_TIMER("rdf blocking parse");
|
|
|
|
NS_TIMELINE_MARK_TIMER("rdf blocking parse");
|
2000-01-27 02:24:20 +00:00
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
mListener = nsnull; // release the parser
|
2000-01-28 00:29:42 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-05-05 03:09:12 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-08-26 22:45:55 +00:00
|
|
|
// Null LoadGroup ?
|
2000-01-27 02:24:20 +00:00
|
|
|
rv = NS_OpenURI(this, nsnull, mURL, nsnull);
|
1999-09-24 19:52:42 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// So we don't try to issue two asynchronous loads at once.
|
2000-01-27 02:24:20 +00:00
|
|
|
mLoadState = eLoadState_Pending;
|
1999-05-05 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
1999-09-24 19:52:42 +00:00
|
|
|
return NS_OK;
|
1999-05-05 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::BeginLoad(void)
|
|
|
|
{
|
2002-12-11 05:40:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCAutoString spec;
|
|
|
|
if (mURL) {
|
|
|
|
mURL->GetSpec(spec);
|
|
|
|
}
|
1999-10-13 08:00:14 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] begin-load(%s)", this, spec.get()));
|
|
|
|
#endif
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
mLoadState = eLoadState_Loading;
|
1999-01-19 02:42:30 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2001-02-20 03:31:24 +00:00
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
obs->OnBeginLoad(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Interrupt(void)
|
|
|
|
{
|
2002-12-11 05:40:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCAutoString spec;
|
|
|
|
if (mURL) {
|
|
|
|
mURL->GetSpec(spec);
|
|
|
|
}
|
1999-10-13 08:00:14 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] interrupt(%s)", this, spec.get()));
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2001-02-20 03:31:24 +00:00
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
obs->OnInterrupt(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::Resume(void)
|
|
|
|
{
|
2002-12-11 05:40:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCAutoString spec;
|
|
|
|
if (mURL) {
|
|
|
|
mURL->GetSpec(spec);
|
|
|
|
}
|
1999-10-13 08:00:14 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] resume(%s)", this, spec.get()));
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2001-02-20 03:31:24 +00:00
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
1999-01-19 02:42:30 +00:00
|
|
|
obs->OnResume(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::EndLoad(void)
|
|
|
|
{
|
2002-12-11 05:40:14 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCAutoString spec;
|
|
|
|
if (mURL) {
|
|
|
|
mURL->GetSpec(spec);
|
|
|
|
}
|
1999-10-13 08:00:14 +00:00
|
|
|
PR_LOG(gLog, PR_LOG_ALWAYS,
|
2002-12-11 05:40:14 +00:00
|
|
|
("rdfxml[%p] end-load(%s)", this, spec.get()));
|
|
|
|
#endif
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
mLoadState = eLoadState_Loaded;
|
|
|
|
|
|
|
|
// Clear out any unmarked assertions from the datasource.
|
1999-05-05 03:09:12 +00:00
|
|
|
nsCOMPtr<nsIRDFPurgeableDataSource> gcable = do_QueryInterface(mInner);
|
|
|
|
if (gcable) {
|
|
|
|
gcable->Sweep();
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
// Notify load observers
|
1999-01-19 02:42:30 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2001-02-20 03:31:24 +00:00
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
1999-05-05 03:09:12 +00:00
|
|
|
obs->OnEndLoad(this);
|
1999-01-19 02:42:30 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-21 22:24:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFXMLDataSourceImpl::AddNameSpace(nsIAtom* aPrefix, const nsString& aURI)
|
|
|
|
{
|
2001-05-15 19:56:28 +00:00
|
|
|
mNameSpaces.Put(aURI, aPrefix);
|
1999-01-21 22:24:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-24 00:22:58 +00:00
|
|
|
RDFXMLDataSourceImpl::AddXMLSinkObserver(nsIRDFXMLSinkObserver* aObserver)
|
1999-02-01 22:34:51 +00:00
|
|
|
{
|
2000-01-27 02:24:20 +00:00
|
|
|
if (! aObserver)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
NS_ADDREF(aObserver);
|
1999-02-01 22:34:51 +00:00
|
|
|
mObservers.AppendElement(aObserver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-24 00:22:58 +00:00
|
|
|
RDFXMLDataSourceImpl::RemoveXMLSinkObserver(nsIRDFXMLSinkObserver* aObserver)
|
1999-02-01 22:34:51 +00:00
|
|
|
{
|
2000-01-27 02:24:20 +00:00
|
|
|
if (! aObserver)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mObservers.RemoveElement(aObserver)) {
|
|
|
|
// RemoveElement() returns PR_TRUE if it was actually there...
|
|
|
|
NS_RELEASE(aObserver);
|
|
|
|
}
|
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
2001-04-10 06:01:08 +00:00
|
|
|
// nsIRequestObserver
|
2000-01-27 02:24:20 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
RDFXMLDataSourceImpl::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
2000-01-27 02:24:20 +00:00
|
|
|
{
|
2001-05-15 19:56:28 +00:00
|
|
|
return mListener->OnStartRequest(request, ctxt);
|
2000-01-27 02:24:20 +00:00
|
|
|
}
|
1999-02-01 22:34:51 +00:00
|
|
|
|
2000-01-27 02:24:20 +00:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
RDFXMLDataSourceImpl::OnStopRequest(nsIRequest *request,
|
2000-01-27 02:24:20 +00:00
|
|
|
nsISupports *ctxt,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult status)
|
2000-01-27 02:24:20 +00:00
|
|
|
{
|
|
|
|
if (NS_FAILED(status)) {
|
2000-01-28 00:29:42 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2001-02-20 03:31:24 +00:00
|
|
|
nsIRDFXMLSinkObserver* obs =
|
|
|
|
NS_STATIC_CAST(nsIRDFXMLSinkObserver*, mObservers[i]);
|
|
|
|
|
2001-04-10 06:01:08 +00:00
|
|
|
(void) obs->OnError(this, status, nsnull);
|
2000-01-28 00:29:42 +00:00
|
|
|
}
|
2000-01-27 02:24:20 +00:00
|
|
|
}
|
|
|
|
|
2000-01-27 06:17:13 +00:00
|
|
|
nsresult rv;
|
2001-05-15 19:56:28 +00:00
|
|
|
rv = mListener->OnStopRequest(request, ctxt, status);
|
2000-01-27 06:17:13 +00:00
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
mListener = nsnull; // release the parser
|
2000-01-27 06:17:13 +00:00
|
|
|
|
|
|
|
return rv;
|
2000-01-27 02:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIStreamListener
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
RDFXMLDataSourceImpl::OnDataAvailable(nsIRequest *request,
|
2000-01-27 02:24:20 +00:00
|
|
|
nsISupports *ctxt,
|
|
|
|
nsIInputStream *inStr,
|
|
|
|
PRUint32 sourceOffset,
|
|
|
|
PRUint32 count)
|
|
|
|
{
|
2001-05-15 19:56:28 +00:00
|
|
|
return mListener->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
|
2000-01-27 02:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
2001-05-15 19:56:28 +00:00
|
|
|
// nsIRDFXMLSource
|
2000-01-27 02:24:20 +00:00
|
|
|
//
|
1999-01-19 02:42:30 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-01-21 22:24:32 +00:00
|
|
|
RDFXMLDataSourceImpl::Serialize(nsIOutputStream* aStream)
|
1999-01-19 02:42:30 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-05-15 19:56:28 +00:00
|
|
|
nsCOMPtr<nsIRDFXMLSerializer> serializer
|
|
|
|
= do_CreateInstance("@mozilla.org/rdf/xml-serializer;1", &rv);
|
1999-01-21 22:24:32 +00:00
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
if (! serializer)
|
1999-03-30 02:30:16 +00:00
|
|
|
return rv;
|
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
rv = serializer->Init(this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-21 22:24:32 +00:00
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
// Add any namespace information that we picked up when reading
|
|
|
|
// the RDF/XML
|
|
|
|
nsNameSpaceMap::const_iterator last = mNameSpaces.last();
|
|
|
|
for (nsNameSpaceMap::const_iterator iter = mNameSpaces.first(); iter != last; ++iter)
|
|
|
|
serializer->AddNameSpace(iter->mPrefix, iter->mURI);
|
1999-09-01 00:50:01 +00:00
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
// Serialize!
|
|
|
|
nsCOMPtr<nsIRDFXMLSource> source = do_QueryInterface(serializer);
|
|
|
|
if (! source)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-09-01 00:50:01 +00:00
|
|
|
|
2001-05-15 19:56:28 +00:00
|
|
|
return source->Serialize(aStream);
|
1999-09-01 00:50:01 +00:00
|
|
|
}
|