GME  13
EncodingValidator.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: EncodingValidator.cpp 635560 2008-03-10 14:10:09Z borisk $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/util/EncodingValidator.hpp>
00026 #include <xercesc/internal/IANAEncodings.hpp>
00027 #include <xercesc/util/XMLInitializer.hpp>
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 EncodingValidator* EncodingValidator::fInstance = 0;
00032 
00033 void XMLInitializer::initializeEncodingValidator()
00034 {
00035     EncodingValidator::fInstance = new EncodingValidator();
00036 }
00037 
00038 void XMLInitializer::terminateEncodingValidator()
00039 {
00040     delete EncodingValidator::fInstance;
00041     EncodingValidator::fInstance = 0;
00042 }
00043 
00044 // ---------------------------------------------------------------------------
00045 //  EncodingValidator: Constructors and Destructor
00046 // ---------------------------------------------------------------------------
00047 EncodingValidator::EncodingValidator() :
00048     fEncodingRegistry(0)
00049 {
00050     initializeRegistry();
00051 }
00052 
00053 EncodingValidator::~EncodingValidator() {
00054 
00055     delete fEncodingRegistry;
00056     fEncodingRegistry = 0;
00057 }
00058 
00059 // ---------------------------------------------------------------------------
00060 //  EncodingValidator: Validation methods
00061 // ---------------------------------------------------------------------------
00062 bool EncodingValidator::isValidEncoding(const XMLCh* const encName) {
00063 
00064     if (fEncodingRegistry->containsKey(encName))
00065                 return true;
00066 
00067         return false;
00068 }
00069 
00070 
00071 // ---------------------------------------------------------------------------
00072 //  EncodingValidator: Initialization methods
00073 // ---------------------------------------------------------------------------
00074 void EncodingValidator::initializeRegistry() {
00075 
00076     fEncodingRegistry = new ValueHashTableOf<bool>(109);
00077 
00078     for (unsigned int i=0; i < gEncodingArraySize; i++) {
00079         fEncodingRegistry->put((void*) gEncodingArray[i], true);
00080     }
00081 }
00082 
00083 
00084 // ---------------------------------------------------------------------------
00085 //  EncodingValidator: Instance methods
00086 // ---------------------------------------------------------------------------
00087 EncodingValidator* EncodingValidator::instance()
00088 {
00089     return fInstance;
00090 }
00091 
00092 XERCES_CPP_NAMESPACE_END
00093