1998-12-24 08:07:14 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03: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/
|
1998-12-24 08:07:14 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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.
|
1998-12-24 08:07:14 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:43:54 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-12-24 08:07:14 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-06 00:22:20 +03: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 22:30:04 +03: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-06 00:22:20 +03:00
|
|
|
*/
|
|
|
|
|
1999-02-16 22:30:04 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-20 04:42:13 +03:00
|
|
|
#include "nsIRDFDataSource.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
#include "nsIRDFNode.h"
|
1999-01-05 06:53:15 +03:00
|
|
|
#include "nsIRDFService.h"
|
1999-01-12 22:41:06 +03:00
|
|
|
#include "nsIServiceManager.h"
|
1999-06-09 12:29:51 +04:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-01-12 22:41:06 +03:00
|
|
|
#include "nsRDFCID.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
#include "nsString.h"
|
1999-03-29 23:52:54 +04:00
|
|
|
#include "nsXPIDLString.h"
|
1999-05-22 02:18:29 +04:00
|
|
|
#include "prtime.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
#include "rdfutil.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
|
1999-01-12 22:41:06 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-06-16 08:45:36 +04:00
|
|
|
nsresult
|
1999-06-09 12:29:51 +04:00
|
|
|
rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI)
|
1999-01-22 09:48:25 +03:00
|
|
|
{
|
1999-06-09 12:29:51 +04: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 09:48:25 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Otherwise, pare down the target URI, removing the context URI.
|
1999-06-09 12:29:51 +04:00
|
|
|
aURI.Cut(0, aBaseURI.Length());
|
1999-03-05 03:03:30 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
if (aURI.First() == '/')
|
1999-03-05 03:03:30 +03:00
|
|
|
aURI.Cut(0, 1);
|
|
|
|
|
1999-01-22 09:48:25 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-16 08:45:36 +04:00
|
|
|
nsresult
|
1999-06-09 12:29:51 +04:00
|
|
|
rdf_MakeRelativeName(const nsString& aBaseURI, nsString& aURI)
|
1999-02-17 14:09:57 +03:00
|
|
|
{
|
1999-06-09 12:29:51 +04:00
|
|
|
nsresult rv;
|
1999-02-17 14:09:57 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
rv = rdf_MakeRelativeRef(aBaseURI, aURI);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (aURI.First() == '#')
|
|
|
|
aURI.Cut(0, 1);
|
1999-02-17 14:09:57 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-16 08:45:36 +04:00
|
|
|
nsresult
|
1999-06-09 12:29:51 +04:00
|
|
|
rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString result;
|
|
|
|
|
1999-11-03 08:13:44 +03:00
|
|
|
nsCOMPtr<nsIURI> base;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(base), aBaseURI);
|
1999-06-18 21:34:08 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-03 08:13:44 +03:00
|
|
|
rv = NS_MakeAbsoluteURI(aURI, base, result);
|
1999-06-18 21:34:08 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aURI = result;
|
1999-02-17 14:09:57 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-06-09 12:29:51 +04: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 14:09:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-13 01:14:32 +04:00
|
|
|
|
|
|
|
|
1999-06-16 08:45:36 +04:00
|
|
|
nsresult
|
1999-06-23 07:29:44 +04:00
|
|
|
rdf_MakeAbsoluteURI(nsIURI* aURL, nsString& aURI)
|
1999-06-13 01:14:32 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString result;
|
|
|
|
|
1999-11-03 08:13:44 +03:00
|
|
|
rv = NS_MakeAbsoluteURI(aURI, aURL, result);
|
1999-06-18 21:34:08 +04:00
|
|
|
|
1999-06-13 01:14:32 +04: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;
|
|
|
|
}
|