KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dv > dtd > IDREFDatatypeValidator


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.dv.dtd;
18
19 import org.apache.xerces.impl.dv.*;
20 import org.apache.xerces.util.XMLChar;
21
22 /**
23  * <P>IDREFDatatypeValidator - represents the IDREFS
24  * attribute type from XML 1.0 recommendation. The
25  * Value Space of IDREF is the set of all strings
26  * that match the NCName production and have been
27  * used in an XML Document as the value of an element
28  * or attribute of Type ID. The Lexical space of
29  * IDREF is the set of strings that match the NCName
30  * production.</P>
31  * <P>The Value space of IDREF is scoped to a specific
32  * instance document</P>
33  *
34  * @xerces.internal
35  *
36  * @author Jeffrey Rodriguez, IBM
37  * @author Sandy Gao, IBM
38  *
39  * @version $Id: IDREFDatatypeValidator.java,v 1.9 2004/10/06 14:56:51 mrglavas Exp $
40  */

41 public class IDREFDatatypeValidator implements DatatypeValidator {
42
43     // construct an IDREF datatype validator
44
public IDREFDatatypeValidator() {
45     }
46
47     /**
48      * Checks that "content" string is valid IDREF value.
49      * If invalid a Datatype validation exception is thrown.
50      *
51      * @param content the string value that needs to be validated
52      * @param context the validation context
53      * @throws InvalidDatatypeException if the content is
54      * invalid according to the rules for the validators
55      * @see InvalidDatatypeValueException
56      */

57     public void validate(String JavaDoc content, ValidationContext context) throws InvalidDatatypeValueException {
58
59         //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
60
if(context.useNamespaces()) {
61             if (!XMLChar.isValidNCName(content)) {
62                 throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object JavaDoc[]{content});
63             }
64         }
65         else {
66             if (!XMLChar.isValidName(content)) {
67                 throw new InvalidDatatypeValueException("IDREFInvalid", new Object JavaDoc[]{content});
68             }
69         }
70
71         context.addIdRef(content);
72         
73     }
74
75 }
76
Popular Tags