1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The MITRE Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Keith Visco <kvisco@ziplink.net> (Original Author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : /**
40 : * An XML Utility class
41 : **/
42 :
43 : #ifndef MITRE_XMLUTILS_H
44 : #define MITRE_XMLUTILS_H
45 :
46 : #include "txCore.h"
47 : #include "nsCOMPtr.h"
48 : #include "nsDependentSubstring.h"
49 : #include "nsIAtom.h"
50 : #include "txXPathNode.h"
51 : #include "nsIParserService.h"
52 : #include "nsContentUtils.h"
53 :
54 : #define kExpatSeparatorChar 0xFFFF
55 :
56 : class nsIAtom;
57 : class txNamespaceMap;
58 :
59 57564 : class txExpandedName {
60 : public:
61 0 : txExpandedName() : mNamespaceID(kNameSpaceID_None)
62 : {
63 0 : }
64 :
65 57564 : txExpandedName(PRInt32 aNsID,
66 : nsIAtom* aLocalName) : mNamespaceID(aNsID),
67 57564 : mLocalName(aLocalName)
68 : {
69 57564 : }
70 :
71 0 : txExpandedName(const txExpandedName& aOther) :
72 : mNamespaceID(aOther.mNamespaceID),
73 0 : mLocalName(aOther.mLocalName)
74 : {
75 0 : }
76 :
77 : nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
78 : bool aUseDefault);
79 :
80 0 : void reset()
81 : {
82 0 : mNamespaceID = kNameSpaceID_None;
83 0 : mLocalName = nsnull;
84 0 : }
85 :
86 0 : bool isNull()
87 : {
88 0 : return mNamespaceID == kNameSpaceID_None && !mLocalName;
89 : }
90 :
91 : txExpandedName& operator = (const txExpandedName& rhs)
92 : {
93 : mNamespaceID = rhs.mNamespaceID;
94 : mLocalName = rhs.mLocalName;
95 : return *this;
96 : }
97 :
98 0 : bool operator == (const txExpandedName& rhs) const
99 : {
100 0 : return ((mLocalName == rhs.mLocalName) &&
101 0 : (mNamespaceID == rhs.mNamespaceID));
102 : }
103 :
104 : bool operator != (const txExpandedName& rhs) const
105 : {
106 : return ((mLocalName != rhs.mLocalName) ||
107 : (mNamespaceID != rhs.mNamespaceID));
108 : }
109 :
110 : PRInt32 mNamespaceID;
111 : nsCOMPtr<nsIAtom> mLocalName;
112 : };
113 :
114 : class XMLUtils {
115 :
116 : public:
117 : static nsresult splitExpatName(const PRUnichar *aExpatName,
118 : nsIAtom **aPrefix, nsIAtom **aLocalName,
119 : PRInt32* aNameSpaceID);
120 : static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
121 : nsIAtom** aLocalName);
122 : static const nsDependentSubstring getLocalPart(const nsAString& src);
123 :
124 : /*
125 : * Returns true if the given character is whitespace.
126 : */
127 42 : static bool isWhitespace(const PRUnichar& aChar)
128 : {
129 : return (aChar <= ' ' &&
130 : (aChar == ' ' || aChar == '\r' ||
131 42 : aChar == '\n'|| aChar == '\t'));
132 : }
133 :
134 : /**
135 : * Returns true if the given string has only whitespace characters
136 : */
137 : static bool isWhitespace(const nsAFlatString& aText);
138 :
139 : /**
140 : * Normalizes the value of a XML processingInstruction
141 : **/
142 : static void normalizePIValue(nsAString& attValue);
143 :
144 : /**
145 : * Returns true if the given string is a valid XML QName
146 : */
147 0 : static bool isValidQName(const nsAFlatString& aQName,
148 : const PRUnichar** aColon)
149 : {
150 0 : nsIParserService* ps = nsContentUtils::GetParserService();
151 0 : return ps && NS_SUCCEEDED(ps->CheckQName(aQName, true, aColon));
152 : }
153 :
154 : /**
155 : * Returns true if the given character represents an Alpha letter
156 : */
157 42 : static bool isLetter(PRUnichar aChar)
158 : {
159 42 : nsIParserService* ps = nsContentUtils::GetParserService();
160 42 : return ps && ps->IsXMLLetter(aChar);
161 : }
162 :
163 : /**
164 : * Returns true if the given character is an allowable NCName character
165 : */
166 0 : static bool isNCNameChar(PRUnichar aChar)
167 : {
168 0 : nsIParserService* ps = nsContentUtils::GetParserService();
169 0 : return ps && ps->IsXMLNCNameChar(aChar);
170 : }
171 :
172 : /*
173 : * Walks up the document tree and returns true if the closest xml:space
174 : * attribute is "preserve"
175 : */
176 : static bool getXMLSpacePreserve(const txXPathNode& aNode);
177 : };
178 :
179 : #endif
|