http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Charter
Release Info

Installation
Download
Build Instructions

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

Source Repository
User Mail Archive
Devel Mail Archive

API Docs for SAX and DOM
 

TransService.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2001,2004 The Apache Software Foundation.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * $Id: TransService.hpp 191054 2005-06-17 02:56:35Z jberry $
00019  */
00020 
00021 #ifndef TRANSSERVICE_HPP
00022 #define TRANSSERVICE_HPP
00023 
00024 #include <xercesc/util/XMemory.hpp>
00025 #include <xercesc/util/PlatformUtils.hpp>
00026 #include <xercesc/framework/XMLRecognizer.hpp>
00027 #include <xercesc/util/RefHashTableOf.hpp>
00028 #include <xercesc/util/RefVectorOf.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // Forward references
00033 //class XMLPlatformUtils;
00034 class XMLLCPTranscoder;
00035 class XMLTranscoder;
00036 class ENameMap;
00037 
00038 
00039 //
00040 //  This class is an abstract base class which are used to abstract the
00041 //  transcoding services that Xerces uses. The parser's actual transcoding
00042 //  needs are small so it is desirable to allow different implementations
00043 //  to be provided.
00044 //
00045 //  The transcoding service has to provide a couple of required string
00046 //  and character operations, but its most important service is the creation
00047 //  of transcoder objects. There are two types of transcoders, which are
00048 //  discussed below in the XMLTranscoder class' description.
00049 //
00050 class  XMLTransService : public XMemory
00051 {
00052 public :
00053     // -----------------------------------------------------------------------
00054     //  Class specific types
00055     // -----------------------------------------------------------------------
00056     enum Codes
00057     {
00058         Ok
00059         , UnsupportedEncoding
00060         , InternalFailure
00061         , SupportFilesNotFound
00062     };
00063 
00064     struct TransRec
00065     {
00066         XMLCh       intCh;
00067         XMLByte     extCh;
00068     };
00069 
00070 
00071     // -----------------------------------------------------------------------
00072     //  Public constructors and destructor
00073     // -----------------------------------------------------------------------
00074     virtual ~XMLTransService();
00075 
00076 
00077     // -----------------------------------------------------------------------
00078     //  Non-virtual API
00079     // -----------------------------------------------------------------------
00080     XMLTranscoder* makeNewTranscoderFor
00081     (
00082         const   XMLCh* const            encodingName
00083         ,       XMLTransService::Codes& resValue
00084         , const unsigned int            blockSize
00085         , MemoryManager* const          manager = XMLPlatformUtils::fgMemoryManager
00086     );
00087 
00088     XMLTranscoder* makeNewTranscoderFor
00089     (
00090         const   char* const             encodingName
00091         ,       XMLTransService::Codes& resValue
00092         , const unsigned int            blockSize
00093         , MemoryManager* const          manager = XMLPlatformUtils::fgMemoryManager
00094     );
00095 
00096     XMLTranscoder* makeNewTranscoderFor
00097     (
00098         XMLRecognizer::Encodings        encodingEnum
00099         ,       XMLTransService::Codes& resValue
00100         , const unsigned int            blockSize
00101         , MemoryManager* const          manager = XMLPlatformUtils::fgMemoryManager
00102     );
00103 
00104 
00105     // -----------------------------------------------------------------------
00106     //  The virtual transcoding service API
00107     // -----------------------------------------------------------------------
00108     virtual int compareIString
00109     (
00110         const   XMLCh* const    comp1
00111         , const XMLCh* const    comp2
00112     ) = 0;
00113 
00114     virtual int compareNIString
00115     (
00116         const   XMLCh* const    comp1
00117         , const XMLCh* const    comp2
00118         , const unsigned int    maxChars
00119     ) = 0;
00120 
00121     virtual const XMLCh* getId() const = 0;
00122 
00123     virtual bool isSpace(const XMLCh toCheck) const = 0;
00124 
00125     virtual XMLLCPTranscoder* makeNewLCPTranscoder() = 0;
00126 
00127     virtual bool supportsSrcOfs() const = 0;
00128 
00129     virtual void upperCase(XMLCh* const toUpperCase) const = 0;
00130     virtual void lowerCase(XMLCh* const toLowerCase) const = 0;
00131 
00132     // -----------------------------------------------------------------------
00133     //  Allow users to add their own encodings to the intrinsinc mapping
00134     //  table
00135     //  Usage:
00136     //      XMLTransService::addEncoding (
00137     //          gMyEncodingNameString
00138     //          , new ENameMapFor<MyTransClassType>(gMyEncodingNameString)
00139     //      );
00140     // -----------------------------------------------------------------------
00141     static void addEncoding(const XMLCh* const encoding, ENameMap* const ownMapping);
00142 
00143 
00144 protected :
00145     // -----------------------------------------------------------------------
00146     //  Hidden constructors
00147     // -----------------------------------------------------------------------
00148     XMLTransService();
00149 
00150 
00151     // -----------------------------------------------------------------------
00152     //  Protected virtual methods.
00153     // -----------------------------------------------------------------------
00154     virtual XMLTranscoder* makeNewXMLTranscoder
00155     (
00156         const   XMLCh* const            encodingName
00157         ,       XMLTransService::Codes& resValue
00158         , const unsigned int            blockSize
00159         , MemoryManager* const          manager
00160     ) = 0;
00161 
00162     // -----------------------------------------------------------------------
00163     //  Protected init method for platform utils to call
00164     // -----------------------------------------------------------------------
00165     friend class XMLPlatformUtils;
00166     virtual void initTransService();
00167 
00168     // -----------------------------------------------------------------------
00169     // protected static members
00170     //  gMappings
00171     //      This is a hash table of ENameMap objects. It is created and filled
00172     //      in when the platform init calls our initTransService() method.
00173     //
00174     //  gMappingsRecognizer
00175     //      This is an array of ENameMap objects, predefined for those
00176     //      already recognized by XMLRecognizer::Encodings.
00177     //
00178 
00179     static RefHashTableOf<ENameMap>*    gMappings;
00180     static RefVectorOf<ENameMap>*       gMappingsRecognizer;
00181 
00182 private :
00183     // -----------------------------------------------------------------------
00184     //  Unimplemented constructors and operators
00185     // -----------------------------------------------------------------------
00186     XMLTransService(const XMLTransService&);
00187     XMLTransService& operator=(const XMLTransService&);
00188 
00189     // -----------------------------------------------------------------------
00190     //  Hidden method to enable/disable strict IANA encoding check
00191     //  Caller: XMLPlatformUtils
00192     // -----------------------------------------------------------------------
00193     void strictIANAEncoding(const bool newState);
00194     bool isStrictIANAEncoding();
00195     static void reinitMappings();
00196     static void reinitMappingsRecognizer();
00197 
00198 };
00199 
00200 
00201 
00218 class  XMLTranscoder : public XMemory
00219 {
00220 public :
00221 
00229     enum UnRepOpts
00230     {
00231         UnRep_Throw     
00232         , UnRep_RepChar     
00233     };
00234 
00235 
00238 
00243     virtual ~XMLTranscoder();
00245 
00246 
00247 
00250 
00270     virtual unsigned int transcodeFrom
00271     (
00272         const   XMLByte* const          srcData
00273         , const unsigned int            srcCount
00274         ,       XMLCh* const            toFill
00275         , const unsigned int            maxChars
00276         ,       unsigned int&           bytesEaten
00277         ,       unsigned char* const    charSizes
00278     ) = 0;
00279 
00293     virtual unsigned int transcodeTo
00294     (
00295         const   XMLCh* const    srcData
00296         , const unsigned int    srcCount
00297         ,       XMLByte* const  toFill
00298         , const unsigned int    maxBytes
00299         ,       unsigned int&   charsEaten
00300         , const UnRepOpts       options
00301     ) = 0;
00302 
00308     virtual bool canTranscodeTo
00309     (
00310         const   unsigned int    toCheck
00311     )   const = 0;
00312 
00314 
00317 
00322     unsigned int getBlockSize() const;
00323 
00329     const XMLCh* getEncodingName() const;
00331 
00334 
00342     MemoryManager* getMemoryManager() const;
00343 
00345 
00346 protected :
00347     // -----------------------------------------------------------------------
00348     //  Hidden constructors
00349     // -----------------------------------------------------------------------
00350     XMLTranscoder
00351     (
00352         const   XMLCh* const    encodingName
00353         , const unsigned int    blockSize
00354         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00355     );
00356 
00357 
00358     // -----------------------------------------------------------------------
00359     //  Protected helper methods
00360     // -----------------------------------------------------------------------
00361     // As the body of this function is commented out it could be removed.
00362     // However, currently all calls to it are guarded by #if defined(XERCES_DEBUG)
00363     // so will leave it for now.
00364     void checkBlockSize(const unsigned int toCheck);
00365 
00366 
00367 private :
00368     // -----------------------------------------------------------------------
00369     //  Unimplemented constructors and operators
00370     // -----------------------------------------------------------------------
00371     XMLTranscoder(const XMLTranscoder&);
00372     XMLTranscoder& operator=(const XMLTranscoder&);
00373 
00374     // -----------------------------------------------------------------------
00375     //  Private data members
00376     //
00377     //  fBlockSize
00378     //      This is the block size indicated in the constructor.
00379     //
00380     //  fEncodingName
00381     //      This is the name of the encoding this encoder is for. All basic
00382     //      XML transcoder's are for named encodings.
00383     // -----------------------------------------------------------------------
00384     unsigned int    fBlockSize;
00385     XMLCh*          fEncodingName;
00386     MemoryManager*  fMemoryManager;
00387 };
00388 
00389 
00390 //
00391 //  This class is a specialized transcoder that only transcodes between
00392 //  the internal XMLCh format and the local code page. It is specialized
00393 //  for the very common job of translating data from the client app's
00394 //  native code page to the internal format and vice versa.
00395 //
00396 class  XMLLCPTranscoder : public XMemory
00397 {
00398 public :
00399     // -----------------------------------------------------------------------
00400     //  Public constructors and destructor
00401     // -----------------------------------------------------------------------
00402     virtual ~XMLLCPTranscoder();
00403 
00404 
00405     // -----------------------------------------------------------------------
00406     //  The virtual transcoder API
00407     //
00408     //  NOTE:   All these APIs don't include null terminator characters in
00409     //          their parameters. So calcRequiredSize() returns the number
00410     //          of actual chars, not including the null. maxBytes and maxChars
00411     //          parameters refer to actual chars, not including the null so
00412     //          its assumed that the buffer is physically one char or byte
00413     //          larger.
00414     // -----------------------------------------------------------------------
00415     virtual unsigned int calcRequiredSize(const char* const srcText
00416         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) = 0;
00417 
00418     virtual unsigned int calcRequiredSize(const XMLCh* const srcText
00419         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) = 0;
00420 
00421     virtual char* transcode(const XMLCh* const toTranscode) = 0;
00422     virtual char* transcode(const XMLCh* const toTranscode,
00423                             MemoryManager* const manager) = 0;
00424 
00425     virtual XMLCh* transcode(const char* const toTranscode) = 0;
00426     virtual XMLCh* transcode(const char* const toTranscode,
00427                              MemoryManager* const manager) = 0;
00428 
00429     virtual bool transcode
00430     (
00431         const   char* const     toTranscode
00432         ,       XMLCh* const    toFill
00433         , const unsigned int    maxChars
00434         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00435     ) = 0;
00436 
00437     virtual bool transcode
00438     (
00439         const   XMLCh* const    toTranscode
00440         ,       char* const     toFill
00441         , const unsigned int    maxBytes
00442         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00443     ) = 0;
00444 
00445 
00446 protected :
00447     // -----------------------------------------------------------------------
00448     //  Hidden constructors
00449     // -----------------------------------------------------------------------
00450     XMLLCPTranscoder();
00451 
00452 
00453 private :
00454     // -----------------------------------------------------------------------
00455     //  Unimplemented constructors and operators
00456     // -----------------------------------------------------------------------
00457     XMLLCPTranscoder(const XMLLCPTranscoder&);
00458     XMLLCPTranscoder& operator=(const XMLLCPTranscoder&);
00459 };
00460 
00461 
00462 // ---------------------------------------------------------------------------
00463 //  XMLTranscoder: Getter methods
00464 // ---------------------------------------------------------------------------
00465 inline MemoryManager* XMLTranscoder::getMemoryManager() const
00466 {
00467     return fMemoryManager;
00468 }
00469 
00470 // ---------------------------------------------------------------------------
00471 //  XMLTranscoder: Protected helper methods
00472 // ---------------------------------------------------------------------------
00473 inline unsigned int XMLTranscoder::getBlockSize() const
00474 {
00475     return fBlockSize;
00476 }
00477 
00478 inline const XMLCh* XMLTranscoder::getEncodingName() const
00479 {
00480     return fEncodingName;
00481 }
00482 
00483 XERCES_CPP_NAMESPACE_END
00484 
00485 #endif


Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.