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

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

TransService.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 1999, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Log: TransService.hpp,v $
00059  * Revision 1.12  2004/01/29 11:48:46  cargilld
00060  * Code cleanup changes to get rid of various compiler diagnostic messages.
00061  *
00062  * Revision 1.11  2003/12/24 15:24:13  cargilld
00063  * More updates to memory management so that the static memory manager.
00064  *
00065  * Revision 1.10  2003/11/24 19:52:06  neilg
00066  * allow classes derived from XMLTransService to tailor the intrinsic maps to their taste.
00067  *
00068  * Revision 1.9  2003/06/03 18:12:29  knoaman
00069  * Add default value for memory manager argument.
00070  *
00071  * Revision 1.8  2003/05/15 19:07:45  knoaman
00072  * Partial implementation of the configurable memory manager.
00073  *
00074  * Revision 1.7  2003/03/07 18:11:55  tng
00075  * Return a reference instead of void for operator=
00076  *
00077  * Revision 1.6  2003/02/04 22:11:52  peiyongz
00078  * bug#16784: Obsolete documentation on XMLTranscoder -- reported by
00079  * Colin Paul Adams, Preston Lancashire
00080  *
00081  * Revision 1.5  2002/11/25 21:27:52  tng
00082  * Performance: use XMLRecognizer::Encodings enum to make new transcode, faster than comparing the encoding string every time.
00083  *
00084  * Revision 1.4  2002/11/04 15:22:04  tng
00085  * C++ Namespace Support.
00086  *
00087  * Revision 1.3  2002/07/18 20:05:31  knoaman
00088  * Add a new feature to control strict IANA encoding name.
00089  *
00090  * Revision 1.2  2002/04/09 15:44:00  knoaman
00091  * Add lower case string support.
00092  *
00093  * Revision 1.1.1.1  2002/02/01 22:22:13  peiyongz
00094  * sane_include
00095  *
00096  * Revision 1.14  2001/11/01 23:37:07  jasons
00097  * 2001-11-01  Jason E. Stewart  <jason@openinformatics.com>
00098  *
00099  *  * src/util/TransService.hpp (Repository):
00100  *  Updated Doxygen documentation for XMLTranscoder class
00101  *
00102  * Revision 1.13  2001/05/11 13:26:30  tng
00103  * Copyright update.
00104  *
00105  * Revision 1.12  2001/01/25 19:19:32  tng
00106  * Let user add their encoding to the intrinsic mapping table.  Added by Khaled Noaman.
00107  *
00108  * Revision 1.11  2000/04/12 22:57:45  roddey
00109  * A couple of fixes to comments and parameter names to make them
00110  * more correct.
00111  *
00112  * Revision 1.10  2000/03/28 19:43:19  roddey
00113  * Fixes for signed/unsigned warnings. New work for two way transcoding
00114  * stuff.
00115  *
00116  * Revision 1.9  2000/03/17 23:59:54  roddey
00117  * Initial updates for two way transcoding support
00118  *
00119  * Revision 1.8  2000/03/02 19:54:46  roddey
00120  * This checkin includes many changes done while waiting for the
00121  * 1.1.0 code to be finished. I can't list them all here, but a list is
00122  * available elsewhere.
00123  *
00124  * Revision 1.7  2000/02/24 20:05:25  abagchi
00125  * Swat for removing Log from API docs
00126  *
00127  * Revision 1.6  2000/02/06 07:48:04  rahulj
00128  * Year 2K copyright swat.
00129  *
00130  * Revision 1.5  2000/01/25 22:49:55  roddey
00131  * Moved the supportsSrcOfs() method from the individual transcoder to the
00132  * transcoding service, where it should have been to begin with.
00133  *
00134  * Revision 1.4  2000/01/25 19:19:07  roddey
00135  * Simple addition of a getId() method to the xcode and netacess abstractions to
00136  * allow each impl to give back an id string.
00137  *
00138  * Revision 1.3  1999/12/18 00:18:10  roddey
00139  * More changes to support the new, completely orthagonal support for
00140  * intrinsic encodings.
00141  *
00142  * Revision 1.2  1999/12/15 19:41:28  roddey
00143  * Support for the new transcoder system, where even intrinsic encodings are
00144  * done via the same transcoder abstraction as external ones.
00145  *
00146  * Revision 1.1.1.1  1999/11/09 01:05:16  twl
00147  * Initial checkin
00148  *
00149  * Revision 1.2  1999/11/08 20:45:16  rahul
00150  * Swat for adding in Product name and CVS comment log variable.
00151  *
00152  */
00153 
00154 #ifndef TRANSSERVICE_HPP
00155 #define TRANSSERVICE_HPP
00156 
00157 #include <xercesc/util/XMemory.hpp>
00158 #include <xercesc/util/PlatformUtils.hpp>
00159 #include <xercesc/framework/XMLRecognizer.hpp>
00160 #include <xercesc/util/RefHashTableOf.hpp>
00161 #include <xercesc/util/RefVectorOf.hpp>
00162 
00163 XERCES_CPP_NAMESPACE_BEGIN
00164 
00165 // Forward references
00166 //class XMLPlatformUtils;
00167 class XMLLCPTranscoder;
00168 class XMLTranscoder;
00169 class ENameMap;
00170 
00171 
00172 //
00173 //  This class is an abstract base class which are used to abstract the
00174 //  transcoding services that Xerces uses. The parser's actual transcoding
00175 //  needs are small so it is desirable to allow different implementations
00176 //  to be provided.
00177 //
00178 //  The transcoding service has to provide a couple of required string
00179 //  and character operations, but its most important service is the creation
00180 //  of transcoder objects. There are two types of transcoders, which are
00181 //  discussed below in the XMLTranscoder class' description.
00182 //
00183 class  XMLTransService : public XMemory
00184 {
00185 public :
00186     // -----------------------------------------------------------------------
00187     //  Class specific types
00188     // -----------------------------------------------------------------------
00189     enum Codes
00190     {
00191         Ok
00192         , UnsupportedEncoding
00193         , InternalFailure
00194         , SupportFilesNotFound
00195     };
00196 
00197     struct TransRec
00198     {
00199         XMLCh       intCh;
00200         XMLByte     extCh;
00201     };
00202 
00203 
00204     // -----------------------------------------------------------------------
00205     //  Public constructors and destructor
00206     // -----------------------------------------------------------------------
00207     virtual ~XMLTransService();
00208 
00209 
00210     // -----------------------------------------------------------------------
00211     //  Non-virtual API
00212     // -----------------------------------------------------------------------
00213     XMLTranscoder* makeNewTranscoderFor
00214     (
00215         const   XMLCh* const            encodingName
00216         ,       XMLTransService::Codes& resValue
00217         , const unsigned int            blockSize
00218         , MemoryManager* const          manager = XMLPlatformUtils::fgMemoryManager
00219     );
00220 
00221     XMLTranscoder* makeNewTranscoderFor
00222     (
00223         const   char* const             encodingName
00224         ,       XMLTransService::Codes& resValue
00225         , const unsigned int            blockSize
00226         , MemoryManager* const          manager = XMLPlatformUtils::fgMemoryManager
00227     );
00228 
00229     XMLTranscoder* makeNewTranscoderFor
00230     (
00231         XMLRecognizer::Encodings        encodingEnum
00232         ,       XMLTransService::Codes& resValue
00233         , const unsigned int            blockSize
00234         , MemoryManager* const          manager = XMLPlatformUtils::fgMemoryManager
00235     );
00236 
00237 
00238     // -----------------------------------------------------------------------
00239     //  The virtual transcoding service API
00240     // -----------------------------------------------------------------------
00241     virtual int compareIString
00242     (
00243         const   XMLCh* const    comp1
00244         , const XMLCh* const    comp2
00245     ) = 0;
00246 
00247     virtual int compareNIString
00248     (
00249         const   XMLCh* const    comp1
00250         , const XMLCh* const    comp2
00251         , const unsigned int    maxChars
00252     ) = 0;
00253 
00254     virtual const XMLCh* getId() const = 0;
00255 
00256     virtual bool isSpace(const XMLCh toCheck) const = 0;
00257 
00258     virtual XMLLCPTranscoder* makeNewLCPTranscoder() = 0;
00259 
00260     virtual bool supportsSrcOfs() const = 0;
00261 
00262     virtual void upperCase(XMLCh* const toUpperCase) const = 0;
00263     virtual void lowerCase(XMLCh* const toLowerCase) const = 0;
00264 
00265     // -----------------------------------------------------------------------
00266     //  Allow users to add their own encodings to the intrinsinc mapping
00267     //  table
00268     //  Usage:
00269     //      XMLTransService::addEncoding (
00270     //          gMyEncodingNameString
00271     //          , new ENameMapFor<MyTransClassType>(gMyEncodingNameString)
00272     //      );
00273     // -----------------------------------------------------------------------
00274     static void addEncoding(const XMLCh* const encoding, ENameMap* const ownMapping);
00275 
00276 
00277 protected :
00278     // -----------------------------------------------------------------------
00279     //  Hidden constructors
00280     // -----------------------------------------------------------------------
00281     XMLTransService();
00282 
00283 
00284     // -----------------------------------------------------------------------
00285     //  Protected virtual methods.
00286     // -----------------------------------------------------------------------
00287     virtual XMLTranscoder* makeNewXMLTranscoder
00288     (
00289         const   XMLCh* const            encodingName
00290         ,       XMLTransService::Codes& resValue
00291         , const unsigned int            blockSize
00292         , MemoryManager* const          manager
00293     ) = 0;
00294 
00295     // -----------------------------------------------------------------------
00296     //  Protected init method for platform utils to call
00297     // -----------------------------------------------------------------------
00298     friend class XMLPlatformUtils;
00299     virtual void initTransService();
00300 
00301     // -----------------------------------------------------------------------
00302     // protected static members
00303     //  gMappings
00304     //      This is a hash table of ENameMap objects. It is created and filled
00305     //      in when the platform init calls our initTransService() method.
00306     //
00307     //  gMappingsRecognizer
00308     //      This is an array of ENameMap objects, predefined for those
00309     //      already recognized by XMLRecognizer::Encodings.
00310     //
00311 
00312     static RefHashTableOf<ENameMap>*    gMappings;
00313     static RefVectorOf<ENameMap>*       gMappingsRecognizer;
00314 
00315 private :
00316     // -----------------------------------------------------------------------
00317     //  Unimplemented constructors and operators
00318     // -----------------------------------------------------------------------
00319     XMLTransService(const XMLTransService&);
00320     XMLTransService& operator=(const XMLTransService&);
00321 
00322     // -----------------------------------------------------------------------
00323     //  Hidden method to enable/disable strict IANA encoding check
00324     //  Caller: XMLPlatformUtils
00325     // -----------------------------------------------------------------------
00326     void strictIANAEncoding(const bool newState);
00327     bool isStrictIANAEncoding();
00328     static void reinitMappings();
00329     static void reinitMappingsRecognizer();
00330 
00331 };
00332 
00333 
00334 
00351 class  XMLTranscoder : public XMemory
00352 {
00353 public :
00354 
00362     enum UnRepOpts
00363     {
00364         UnRep_Throw     
00365         , UnRep_RepChar     
00366     };
00367 
00368 
00371 
00376     virtual ~XMLTranscoder();
00378 
00379 
00380 
00383 
00403     virtual unsigned int transcodeFrom
00404     (
00405         const   XMLByte* const          srcData
00406         , const unsigned int            srcCount
00407         ,       XMLCh* const            toFill
00408         , const unsigned int            maxChars
00409         ,       unsigned int&           bytesEaten
00410         ,       unsigned char* const    charSizes
00411     ) = 0;
00412 
00426     virtual unsigned int transcodeTo
00427     (
00428         const   XMLCh* const    srcData
00429         , const unsigned int    srcCount
00430         ,       XMLByte* const  toFill
00431         , const unsigned int    maxBytes
00432         ,       unsigned int&   charsEaten
00433         , const UnRepOpts       options
00434     ) = 0;
00435 
00441     virtual bool canTranscodeTo
00442     (
00443         const   unsigned int    toCheck
00444     )   const = 0;
00445 
00447 
00450 
00455     unsigned int getBlockSize() const;
00456 
00462     const XMLCh* getEncodingName() const;
00464 
00467 
00475     MemoryManager* getMemoryManager() const;
00476 
00478 
00479 protected :
00480     // -----------------------------------------------------------------------
00481     //  Hidden constructors
00482     // -----------------------------------------------------------------------
00483     XMLTranscoder
00484     (
00485         const   XMLCh* const    encodingName
00486         , const unsigned int    blockSize
00487         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00488     );
00489 
00490 
00491     // -----------------------------------------------------------------------
00492     //  Protected helper methods
00493     // -----------------------------------------------------------------------
00494     // As the body of this function is commented out it could be removed.
00495     // However, currently all calls to it are guarded by #if defined(XERCES_DEBUG)
00496     // so will leave it for now.
00497     void checkBlockSize(const unsigned int toCheck);
00498 
00499 
00500 private :
00501     // -----------------------------------------------------------------------
00502     //  Unimplemented constructors and operators
00503     // -----------------------------------------------------------------------
00504     XMLTranscoder(const XMLTranscoder&);
00505     XMLTranscoder& operator=(const XMLTranscoder&);
00506 
00507     // -----------------------------------------------------------------------
00508     //  Private data members
00509     //
00510     //  fBlockSize
00511     //      This is the block size indicated in the constructor.
00512     //
00513     //  fEncodingName
00514     //      This is the name of the encoding this encoder is for. All basic
00515     //      XML transcoder's are for named encodings.
00516     // -----------------------------------------------------------------------
00517     unsigned int    fBlockSize;
00518     XMLCh*          fEncodingName;
00519     MemoryManager*  fMemoryManager;
00520 };
00521 
00522 
00523 //
00524 //  This class is a specialized transcoder that only transcodes between
00525 //  the internal XMLCh format and the local code page. It is specialized
00526 //  for the very common job of translating data from the client app's
00527 //  native code page to the internal format and vice versa.
00528 //
00529 class  XMLLCPTranscoder : public XMemory
00530 {
00531 public :
00532     // -----------------------------------------------------------------------
00533     //  Public constructors and destructor
00534     // -----------------------------------------------------------------------
00535     virtual ~XMLLCPTranscoder();
00536 
00537 
00538     // -----------------------------------------------------------------------
00539     //  The virtual transcoder API
00540     //
00541     //  NOTE:   All these APIs don't include null terminator characters in
00542     //          their parameters. So calcRequiredSize() returns the number
00543     //          of actual chars, not including the null. maxBytes and maxChars
00544     //          parameters refer to actual chars, not including the null so
00545     //          its assumed that the buffer is physically one char or byte
00546     //          larger.
00547     // -----------------------------------------------------------------------
00548     virtual unsigned int calcRequiredSize(const char* const srcText
00549         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) = 0;
00550 
00551     virtual unsigned int calcRequiredSize(const XMLCh* const srcText
00552         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) = 0;
00553 
00554     virtual char* transcode(const XMLCh* const toTranscode) = 0;
00555     virtual char* transcode(const XMLCh* const toTranscode,
00556                             MemoryManager* const manager) = 0;
00557 
00558     virtual XMLCh* transcode(const char* const toTranscode) = 0;
00559     virtual XMLCh* transcode(const char* const toTranscode,
00560                              MemoryManager* const manager) = 0;
00561 
00562     virtual bool transcode
00563     (
00564         const   char* const     toTranscode
00565         ,       XMLCh* const    toFill
00566         , const unsigned int    maxChars
00567         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00568     ) = 0;
00569 
00570     virtual bool transcode
00571     (
00572         const   XMLCh* const    toTranscode
00573         ,       char* const     toFill
00574         , const unsigned int    maxBytes
00575         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00576     ) = 0;
00577 
00578 
00579 protected :
00580     // -----------------------------------------------------------------------
00581     //  Hidden constructors
00582     // -----------------------------------------------------------------------
00583     XMLLCPTranscoder();
00584 
00585 
00586 private :
00587     // -----------------------------------------------------------------------
00588     //  Unimplemented constructors and operators
00589     // -----------------------------------------------------------------------
00590     XMLLCPTranscoder(const XMLLCPTranscoder&);
00591     XMLLCPTranscoder& operator=(const XMLLCPTranscoder&);
00592 };
00593 
00594 
00595 // ---------------------------------------------------------------------------
00596 //  XMLTranscoder: Getter methods
00597 // ---------------------------------------------------------------------------
00598 inline MemoryManager* XMLTranscoder::getMemoryManager() const
00599 {
00600     return fMemoryManager;
00601 }
00602 
00603 // ---------------------------------------------------------------------------
00604 //  XMLTranscoder: Protected helper methods
00605 // ---------------------------------------------------------------------------
00606 inline unsigned int XMLTranscoder::getBlockSize() const
00607 {
00608     return fBlockSize;
00609 }
00610 
00611 inline const XMLCh* XMLTranscoder::getEncodingName() const
00612 {
00613     return fEncodingName;
00614 }
00615 
00616 XERCES_CPP_NAMESPACE_END
00617 
00618 #endif


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