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 07:36:06 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
#ifndef TX_EXE
|
|
|
|
#include "nsIParserService.h"
|
|
|
|
#endif
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~txExpandedName()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-11-02 07:40:09 +00:00
|
|
|
nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
|
|
|
|
MBool aUseDefault);
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
mNamespaceID = kNameSpaceID_None;
|
|
|
|
mLocalName = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool isNull()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2005-11-02 07:37:26 +00:00
|
|
|
MBool 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
|
|
|
}
|
|
|
|
|
2005-11-02 07:37:26 +00:00
|
|
|
MBool 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
|
|
|
};
|
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
#ifdef TX_EXE
|
2005-11-02 07:41:56 +00:00
|
|
|
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
|
|
|
|
int ns_aware, const char** colon);
|
2005-11-02 07:41:54 +00:00
|
|
|
extern "C" int MOZ_XMLIsLetter(const char* ptr);
|
|
|
|
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
|
|
|
|
#else
|
|
|
|
extern nsIParserService *gTxParserService;
|
|
|
|
#endif
|
|
|
|
|
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:40:09 +00:00
|
|
|
static nsresult splitXMLName(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.
|
|
|
|
*/
|
2005-11-02 07:38:52 +00:00
|
|
|
static MBool 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
|
|
|
*/
|
|
|
|
static PRBool isWhitespace(const nsAFlatString& aText);
|
|
|
|
|
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
|
|
|
*/
|
2005-11-02 07:41:55 +00:00
|
|
|
static PRBool isValidQName(const nsAFlatString& aQName,
|
|
|
|
const PRUnichar** aColon)
|
2005-11-02 07:41:54 +00:00
|
|
|
{
|
|
|
|
#ifdef TX_EXE
|
|
|
|
const PRUnichar* end;
|
|
|
|
aQName.EndReading(end);
|
|
|
|
|
|
|
|
const char *colonPtr;
|
2005-11-02 07:41:56 +00:00
|
|
|
int result = MOZ_XMLCheckQName(NS_REINTERPRET_CAST(const char*,
|
|
|
|
aQName.get()),
|
|
|
|
NS_REINTERPRET_CAST(const char*,
|
|
|
|
end),
|
|
|
|
PR_TRUE, &colonPtr);
|
2005-11-02 07:41:54 +00:00
|
|
|
*aColon = NS_REINTERPRET_CAST(const PRUnichar*, colonPtr);
|
2005-11-02 07:41:56 +00:00
|
|
|
return result == 0;
|
2005-11-02 07:41:54 +00:00
|
|
|
#else
|
2005-11-02 07:41:56 +00:00
|
|
|
return NS_SUCCEEDED(gTxParserService->CheckQName(aQName, PR_TRUE, aColon));
|
2005-11-02 07:41:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
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
|
|
|
*/
|
2005-11-02 07:41:54 +00:00
|
|
|
static PRBool isLetter(PRUnichar aChar)
|
|
|
|
{
|
|
|
|
#ifdef TX_EXE
|
|
|
|
return MOZ_XMLIsLetter(NS_REINTERPRET_CAST(const char*, &aChar));
|
|
|
|
#else
|
|
|
|
return gTxParserService->IsXMLLetter(aChar);
|
|
|
|
#endif
|
|
|
|
}
|
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
|
|
|
*/
|
2005-11-02 07:41:54 +00:00
|
|
|
static PRBool isNCNameChar(PRUnichar aChar)
|
|
|
|
{
|
|
|
|
#ifdef TX_EXE
|
|
|
|
return MOZ_XMLIsNCNameChar(NS_REINTERPRET_CAST(const char*, &aChar));
|
|
|
|
#else
|
|
|
|
return gTxParserService->IsXMLNCNameChar(aChar);
|
|
|
|
#endif
|
|
|
|
}
|
2005-11-02 07:38:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walks up the document tree and returns true if the closest xml:space
|
|
|
|
* attribute is "preserve"
|
|
|
|
*/
|
2005-11-02 07:41:43 +00:00
|
|
|
static MBool getXMLSpacePreserve(const txXPathNode& aNode);
|
2005-11-02 07:37:53 +00:00
|
|
|
};
|
1999-08-28 08:19:56 +00:00
|
|
|
|
|
|
|
#endif
|