1998-12-24 05:07:14 +00: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 "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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
1999-01-05 21:22:20 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Implementations for a bunch of useful RDF utility routines. Many of
|
|
|
|
these will eventually be exported outside of RDF.DLL via the
|
|
|
|
nsIRDFService interface.
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
TO DO
|
|
|
|
|
|
|
|
1) Make this so that it doesn't permanently leak the RDF service
|
|
|
|
object.
|
|
|
|
|
|
|
|
2) Make container functions thread-safe. They currently don't ensure
|
|
|
|
that the RDF:nextVal property is maintained safely.
|
|
|
|
|
1999-01-05 21:22:20 +00:00
|
|
|
*/
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFDataSource.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIRDFNode.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFService.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-06-09 08:29:51 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsRDFCID.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsString.h"
|
1999-03-29 19:52:54 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-05-21 22:18:29 +00:00
|
|
|
#include "prtime.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "rdfutil.h"
|
1999-11-03 05:13:44 +00:00
|
|
|
#include "nsNeckoUtil.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-06-16 04:45:36 +00:00
|
|
|
nsresult
|
1999-06-09 08:29:51 +00:00
|
|
|
rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI)
|
1999-01-22 06:48:25 +00:00
|
|
|
{
|
1999-06-09 08:29:51 +00:00
|
|
|
// This implementation is extremely simple: e.g., it can't compute
|
|
|
|
// relative paths, or anything fancy like that. If the context URI
|
|
|
|
// is not a prefix of the URI in question, we'll just bail.
|
|
|
|
if (aURI.Find(aBaseURI) != 0)
|
1999-01-22 06:48:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Otherwise, pare down the target URI, removing the context URI.
|
1999-06-09 08:29:51 +00:00
|
|
|
aURI.Cut(0, aBaseURI.Length());
|
1999-03-05 00:03:30 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
if (aURI.First() == '/')
|
1999-03-05 00:03:30 +00:00
|
|
|
aURI.Cut(0, 1);
|
|
|
|
|
1999-01-22 06:48:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-16 04:45:36 +00:00
|
|
|
nsresult
|
1999-06-09 08:29:51 +00:00
|
|
|
rdf_MakeRelativeName(const nsString& aBaseURI, nsString& aURI)
|
1999-02-17 11:09:57 +00:00
|
|
|
{
|
1999-06-09 08:29:51 +00:00
|
|
|
nsresult rv;
|
1999-02-17 11:09:57 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
rv = rdf_MakeRelativeRef(aBaseURI, aURI);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (aURI.First() == '#')
|
|
|
|
aURI.Cut(0, 1);
|
1999-02-17 11:09:57 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-16 04:45:36 +00:00
|
|
|
nsresult
|
1999-06-09 08:29:51 +00:00
|
|
|
rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString result;
|
|
|
|
|
1999-11-03 05:13:44 +00:00
|
|
|
nsCOMPtr<nsIURI> base;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(base), aBaseURI);
|
1999-06-18 17:34:08 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-03 05:13:44 +00:00
|
|
|
rv = NS_MakeAbsoluteURI(aURI, base, result);
|
1999-06-18 17:34:08 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aURI = result;
|
1999-02-17 11:09:57 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-06-09 08:29:51 +00:00
|
|
|
// There are some ugly URIs (e.g., "NC:Foo") that netlib can't
|
|
|
|
// parse. If NS_MakeAbsoluteURL fails, then just punt and
|
|
|
|
// assume that aURI was already absolute.
|
1999-02-17 11:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-12 21:14:32 +00:00
|
|
|
|
|
|
|
|
1999-06-16 04:45:36 +00:00
|
|
|
nsresult
|
1999-06-23 03:29:44 +00:00
|
|
|
rdf_MakeAbsoluteURI(nsIURI* aURL, nsString& aURI)
|
1999-06-12 21:14:32 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString result;
|
|
|
|
|
1999-11-03 05:13:44 +00:00
|
|
|
rv = NS_MakeAbsoluteURI(aURI, aURL, result);
|
1999-06-18 17:34:08 +00:00
|
|
|
|
1999-06-12 21:14:32 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aURI = result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// There are some ugly URIs (e.g., "NC:Foo") that netlib can't
|
|
|
|
// parse. If NS_MakeAbsoluteURL fails, then just punt and
|
|
|
|
// assume that aURI was already absolute.
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|