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

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