www.alphaworks.ibm.comwww.ibm.com/developerwww.ibm.com

Home

Readme
Download

Build







Migration

Releases

Feedback

Y2K Compliance


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.13  2001/05/11 13:26:30  tng
00060  * Copyright update.
00061  *
00062  * Revision 1.12  2001/01/25 19:19:32  tng
00063  * Let user add their encoding to the intrinsic mapping table.  Added by Khaled Noaman.
00064  *
00065  * Revision 1.11  2000/04/12 22:57:45  roddey
00066  * A couple of fixes to comments and parameter names to make them
00067  * more correct.
00068  *
00069  * Revision 1.10  2000/03/28 19:43:19  roddey
00070  * Fixes for signed/unsigned warnings. New work for two way transcoding
00071  * stuff.
00072  *
00073  * Revision 1.9  2000/03/17 23:59:54  roddey
00074  * Initial updates for two way transcoding support
00075  *
00076  * Revision 1.8  2000/03/02 19:54:46  roddey
00077  * This checkin includes many changes done while waiting for the
00078  * 1.1.0 code to be finished. I can't list them all here, but a list is
00079  * available elsewhere.
00080  *
00081  * Revision 1.7  2000/02/24 20:05:25  abagchi
00082  * Swat for removing Log from API docs
00083  *
00084  * Revision 1.6  2000/02/06 07:48:04  rahulj
00085  * Year 2K copyright swat.
00086  *
00087  * Revision 1.5  2000/01/25 22:49:55  roddey
00088  * Moved the supportsSrcOfs() method from the individual transcoder to the
00089  * transcoding service, where it should have been to begin with.
00090  *
00091  * Revision 1.4  2000/01/25 19:19:07  roddey
00092  * Simple addition of a getId() method to the xcode and netacess abstractions to
00093  * allow each impl to give back an id string.
00094  *
00095  * Revision 1.3  1999/12/18 00:18:10  roddey
00096  * More changes to support the new, completely orthagonal support for
00097  * intrinsic encodings.
00098  *
00099  * Revision 1.2  1999/12/15 19:41:28  roddey
00100  * Support for the new transcoder system, where even intrinsic encodings are
00101  * done via the same transcoder abstraction as external ones.
00102  *
00103  * Revision 1.1.1.1  1999/11/09 01:05:16  twl
00104  * Initial checkin
00105  *
00106  * Revision 1.2  1999/11/08 20:45:16  rahul
00107  * Swat for adding in Product name and CVS comment log variable.
00108  *
00109  */
00110 
00111 #ifndef TRANSSERVICE_HPP
00112 #define TRANSSERVICE_HPP
00113 
00114 #include <util/XercesDefs.hpp>
00115 
00116 
00117 // Forward references
00118 class XMLPlatformUtils;
00119 class XMLLCPTranscoder;
00120 class XMLTranscoder;
00121 class ENameMap;
00122 
00123 
00124 //
00125 //  This class is an abstract base class which are used to abstract the
00126 //  transcoding services that Xerces uses. The parser's actual transcoding
00127 //  needs are small so it is desirable to allow different implementations
00128 //  to be provided.
00129 //
00130 //  The transcoding service has to provide a couple of required string
00131 //  and character operations, but its most important service is the creation
00132 //  of transcoder objects. There are two types of transcoders, which are
00133 //  discussed below in the XMLTranscoder class' description.
00134 //
00135 class  XMLTransService
00136 {
00137 public :
00138     // -----------------------------------------------------------------------
00139     //  Class specific types
00140     // -----------------------------------------------------------------------
00141     enum Codes
00142     {
00143         Ok
00144         , UnsupportedEncoding
00145         , InternalFailure
00146         , SupportFilesNotFound
00147     };
00148 
00149     struct TransRec
00150     {
00151         XMLCh       intCh;
00152         XMLByte     extCh;
00153     };
00154 
00155 
00156     // -----------------------------------------------------------------------
00157     //  Public constructors and destructor
00158     // -----------------------------------------------------------------------
00159     virtual ~XMLTransService();
00160 
00161 
00162     // -----------------------------------------------------------------------
00163     //  Non-virtual API
00164     // -----------------------------------------------------------------------
00165     XMLTranscoder* makeNewTranscoderFor
00166     (
00167         const   XMLCh* const            encodingName
00168         ,       XMLTransService::Codes& resValue
00169         , const unsigned int            blockSize
00170     );
00171 
00172     XMLTranscoder* makeNewTranscoderFor
00173     (
00174         const   char* const             encodingName
00175         ,       XMLTransService::Codes& resValue
00176         , const unsigned int            blockSize
00177     );
00178 
00179 
00180     // -----------------------------------------------------------------------
00181     //  The virtual transcoding service API
00182     // -----------------------------------------------------------------------
00183     virtual int compareIString
00184     (
00185         const   XMLCh* const    comp1
00186         , const XMLCh* const    comp2
00187     ) = 0;
00188 
00189     virtual int compareNIString
00190     (
00191         const   XMLCh* const    comp1
00192         , const XMLCh* const    comp2
00193         , const unsigned int    maxChars
00194     ) = 0;
00195 
00196     virtual const XMLCh* getId() const = 0;
00197 
00198     virtual bool isSpace(const XMLCh toCheck) const = 0;
00199 
00200     virtual XMLLCPTranscoder* makeNewLCPTranscoder() = 0;
00201 
00202     virtual bool supportsSrcOfs() const = 0;
00203 
00204     virtual void upperCase(XMLCh* const toUpperCase) const = 0;
00205 
00206     // -----------------------------------------------------------------------
00207     //  Allow users to add their own encodings to the intrinsinc mapping
00208     //  table
00209     //  Usage:
00210     //      XMLTransService::addEncoding (
00211     //          gMyEncodingNameString
00212     //          , new ENameMapFor<MyTransClassType>(gMyEncodingNameString)
00213     //      );
00214     // -----------------------------------------------------------------------
00215     static void addEncoding(const XMLCh* const encoding, ENameMap* const ownMapping);
00216 
00217 
00218 protected :
00219     // -----------------------------------------------------------------------
00220     //  Hidden constructors
00221     // -----------------------------------------------------------------------
00222     XMLTransService();
00223 
00224 
00225     // -----------------------------------------------------------------------
00226     //  Protected virtual methods.
00227     // -----------------------------------------------------------------------
00228     virtual XMLTranscoder* makeNewXMLTranscoder
00229     (
00230         const   XMLCh* const            encodingName
00231         ,       XMLTransService::Codes& resValue
00232         , const unsigned int            blockSize
00233     ) = 0;
00234 
00235 
00236 private :
00237     // -----------------------------------------------------------------------
00238     //  Unimplemented constructors and operators
00239     // -----------------------------------------------------------------------
00240     XMLTransService(const XMLTransService&);
00241     void operator=(const XMLTransService&);
00242 
00243 
00244     // -----------------------------------------------------------------------
00245     //  Hidden init method for platform utils to call
00246     // -----------------------------------------------------------------------
00247     friend class XMLPlatformUtils;
00248     void initTransService();
00249 };
00250 
00251 
00252 
00253 //
00254 //  This type of transcoder is for non-local code page encodings, i.e.
00255 //  named encodings. These are used internally by the scanner to internalize
00256 //  raw XML into the internal Unicode format, and by writer classes to
00257 //  convert that internal Unicode format (which comes out of the parser)
00258 //  back out to a format that the receiving client code wants to use.
00259 //
00260 class  XMLTranscoder
00261 {
00262 public :
00263     // -----------------------------------------------------------------------
00264     //  This enum is used by the transcodeTo() method to indicate how to
00265     //  react to unrepresentable characters. The transcodeFrom() method always
00266     //  works the same. It will consider any invalid data to be an error and
00267     //  throw.
00268     //
00269     //  The options mean:
00270     //      Throw   - Throw an exception
00271     //      RepChar - Use the replacement char
00272     // -----------------------------------------------------------------------
00273     enum UnRepOpts
00274     {
00275         UnRep_Throw
00276         , UnRep_RepChar
00277     };
00278 
00279 
00280     // -----------------------------------------------------------------------
00281     //  Public constructors and destructor
00282     // -----------------------------------------------------------------------
00283     virtual ~XMLTranscoder();
00284 
00285 
00286     // -----------------------------------------------------------------------
00287     //  The virtual transcoding interface
00288     // -----------------------------------------------------------------------
00289     virtual unsigned int transcodeFrom
00290     (
00291         const   XMLByte* const          srcData
00292         , const unsigned int            srcCount
00293         ,       XMLCh* const            toFill
00294         , const unsigned int            maxChars
00295         ,       unsigned int&           bytesEaten
00296         ,       unsigned char* const    charSizes
00297     ) = 0;
00298 
00299     virtual unsigned int transcodeTo
00300     (
00301         const   XMLCh* const    srcData
00302         , const unsigned int    srcCount
00303         ,       XMLByte* const  toFill
00304         , const unsigned int    maxBytes
00305         ,       unsigned int&   charsEaten
00306         , const UnRepOpts       options
00307     ) = 0;
00308 
00309     virtual bool canTranscodeTo
00310     (
00311         const   unsigned int    toCheck
00312     )   const = 0;
00313 
00314 
00315     // -----------------------------------------------------------------------
00316     //  Getter methods
00317     // -----------------------------------------------------------------------
00318     unsigned int getBlockSize() const;
00319 
00320     const XMLCh* getEncodingName() const;
00321 
00322 
00323 protected :
00324     // -----------------------------------------------------------------------
00325     //  Hidden constructors
00326     // -----------------------------------------------------------------------
00327     XMLTranscoder
00328     (
00329         const   XMLCh* const    encodingName
00330         , const unsigned int    blockSize
00331     );
00332 
00333 
00334     // -----------------------------------------------------------------------
00335     //  Protected helper methods
00336     // -----------------------------------------------------------------------
00337     void checkBlockSize(const unsigned int toCheck);
00338 
00339 
00340 private :
00341     // -----------------------------------------------------------------------
00342     //  Unimplemented constructors and operators
00343     // -----------------------------------------------------------------------
00344     XMLTranscoder(const XMLTranscoder&);
00345     void operator=(const XMLTranscoder&);
00346 
00347 
00348     // -----------------------------------------------------------------------
00349     //  Private data members
00350     //
00351     //  fBlockSize
00352     //      This is the block size indicated in the constructor. This lets
00353     //      the derived class preallocate appopriately sized buffers. This
00354     //      sets the maximum number of characters which can be internalized
00355     //      per call to transcodeFrom() and transcodeTo().
00356     //
00357     //  fEncodingName
00358     //      This is the name of the encoding this encoder is for. All basic
00359     //      XML transcoder's are for named encodings.
00360     // -----------------------------------------------------------------------
00361     unsigned int    fBlockSize;
00362     XMLCh*          fEncodingName;
00363 };
00364 
00365 
00366 //
00367 //  This class is a specialized transcoder that only transcodes between
00368 //  the internal XMLCh format and the local code page. It is specialized
00369 //  for the very common job of translating data from the client app's
00370 //  native code page to the internal format and vice versa.
00371 //
00372 class  XMLLCPTranscoder
00373 {
00374 public :
00375     // -----------------------------------------------------------------------
00376     //  Public constructors and destructor
00377     // -----------------------------------------------------------------------
00378     virtual ~XMLLCPTranscoder();
00379 
00380 
00381     // -----------------------------------------------------------------------
00382     //  The virtual transcoder API
00383     //
00384     //  NOTE:   All these APIs don't include null terminator characters in
00385     //          their parameters. So calcRequiredSize() returns the number
00386     //          of actual chars, not including the null. maxBytes and maxChars
00387     //          parameters refer to actual chars, not including the null so
00388     //          its assumed that the buffer is physically one char or byte
00389     //          larger.
00390     // -----------------------------------------------------------------------
00391     virtual unsigned int calcRequiredSize(const char* const srcText) = 0;
00392 
00393     virtual unsigned int calcRequiredSize(const XMLCh* const srcText) = 0;
00394 
00395     virtual char* transcode(const XMLCh* const toTranscode) = 0;
00396 
00397     virtual XMLCh* transcode(const char* const toTranscode) = 0;
00398 
00399     virtual bool transcode
00400     (
00401         const   char* const     toTranscode
00402         ,       XMLCh* const    toFill
00403         , const unsigned int    maxChars
00404     ) = 0;
00405 
00406     virtual bool transcode
00407     (
00408         const   XMLCh* const    toTranscode
00409         ,       char* const     toFill
00410         , const unsigned int    maxBytes
00411     ) = 0;
00412 
00413 
00414 protected :
00415     // -----------------------------------------------------------------------
00416     //  Hidden constructors
00417     // -----------------------------------------------------------------------
00418     XMLLCPTranscoder();
00419 
00420 
00421 private :
00422     // -----------------------------------------------------------------------
00423     //  Unimplemented constructors and operators
00424     // -----------------------------------------------------------------------
00425     XMLLCPTranscoder(const XMLLCPTranscoder&);
00426     void operator=(const XMLLCPTranscoder&);
00427 };
00428 
00429 
00430 // ---------------------------------------------------------------------------
00431 //  XMLTranscoder: Protected helper methods
00432 // ---------------------------------------------------------------------------
00433 inline unsigned int XMLTranscoder::getBlockSize() const
00434 {
00435     return fBlockSize;
00436 }
00437 
00438 inline const XMLCh* XMLTranscoder::getEncodingName() const
00439 {
00440     return fEncodingName;
00441 }
00442 
00443 #endif


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