2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
#ifndef nsNameSpaceManager_h___
|
|
|
|
#define nsNameSpaceManager_h___
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIAtom;
|
2013-10-21 14:23:33 -07:00
|
|
|
class nsAString;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
class nsNameSpaceKey : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const nsAString* KeyType;
|
|
|
|
typedef const nsAString* KeyTypePointer;
|
|
|
|
|
2014-08-05 06:19:51 -07:00
|
|
|
explicit nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey)
|
2014-02-27 15:04:46 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyType GetKey() const
|
|
|
|
{
|
|
|
|
return mKey;
|
|
|
|
}
|
|
|
|
bool KeyEquals(KeyType aKey) const
|
|
|
|
{
|
|
|
|
return mKey->Equals(*aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
|
|
{
|
|
|
|
return aKey;
|
|
|
|
}
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey) {
|
|
|
|
return mozilla::HashString(*aKey);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
enum {
|
|
|
|
ALLOW_MEMMOVE = true
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsAString* mKey;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2010-05-13 05:19:51 -07:00
|
|
|
* The Name Space Manager tracks the association between a NameSpace
|
2012-08-22 08:56:38 -07:00
|
|
|
* URI and the int32_t runtime id. Mappings between NameSpaces and
|
2007-03-22 10:30:00 -07:00
|
|
|
* NameSpace prefixes are managed by nsINameSpaces.
|
|
|
|
*
|
|
|
|
* All NameSpace URIs are stored in a global table so that IDs are
|
|
|
|
* consistent accross the app. NameSpace IDs are only consistent at runtime
|
|
|
|
* ie: they are not guaranteed to be consistent accross app sessions.
|
|
|
|
*
|
2014-02-27 15:04:46 -08:00
|
|
|
* The nsNameSpaceManager needs to have a live reference for as long as
|
2007-03-22 10:30:00 -07:00
|
|
|
* the NameSpace IDs are needed.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-08-05 10:33:55 -07:00
|
|
|
class nsNameSpaceManager MOZ_FINAL
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-02-27 15:04:46 -08:00
|
|
|
virtual ~nsNameSpaceManager() {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual nsresult RegisterNameSpace(const nsAString& aURI,
|
2014-02-27 15:04:46 -08:00
|
|
|
int32_t& aNameSpaceID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
|
|
|
|
virtual int32_t GetNameSpaceID(const nsAString& aURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
virtual bool HasElementCreator(int32_t aNameSpaceID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
static nsNameSpaceManager* GetInstance();
|
|
|
|
private:
|
|
|
|
bool Init();
|
|
|
|
nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
|
|
|
|
nsTArray< nsAutoPtr<nsString> > mURIArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance;
|
|
|
|
};
|
|
|
|
|
2014-02-27 15:04:46 -08:00
|
|
|
#endif // nsNameSpaceManager_h___
|