1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
15 * The Original Code is Mozilla Schema Validation.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * IBM Corporation. All Rights Reserved.
23 * Doron Rosenberg <doronr@us.ibm.com> (original author)
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef __nsSchemaValidatorUtils_h__
40 #define __nsSchemaValidatorUtils_h__
43 #include "nsStringAPI.h"
44 #include "nsISVSchema.h"
45 #include "nsIDOMNode.h"
46 #include "nsCOMArray.h"
47 #include "nsIServiceManager.h"
48 #include "nsIComponentManager.h"
49 #include "nsISchemaDuration.h"
50 #include "nsISchemaValidatorRegexp.h"
53 PRUint32 day
; // day represented (1-31)
54 PRBool tz_negative
; // is timezone negative
55 PRUint32 tz_hour
; // timezone - hour (0-23) - null if not specified
56 PRUint32 tz_minute
; // timezone - minute (0-59) - null if not specified
59 struct nsSchemaGMonth
{
60 PRUint32 month
; // month represented (1-12)
61 PRBool tz_negative
; // is timezone negative
62 PRUint32 tz_hour
; // timezone - hour (0-23) - null if not specified
63 PRUint32 tz_minute
; // timezone - minute (0-59) - null if not specified
66 struct nsSchemaGYear
{
68 PRBool tz_negative
; // is timezone negative
69 PRUint32 tz_hour
; // timezone - hour (0-23) - null if not specified
70 PRUint32 tz_minute
; // timezone - minute (0-59) - null if not specified
73 struct nsSchemaGYearMonth
{
75 nsSchemaGMonth gMonth
;
78 struct nsSchemaGMonthDay
{
79 nsSchemaGMonth gMonth
;
83 struct nsMonthShortHand
{
85 const char *shortHand
;
88 const nsMonthShortHand monthShortHand
[] = {
103 #define kREGEXP_CID "@mozilla.org/xmlextras/schemas/schemavalidatorregexp;1"
105 class nsSchemaStringFacet
110 nsSchemaStringFacet() {
111 isDefined
= PR_FALSE
;
115 class nsSchemaIntFacet
121 isDefined
= PR_FALSE
;
126 struct nsSchemaDerivedSimpleType
{
127 nsISVSchemaSimpleType
* mBaseType
;
129 nsSchemaIntFacet length
;
130 nsSchemaIntFacet minLength
;
131 nsSchemaIntFacet maxLength
;
133 nsSchemaStringFacet pattern
;
135 PRBool isWhitespaceDefined
;
136 unsigned short whitespace
;
138 nsSchemaStringFacet maxInclusive
;
139 nsSchemaStringFacet minInclusive
;
140 nsSchemaStringFacet maxExclusive
;
141 nsSchemaStringFacet minExclusive
;
143 nsSchemaIntFacet totalDigits
;
144 nsSchemaIntFacet fractionDigits
;
146 nsStringArray enumerationList
;
149 struct nsSchemaDate
{
156 struct nsSchemaTime
{
160 PRUint32 millisecond
;
166 struct nsSchemaDateTime
{
172 class nsSchemaValidatorUtils
175 static PRBool
IsValidSchemaInteger(const nsAString
& aNodeValue
, long *aResult
,
176 PRBool aOverFlowCheck
= PR_FALSE
);
177 static PRBool
IsValidSchemaInteger(const char* aString
, long *aResult
,
178 PRBool aOverFlowCheck
);
180 static PRBool
IsValidSchemaDouble(const nsAString
& aNodeValue
, double *aResult
);
181 static PRBool
IsValidSchemaDouble(const char* aString
, double *aResult
);
183 static PRBool
ParseDateTime(const nsAString
& aNodeValue
,
184 nsSchemaDateTime
*aResult
);
185 static PRBool
ParseSchemaDate(const nsAString
& aStrValue
,
186 PRBool aAllowTimeZone
,
187 nsSchemaDate
*aDate
);
188 static PRBool
ParseSchemaTime(const nsAString
& aStrValue
, nsSchemaTime
*aTime
);
190 static PRBool
ParseSchemaTimeZone(const nsAString
& aStrValue
,
191 char *rv_tzhour
, char *rv_tzminute
);
193 static void GetMonthShorthand(PRUint8 aMonth
, nsACString
& aReturn
);
195 static int CompareDateTime(nsSchemaDateTime aDateTime1
,
196 nsSchemaDateTime aDateTime2
);
197 static int CompareDate(nsSchemaDate aDate1
, nsSchemaDate aDate2
);
198 static int CompareTime(nsSchemaTime aTime1
, nsSchemaTime aTime2
);
200 static void AddTimeZoneToDateTime(nsSchemaDateTime aDateTime
,
201 nsSchemaDateTime
* aDestDateTime2
);
203 static int CompareGYearMonth(nsSchemaGYearMonth aYearMonth1
, nsSchemaGYearMonth aYearMonth2
);
204 static int CompareGMonthDay(nsSchemaGMonthDay aMonthDay1
, nsSchemaGMonthDay aMonthDay2
);
206 static PRBool
ParseSchemaDuration(const char * aStrValue
,
207 nsISchemaDuration
**aDuration
);
208 static PRBool
ParseSchemaDuration(const nsAString
& aStrValue
,
209 nsISchemaDuration
**aDuration
);
211 static int CompareStrings(const nsAString
& aString1
, const nsAString
& aString2
);
213 static int GetMaximumDayInMonthFor(PRUint32 aYearValue
, PRUint8 aMonthValue
);
214 static int CompareDurations(nsISchemaDuration
*aDuration1
,
215 nsISchemaDuration
*aDuration2
);
216 static void AddDurationToDatetime(nsSchemaDateTime aDatetime
,
217 nsISchemaDuration
*aDuration
,
218 nsSchemaDateTime
* aResultDateTime
);
220 static PRBool
IsValidSchemaNormalizedString(const nsAString
& aStrValue
);
221 static PRBool
IsValidSchemaToken(const nsAString
& aStrValue
);
222 static PRBool
IsValidSchemaLanguage(const nsAString
& aStrValue
);
223 static PRBool
IsValidSchemaName(const nsAString
& aStrValue
);
224 static PRBool
IsValidSchemaNCName(const nsAString
& aStrValue
);
225 static PRBool
IsValidSchemaNMToken(const nsAString
& aStrValue
);
226 static PRBool
IsValidSchemaNMTokens(const nsAString
& aStrValue
);
227 static PRBool
IsValidSchemaID(const nsAString
& aStrValue
);
228 static PRBool
IsValidSchemaIDRef(const nsAString
& aStrValue
);
229 static PRBool
IsValidSchemaIDRefs(const nsAString
& aStrValue
);
230 static PRBool
IsWhitespace(PRUnichar aChar
);
232 static PRBool
HandleEnumeration(const nsAString
&aStrValue
,
233 const nsStringArray
&aEnumerationList
);
235 static void RemoveLeadingZeros(nsAString
& aString
);
236 static void RemoveTrailingZeros(nsAString
& aString
);
238 static nsresult
GetDerivedSimpleType(nsISVSchemaSimpleType
*aSimpleType
,
239 nsSchemaDerivedSimpleType
*aDerived
);
240 static void CopyDerivedSimpleType(nsSchemaDerivedSimpleType
*aDerivedDest
,
241 nsSchemaDerivedSimpleType
*aDerivedSrc
);
243 static void SetToNullOrElement(nsIDOMNode
*aNode
, nsIDOMNode
**aResultNode
);
244 static PRInt32
FindCharInSet(const nsAString
& aString
, const char *aSet
,
245 PRInt32 aOffset
= 0);
247 nsSchemaValidatorUtils();
248 ~nsSchemaValidatorUtils();
253 #endif // __nsSchemaValidatorUtils_h__