01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.xerces.impl.dv.dtd;
19:
20: import org.apache.xerces.impl.dv.*;
21: import org.apache.xerces.util.XMLChar;
22:
23: /**
24: * <P>IDREFDatatypeValidator - represents the IDREFS
25: * attribute type from XML 1.0 recommendation. The
26: * Value Space of IDREF is the set of all strings
27: * that match the NCName production and have been
28: * used in an XML Document as the value of an element
29: * or attribute of Type ID. The Lexical space of
30: * IDREF is the set of strings that match the NCName
31: * production.</P>
32: * <P>The Value space of IDREF is scoped to a specific
33: * instance document</P>
34: *
35: * @xerces.internal
36: *
37: * @author Jeffrey Rodriguez, IBM
38: * @author Sandy Gao, IBM
39: *
40: * @version $Id: IDREFDatatypeValidator.java 446749 2006-09-15 21:51:23Z mrglavas $
41: */
42: public class IDREFDatatypeValidator implements DatatypeValidator {
43:
44: // construct an IDREF datatype validator
45: public IDREFDatatypeValidator() {
46: }
47:
48: /**
49: * Checks that "content" string is valid IDREF value.
50: * If invalid a Datatype validation exception is thrown.
51: *
52: * @param content the string value that needs to be validated
53: * @param context the validation context
54: * @throws InvalidDatatypeException if the content is
55: * invalid according to the rules for the validators
56: * @see InvalidDatatypeValueException
57: */
58: public void validate(String content, ValidationContext context)
59: throws InvalidDatatypeValueException {
60:
61: //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
62: if (context.useNamespaces()) {
63: if (!XMLChar.isValidNCName(content)) {
64: throw new InvalidDatatypeValueException(
65: "IDREFInvalidWithNamespaces",
66: new Object[] { content });
67: }
68: } else {
69: if (!XMLChar.isValidName(content)) {
70: throw new InvalidDatatypeValueException("IDREFInvalid",
71: new Object[] { content });
72: }
73: }
74:
75: context.addIdRef(content);
76:
77: }
78:
79: }
|