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 java.util.StringTokenizer;
  26 
  27 /**
  28  * For list types: ENTITIES, IDREFS, NMTOKENS.
  29  *
  30  * @xerces.internal
  31  *
  32  * @author Jeffrey Rodriguez, IBM
  33  * @author Sandy Gao, IBM
  34  *
  35  */
  36 public class ListDatatypeValidator implements DatatypeValidator {
  37 
  38     // the type of items in the list
  39     DatatypeValidator fItemValidator;
  40 
  41     // construct a list datatype validator
  42     public ListDatatypeValidator(DatatypeValidator itemDV) {
  43         fItemValidator = itemDV;
  44     }
  45 
  46     /**
  47      * Checks that "content" string is valid.
  48      * If invalid a Datatype validation exception is thrown.
  49      *
  50      * @param content       the string value that needs to be validated
  51      * @param context       the validation context
  52      * @throws InvalidDatatypeException if the content is
  53      *         invalid according to the rules for the validators
  54      * @see InvalidDatatypeValueException
  55      */
  56     public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {
  57 
  58         StringTokenizer parsedList = new StringTokenizer(content," ");
  59         int numberOfTokens =  parsedList.countTokens();
  60         if (numberOfTokens == 0) {
  61             throw new InvalidDatatypeValueException("EmptyList", null);
  62         }
  63         //Check each token in list against base type
  64         while (parsedList.hasMoreTokens()) {
  65             this.fItemValidator.validate(parsedList.nextToken(), context);
  66         }
  67     }
  68 
  69 }