Main Page   Class Hierarchy   Compound List   File List   Compound Members  

TransService.hpp

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.1  2002/05/11 21:14:53  bhavani
00060  * CR#CR062582# adding xercesc 1.7 file
00061  *
00062  * Revision 1.1.1.1  2002/02/01 22:22:13  peiyongz
00063  * sane_include
00064  *
00065  * Revision 1.14  2001/11/01 23:37:07  jasons
00066  * 2001-11-01  Jason E. Stewart  <jason@openinformatics.com>
00067  *
00068  *      * src/util/TransService.hpp (Repository):
00069  *      Updated Doxygen documentation for XMLTranscoder class
00070  *
00071  * Revision 1.13  2001/05/11 13:26:30  tng
00072  * Copyright update.
00073  *
00074  * Revision 1.12  2001/01/25 19:19:32  tng
00075  * Let user add their encoding to the intrinsic mapping table.  Added by Khaled Noaman.
00076  *
00077  * Revision 1.11  2000/04/12 22:57:45  roddey
00078  * A couple of fixes to comments and parameter names to make them
00079  * more correct.
00080  *
00081  * Revision 1.10  2000/03/28 19:43:19  roddey
00082  * Fixes for signed/unsigned warnings. New work for two way transcoding
00083  * stuff.
00084  *
00085  * Revision 1.9  2000/03/17 23:59:54  roddey
00086  * Initial updates for two way transcoding support
00087  *
00088  * Revision 1.8  2000/03/02 19:54:46  roddey
00089  * This checkin includes many changes done while waiting for the
00090  * 1.1.0 code to be finished. I can't list them all here, but a list is
00091  * available elsewhere.
00092  *
00093  * Revision 1.7  2000/02/24 20:05:25  abagchi
00094  * Swat for removing Log from API docs
00095  *
00096  * Revision 1.6  2000/02/06 07:48:04  rahulj
00097  * Year 2K copyright swat.
00098  *
00099  * Revision 1.5  2000/01/25 22:49:55  roddey
00100  * Moved the supportsSrcOfs() method from the individual transcoder to the
00101  * transcoding service, where it should have been to begin with.
00102  *
00103  * Revision 1.4  2000/01/25 19:19:07  roddey
00104  * Simple addition of a getId() method to the xcode and netacess abstractions to
00105  * allow each impl to give back an id string.
00106  *
00107  * Revision 1.3  1999/12/18 00:18:10  roddey
00108  * More changes to support the new, completely orthagonal support for
00109  * intrinsic encodings.
00110  *
00111  * Revision 1.2  1999/12/15 19:41:28  roddey
00112  * Support for the new transcoder system, where even intrinsic encodings are
00113  * done via the same transcoder abstraction as external ones.
00114  *
00115  * Revision 1.1.1.1  1999/11/09 01:05:16  twl
00116  * Initial checkin
00117  *
00118  * Revision 1.2  1999/11/08 20:45:16  rahul
00119  * Swat for adding in Product name and CVS comment log variable.
00120  *
00121  */
00122 
00123 #ifndef TRANSSERVICE_HPP
00124 #define TRANSSERVICE_HPP
00125 
00126 #include <xercesc/util/XercesDefs.hpp>
00127 
00128 
00129 // Forward references
00130 class XMLPlatformUtils;
00131 class XMLLCPTranscoder;
00132 class XMLTranscoder;
00133 class ENameMap;
00134 
00135 
00136 //
00137 //  This class is an abstract base class which are used to abstract the
00138 //  transcoding services that Xerces uses. The parser's actual transcoding
00139 //  needs are small so it is desirable to allow different implementations
00140 //  to be provided.
00141 //
00142 //  The transcoding service has to provide a couple of required string
00143 //  and character operations, but its most important service is the creation
00144 //  of transcoder objects. There are two types of transcoders, which are
00145 //  discussed below in the XMLTranscoder class' description.
00146 //
00147 class XMLUTIL_EXPORT XMLTransService
00148 {
00149 public :
00150     // -----------------------------------------------------------------------
00151     //  Class specific types
00152     // -----------------------------------------------------------------------
00153     enum Codes
00154     {
00155         Ok
00156         , UnsupportedEncoding
00157         , InternalFailure
00158         , SupportFilesNotFound
00159     };
00160 
00161     struct TransRec
00162     {
00163         XMLCh       intCh;
00164         XMLByte     extCh;
00165     };
00166 
00167 
00168     // -----------------------------------------------------------------------
00169     //  Public constructors and destructor
00170     // -----------------------------------------------------------------------
00171     virtual ~XMLTransService();
00172 
00173 
00174     // -----------------------------------------------------------------------
00175     //  Non-virtual API
00176     // -----------------------------------------------------------------------
00177     XMLTranscoder* makeNewTranscoderFor
00178     (
00179         const   XMLCh* const            encodingName
00180         ,       XMLTransService::Codes& resValue
00181         , const unsigned int            blockSize
00182     );
00183 
00184     XMLTranscoder* makeNewTranscoderFor
00185     (
00186         const   char* const             encodingName
00187         ,       XMLTransService::Codes& resValue
00188         , const unsigned int            blockSize
00189     );
00190 
00191 
00192     // -----------------------------------------------------------------------
00193     //  The virtual transcoding service API
00194     // -----------------------------------------------------------------------
00195     virtual int compareIString
00196     (
00197         const   XMLCh* const    comp1
00198         , const XMLCh* const    comp2
00199     ) = 0;
00200 
00201     virtual int compareNIString
00202     (
00203         const   XMLCh* const    comp1
00204         , const XMLCh* const    comp2
00205         , const unsigned int    maxChars
00206     ) = 0;
00207 
00208     virtual const XMLCh* getId() const = 0;
00209 
00210     virtual bool isSpace(const XMLCh toCheck) const = 0;
00211 
00212     virtual XMLLCPTranscoder* makeNewLCPTranscoder() = 0;
00213 
00214     virtual bool supportsSrcOfs() const = 0;
00215 
00216     virtual void upperCase(XMLCh* const toUpperCase) const = 0;
00217 
00218         // -----------------------------------------------------------------------
00219     //  Allow users to add their own encodings to the intrinsinc mapping
00220         //      table
00221         //      Usage:
00222         //              XMLTransService::addEncoding (
00223         //                      gMyEncodingNameString
00224     //                  , new ENameMapFor<MyTransClassType>(gMyEncodingNameString)
00225         //              );
00226     // -----------------------------------------------------------------------
00227         static void addEncoding(const XMLCh* const encoding, ENameMap* const ownMapping);
00228 
00229 
00230 protected :
00231     // -----------------------------------------------------------------------
00232     //  Hidden constructors
00233     // -----------------------------------------------------------------------
00234     XMLTransService();
00235 
00236 
00237     // -----------------------------------------------------------------------
00238     //  Protected virtual methods.
00239     // -----------------------------------------------------------------------
00240     virtual XMLTranscoder* makeNewXMLTranscoder
00241     (
00242         const   XMLCh* const            encodingName
00243         ,       XMLTransService::Codes& resValue
00244         , const unsigned int            blockSize
00245     ) = 0;
00246 
00247 
00248 private :
00249     // -----------------------------------------------------------------------
00250     //  Unimplemented constructors and operators
00251     // -----------------------------------------------------------------------
00252     XMLTransService(const XMLTransService&);
00253     void operator=(const XMLTransService&);
00254 
00255 
00256     // -----------------------------------------------------------------------
00257     //  Hidden init method for platform utils to call
00258     // -----------------------------------------------------------------------
00259     friend class XMLPlatformUtils;
00260     void initTransService();
00261 };
00262 
00263 
00264 
00281 class XMLUTIL_EXPORT XMLTranscoder
00282 {
00283 public :
00284 
00292     enum UnRepOpts
00293     {
00294         UnRep_Throw             
00295         , UnRep_RepChar         
00296     };
00297 
00298 
00301 
00306     virtual ~XMLTranscoder();
00308 
00309 
00310 
00313 
00333     virtual unsigned int transcodeFrom
00334     (
00335         const   XMLByte* const          srcData
00336         , const unsigned int            srcCount
00337         ,       XMLCh* const            toFill
00338         , const unsigned int            maxChars
00339         ,       unsigned int&           bytesEaten
00340         ,       unsigned char* const    charSizes
00341     ) = 0;
00342 
00356     virtual unsigned int transcodeTo
00357     (
00358         const   XMLCh* const    srcData
00359         , const unsigned int    srcCount
00360         ,       XMLByte* const  toFill
00361         , const unsigned int    maxBytes
00362         ,       unsigned int&   charsEaten
00363         , const UnRepOpts       options
00364     ) = 0;
00365 
00371     virtual bool canTranscodeTo
00372     (
00373         const   unsigned int    toCheck
00374     )   const = 0;
00375 
00377 
00380 
00389     unsigned int getBlockSize() const;
00390 
00396     const XMLCh* getEncodingName() const;
00398 
00399 protected :
00400     // -----------------------------------------------------------------------
00401     //  Hidden constructors
00402     // -----------------------------------------------------------------------
00403     XMLTranscoder
00404     (
00405         const   XMLCh* const    encodingName
00406         , const unsigned int    blockSize
00407     );
00408 
00409 
00410     // -----------------------------------------------------------------------
00411     //  Protected helper methods
00412     // -----------------------------------------------------------------------
00413     void checkBlockSize(const unsigned int toCheck);
00414 
00415 
00416 private :
00417     // -----------------------------------------------------------------------
00418     //  Unimplemented constructors and operators
00419     // -----------------------------------------------------------------------
00420     XMLTranscoder(const XMLTranscoder&);
00421     void operator=(const XMLTranscoder&);
00422 
00423 
00424     // -----------------------------------------------------------------------
00425     //  Private data members
00426     //
00427     //  fBlockSize
00428     //      This is the block size indicated in the constructor. This lets
00429     //      the derived class preallocate appopriately sized buffers. This
00430     //      sets the maximum number of characters which can be internalized
00431     //      per call to transcodeFrom() and transcodeTo().
00432     //
00433     //  fEncodingName
00434     //      This is the name of the encoding this encoder is for. All basic
00435     //      XML transcoder's are for named encodings.
00436     // -----------------------------------------------------------------------
00437     unsigned int    fBlockSize;
00438     XMLCh*          fEncodingName;
00439 };
00440 
00441 
00442 //
00443 //  This class is a specialized transcoder that only transcodes between
00444 //  the internal XMLCh format and the local code page. It is specialized
00445 //  for the very common job of translating data from the client app's
00446 //  native code page to the internal format and vice versa.
00447 //
00448 class XMLUTIL_EXPORT XMLLCPTranscoder
00449 {
00450 public :
00451     // -----------------------------------------------------------------------
00452     //  Public constructors and destructor
00453     // -----------------------------------------------------------------------
00454     virtual ~XMLLCPTranscoder();
00455 
00456 
00457     // -----------------------------------------------------------------------
00458     //  The virtual transcoder API
00459     //
00460     //  NOTE:   All these APIs don't include null terminator characters in
00461     //          their parameters. So calcRequiredSize() returns the number
00462     //          of actual chars, not including the null. maxBytes and maxChars
00463     //          parameters refer to actual chars, not including the null so
00464     //          its assumed that the buffer is physically one char or byte
00465     //          larger.
00466     // -----------------------------------------------------------------------
00467     virtual unsigned int calcRequiredSize(const char* const srcText) = 0;
00468 
00469     virtual unsigned int calcRequiredSize(const XMLCh* const srcText) = 0;
00470 
00471     virtual char* transcode(const XMLCh* const toTranscode) = 0;
00472 
00473     virtual XMLCh* transcode(const char* const toTranscode) = 0;
00474 
00475     virtual bool transcode
00476     (
00477         const   char* const     toTranscode
00478         ,       XMLCh* const    toFill
00479         , const unsigned int    maxChars
00480     ) = 0;
00481 
00482     virtual bool transcode
00483     (
00484         const   XMLCh* const    toTranscode
00485         ,       char* const     toFill
00486         , const unsigned int    maxBytes
00487     ) = 0;
00488 
00489 
00490 protected :
00491     // -----------------------------------------------------------------------
00492     //  Hidden constructors
00493     // -----------------------------------------------------------------------
00494     XMLLCPTranscoder();
00495 
00496 
00497 private :
00498     // -----------------------------------------------------------------------
00499     //  Unimplemented constructors and operators
00500     // -----------------------------------------------------------------------
00501     XMLLCPTranscoder(const XMLLCPTranscoder&);
00502     void operator=(const XMLLCPTranscoder&);
00503 };
00504 
00505 
00506 // ---------------------------------------------------------------------------
00507 //  XMLTranscoder: Protected helper methods
00508 // ---------------------------------------------------------------------------
00509 inline unsigned int XMLTranscoder::getBlockSize() const
00510 {
00511     return fBlockSize;
00512 }
00513 
00514 inline const XMLCh* XMLTranscoder::getEncodingName() const
00515 {
00516     return fEncodingName;
00517 }
00518 
00519 #endif

Generated on Tue Nov 19 09:36:33 2002 by doxygen1.3-rc1