ListDatatypeValidator.java revision 628:2bfaf29cc90b
1193326Sed/*
2193326Sed * reserved comment block
3193326Sed * DO NOT REMOVE OR ALTER!
4193326Sed */
5193326Sed/*
6193326Sed * Copyright 1999-2002,2004,2005 The Apache Software Foundation.
7193326Sed *
8193326Sed * Licensed under the Apache License, Version 2.0 (the "License");
9193326Sed * you may not use this file except in compliance with the License.
10193326Sed * You may obtain a copy of the License at
11193326Sed *
12193326Sed *      http://www.apache.org/licenses/LICENSE-2.0
13193326Sed *
14193326Sed * Unless required by applicable law or agreed to in writing, software
15193326Sed * distributed under the License is distributed on an "AS IS" BASIS,
16193326Sed * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17249423Sdim * See the License for the specific language governing permissions and
18249423Sdim * limitations under the License.
19202879Srdivacky */
20249423Sdim
21193326Sedpackage com.sun.org.apache.xerces.internal.impl.dv.dtd;
22249423Sdim
23212904Sdimimport com.sun.org.apache.xerces.internal.impl.dv.*;
24193326Sedimport java.util.StringTokenizer;
25226633Sdim
26234353Sdim/**
27234353Sdim * For list types: ENTITIES, IDREFS, NMTOKENS.
28239462Sdim *
29193326Sed * @xerces.internal
30193326Sed *
31193326Sed * @author Jeffrey Rodriguez, IBM
32193326Sed * @author Sandy Gao, IBM
33193326Sed *
34239462Sdim */
35243830Sdimpublic class ListDatatypeValidator implements DatatypeValidator {
36212904Sdim
37193326Sed    // the type of items in the list
38193326Sed    DatatypeValidator fItemValidator;
39239462Sdim
40239462Sdim    // construct a list datatype validator
41239462Sdim    public ListDatatypeValidator(DatatypeValidator itemDV) {
42239462Sdim        fItemValidator = itemDV;
43193326Sed    }
44200583Srdivacky
45218893Sdim    /**
46221345Sdim     * Checks that "content" string is valid.
47221345Sdim     * If invalid a Datatype validation exception is thrown.
48263508Sdim     *
49234353Sdim     * @param content       the string value that needs to be validated
50193326Sed     * @param context       the validation context
51193326Sed     * @throws InvalidDatatypeException if the content is
52193326Sed     *         invalid according to the rules for the validators
53193326Sed     * @see InvalidDatatypeValueException
54212904Sdim     */
55193326Sed    public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {
56200583Srdivacky
57218893Sdim        StringTokenizer parsedList = new StringTokenizer(content," ");
58221345Sdim        int numberOfTokens =  parsedList.countTokens();
59239462Sdim        if (numberOfTokens == 0) {
60210299Sed            throw new InvalidDatatypeValueException("EmptyList", null);
61239462Sdim        }
62198092Srdivacky        //Check each token in list against base type
63193326Sed        while (parsedList.hasMoreTokens()) {
64198092Srdivacky            this.fItemValidator.validate(parsedList.nextToken(), context);
65193326Sed        }
66193326Sed    }
67193326Sed
68198092Srdivacky}
69193326Sed