1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2002,2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.dv.dtd; 22 23 import com.sun.org.apache.xerces.internal.impl.dv.*; 24 import com.sun.org.apache.xerces.internal.util.XML11Char; 25 26 /** 27 * <P>IDREFDatatypeValidator - represents the IDREFS 28 * attribute type from XML 1.1 recommendation. The 29 * Value Space of IDREF is the set of all strings 30 * that match the NCName production and have been 31 * used in an XML Document as the value of an element 32 * or attribute of Type ID. The Lexical space of 33 * IDREF is the set of strings that match the NCName 34 * production.</P> 35 * <P>The Value space of IDREF is scoped to a specific 36 * instance document</P> 37 * 38 * @xerces.internal 39 * 40 * @author Jeffrey Rodriguez, IBM 41 * @author Sandy Gao, IBM 42 * @author Neil Graham, IBM 43 * 44 */ 45 public class XML11IDREFDatatypeValidator extends IDREFDatatypeValidator { 46 47 // construct an IDREF datatype validator 48 public XML11IDREFDatatypeValidator() { 49 super(); 50 } 51 52 /** 53 * Checks that "content" string is valid IDREF value. 54 * If invalid a Datatype validation exception is thrown. 55 * 56 * @param content the string value that needs to be validated 57 * @param context the validation context 58 * @throws InvalidDatatypeException if the content is 59 * invalid according to the rules for the validators 60 * @see InvalidDatatypeValueException 61 */ 62 public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException { 63 64 //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* 65 if(context.useNamespaces()) { 66 if (!XML11Char.isXML11ValidNCName(content)) { 67 throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content}); 68 } 69 } 70 else { 71 if (!XML11Char.isXML11ValidName(content)) { 72 throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content}); 73 } 74 } 75 76 context.addIdRef(content); 77 78 } 79 80 }