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