2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2005-11-02 07:42:04 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2005-11-02 07:42:05 +00:00
|
|
|
* The Original Code is TransforMiiX XSLT processor code.
|
1999-08-28 08:19:56 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The MITRE Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2005-11-02 07:42:05 +00:00
|
|
|
* Keith Visco <kvisco@ziplink.net> (Original Author)
|
2005-11-02 07:42:04 +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 MPL, 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 MPL, the GPL or the LGPL.
|
1999-08-28 08:19:56 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-28 08:19:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An XML Utility class
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef MITRE_XMLUTILS_H
|
|
|
|
#define MITRE_XMLUTILS_H
|
|
|
|
|
2005-11-02 07:42:16 +00:00
|
|
|
#include "txCore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2005-11-02 07:39:22 +00:00
|
|
|
#include "nsDependentSubstring.h"
|
2005-11-02 07:42:24 +00:00
|
|
|
#include "nsIAtom.h"
|
2005-11-02 07:41:43 +00:00
|
|
|
#include "txXPathNode.h"
|
2005-11-02 17:34:14 +00:00
|
|
|
#include "nsContentUtils.h"
|
2005-11-02 07:41:54 +00:00
|
|
|
|
2005-11-02 07:42:42 +00:00
|
|
|
#define kExpatSeparatorChar 0xFFFF
|
|
|
|
|
2012-03-15 04:56:58 +00:00
|
|
|
extern "C" int MOZ_XMLIsLetter(const char* ptr);
|
|
|
|
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
|
|
|
|
|
2005-11-02 07:42:16 +00:00
|
|
|
class nsIAtom;
|
2005-11-02 07:40:09 +00:00
|
|
|
class txNamespaceMap;
|
|
|
|
|
2005-11-02 07:37:24 +00:00
|
|
|
class txExpandedName {
|
1999-08-28 08:19:56 +00:00
|
|
|
public:
|
2005-11-02 07:39:22 +00:00
|
|
|
txExpandedName() : mNamespaceID(kNameSpaceID_None)
|
2005-11-02 07:37:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
txExpandedName(PRInt32 aNsID,
|
2005-11-02 07:39:29 +00:00
|
|
|
nsIAtom* aLocalName) : mNamespaceID(aNsID),
|
|
|
|
mLocalName(aLocalName)
|
2005-11-02 07:37:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
txExpandedName(const txExpandedName& aOther) :
|
|
|
|
mNamespaceID(aOther.mNamespaceID),
|
|
|
|
mLocalName(aOther.mLocalName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-11-02 07:40:09 +00:00
|
|
|
nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
|
2011-11-10 19:26:13 +00:00
|
|
|
bool aUseDefault);
|
2005-11-02 07:40:09 +00:00
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
mNamespaceID = kNameSpaceID_None;
|
|
|
|
mLocalName = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isNull()
|
2005-11-02 07:40:09 +00:00
|
|
|
{
|
|
|
|
return mNamespaceID == kNameSpaceID_None && !mLocalName;
|
|
|
|
}
|
2005-11-02 07:37:26 +00:00
|
|
|
|
|
|
|
txExpandedName& operator = (const txExpandedName& rhs)
|
|
|
|
{
|
|
|
|
mNamespaceID = rhs.mNamespaceID;
|
|
|
|
mLocalName = rhs.mLocalName;
|
|
|
|
return *this;
|
|
|
|
}
|
2005-11-02 07:37:24 +00:00
|
|
|
|
2011-11-10 19:26:13 +00:00
|
|
|
bool operator == (const txExpandedName& rhs) const
|
2005-11-02 07:37:24 +00:00
|
|
|
{
|
2005-11-02 07:37:26 +00:00
|
|
|
return ((mLocalName == rhs.mLocalName) &&
|
|
|
|
(mNamespaceID == rhs.mNamespaceID));
|
2005-11-02 07:37:24 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 19:26:13 +00:00
|
|
|
bool operator != (const txExpandedName& rhs) const
|
2005-11-02 07:37:24 +00:00
|
|
|
{
|
2005-11-02 07:37:26 +00:00
|
|
|
return ((mLocalName != rhs.mLocalName) ||
|
|
|
|
(mNamespaceID != rhs.mNamespaceID));
|
2005-11-02 07:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 mNamespaceID;
|
2005-11-02 07:39:22 +00:00
|
|
|
nsCOMPtr<nsIAtom> mLocalName;
|
2005-11-02 07:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class XMLUtils {
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:37:24 +00:00
|
|
|
public:
|
2005-11-02 07:42:27 +00:00
|
|
|
static nsresult splitExpatName(const PRUnichar *aExpatName,
|
|
|
|
nsIAtom **aPrefix, nsIAtom **aLocalName,
|
|
|
|
PRInt32* aNameSpaceID);
|
|
|
|
static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
|
|
|
|
nsIAtom** aLocalName);
|
2005-11-02 07:39:22 +00:00
|
|
|
static const nsDependentSubstring getLocalPart(const nsAString& src);
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:38:03 +00:00
|
|
|
/*
|
|
|
|
* Returns true if the given character is whitespace.
|
|
|
|
*/
|
2011-11-10 19:26:13 +00:00
|
|
|
static bool isWhitespace(const PRUnichar& aChar)
|
2005-11-02 07:38:03 +00:00
|
|
|
{
|
|
|
|
return (aChar <= ' ' &&
|
|
|
|
(aChar == ' ' || aChar == '\r' ||
|
|
|
|
aChar == '\n'|| aChar == '\t'));
|
|
|
|
}
|
|
|
|
|
1999-11-15 07:13:17 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given string has only whitespace characters
|
2005-11-02 07:39:22 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool isWhitespace(const nsAFlatString& aText);
|
2005-11-02 07:39:22 +00:00
|
|
|
|
1999-08-28 08:19:56 +00:00
|
|
|
/**
|
|
|
|
* Normalizes the value of a XML processingInstruction
|
|
|
|
**/
|
2005-11-02 07:39:22 +00:00
|
|
|
static void normalizePIValue(nsAString& attValue);
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given string is a valid XML QName
|
2005-11-02 07:37:53 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool isValidQName(const nsAFlatString& aQName,
|
2005-11-02 07:41:55 +00:00
|
|
|
const PRUnichar** aColon)
|
2005-11-02 07:41:54 +00:00
|
|
|
{
|
2012-03-29 21:31:40 +00:00
|
|
|
return NS_SUCCEEDED(nsContentUtils::CheckQName(aQName, true, aColon));
|
2005-11-02 07:41:54 +00:00
|
|
|
}
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
/**
|
1999-08-28 08:19:56 +00:00
|
|
|
* Returns true if the given character represents an Alpha letter
|
2005-11-02 07:37:53 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool isLetter(PRUnichar aChar)
|
2005-11-02 07:41:54 +00:00
|
|
|
{
|
2012-03-15 04:56:58 +00:00
|
|
|
return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
|
|
|
|
}
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
/**
|
1999-08-28 08:19:56 +00:00
|
|
|
* Returns true if the given character is an allowable NCName character
|
2005-11-02 07:37:53 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool isNCNameChar(PRUnichar aChar)
|
2005-11-02 07:41:54 +00:00
|
|
|
{
|
2012-03-15 04:56:58 +00:00
|
|
|
return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
|
2005-11-02 07:41:54 +00:00
|
|
|
}
|
2005-11-02 07:38:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walks up the document tree and returns true if the closest xml:space
|
|
|
|
* attribute is "preserve"
|
|
|
|
*/
|
2011-11-10 19:26:13 +00:00
|
|
|
static bool getXMLSpacePreserve(const txXPathNode& aNode);
|
2005-11-02 07:37:53 +00:00
|
|
|
};
|
1999-08-28 08:19:56 +00:00
|
|
|
|
|
|
|
#endif
|