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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback
Bug-Todo

Download
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-2000 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  2001/01/25 19:19:32  tng

00060  * Let user add their encoding to the intrinsic mapping table.  Added by Khaled Noaman.

00061  *
00062  * Revision 1.11  2000/04/12 22:57:45  roddey

00063  * A couple of fixes to comments and parameter names to make them

00064  * more correct.

00065  *
00066  * Revision 1.10  2000/03/28 19:43:19  roddey

00067  * Fixes for signed/unsigned warnings. New work for two way transcoding

00068  * stuff.

00069  *
00070  * Revision 1.9  2000/03/17 23:59:54  roddey

00071  * Initial updates for two way transcoding support

00072  *
00073  * Revision 1.8  2000/03/02 19:54:46  roddey

00074  * This checkin includes many changes done while waiting for the

00075  * 1.1.0 code to be finished. I can't list them all here, but a list is

00076  * available elsewhere.

00077  *
00078  * Revision 1.7  2000/02/24 20:05:25  abagchi

00079  * Swat for removing Log from API docs

00080  *
00081  * Revision 1.6  2000/02/06 07:48:04  rahulj

00082  * Year 2K copyright swat.

00083  *
00084  * Revision 1.5  2000/01/25 22:49:55  roddey

00085  * Moved the supportsSrcOfs() method from the individual transcoder to the

00086  * transcoding service, where it should have been to begin with.

00087  *
00088  * Revision 1.4  2000/01/25 19:19:07  roddey

00089  * Simple addition of a getId() method to the xcode and netacess abstractions to

00090  * allow each impl to give back an id string.

00091  *
00092  * Revision 1.3  1999/12/18 00:18:10  roddey

00093  * More changes to support the new, completely orthagonal support for

00094  * intrinsic encodings.

00095  *
00096  * Revision 1.2  1999/12/15 19:41:28  roddey

00097  * Support for the new transcoder system, where even intrinsic encodings are

00098  * done via the same transcoder abstraction as external ones.

00099  *
00100  * Revision 1.1.1.1  1999/11/09 01:05:16  twl

00101  * Initial checkin

00102  *
00103  * Revision 1.2  1999/11/08 20:45:16  rahul

00104  * Swat for adding in Product name and CVS comment log variable.

00105  *
00106  */
00107 
00108 #ifndef TRANSSERVICE_HPP
00109 #define TRANSSERVICE_HPP
00110 
00111 #include <util/XercesDefs.hpp>
00112 
00113 
00114 // Forward references
00115 class XMLPlatformUtils;
00116 class XMLLCPTranscoder;
00117 class XMLTranscoder;
00118 class ENameMap;
00119 
00120 
00121 //
00122 //  This class is an abstract base class which are used to abstract the
00123 //  transcoding services that Xerces uses. The parser's actual transcoding
00124 //  needs are small so it is desirable to allow different implementations
00125 //  to be provided.
00126 //
00127 //  The transcoding service has to provide a couple of required string
00128 //  and character operations, but its most important service is the creation
00129 //  of transcoder objects. There are two types of transcoders, which are
00130 //  discussed below in the XMLTranscoder class' description.
00131 //
00132 class  XMLTransService
00133 {
00134 public :
00135     // -----------------------------------------------------------------------
00136     //  Class specific types
00137     // -----------------------------------------------------------------------
00138     enum Codes
00139     {
00140         Ok
00141         , UnsupportedEncoding
00142         , InternalFailure
00143         , SupportFilesNotFound
00144     };
00145 
00146     struct TransRec
00147     {
00148         XMLCh       intCh;
00149         XMLByte     extCh;
00150     };
00151 
00152 
00153     // -----------------------------------------------------------------------
00154     //  Public constructors and destructor
00155     // -----------------------------------------------------------------------
00156     virtual ~XMLTransService();
00157 
00158 
00159     // -----------------------------------------------------------------------
00160     //  Non-virtual API
00161     // -----------------------------------------------------------------------
00162     XMLTranscoder* makeNewTranscoderFor
00163     (
00164         const   XMLCh* const            encodingName
00165         ,       XMLTransService::Codes& resValue
00166         , const unsigned int            blockSize
00167     );
00168 
00169     XMLTranscoder* makeNewTranscoderFor
00170     (
00171         const   char* const             encodingName
00172         ,       XMLTransService::Codes& resValue
00173         , const unsigned int            blockSize
00174     );
00175 
00176 
00177     // -----------------------------------------------------------------------
00178     //  The virtual transcoding service API
00179     // -----------------------------------------------------------------------
00180     virtual int compareIString
00181     (
00182         const   XMLCh* const    comp1
00183         , const XMLCh* const    comp2
00184     ) = 0;
00185 
00186     virtual int compareNIString
00187     (
00188         const   XMLCh* const    comp1
00189         , const XMLCh* const    comp2
00190         , const unsigned int    maxChars
00191     ) = 0;
00192 
00193     virtual const XMLCh* getId() const = 0;
00194 
00195     virtual bool isSpace(const XMLCh toCheck) const = 0;
00196 
00197     virtual XMLLCPTranscoder* makeNewLCPTranscoder() = 0;
00198 
00199     virtual bool supportsSrcOfs() const = 0;
00200 
00201     virtual void upperCase(XMLCh* const toUpperCase) const = 0;
00202 
00203     // -----------------------------------------------------------------------
00204     //  Allow users to add their own encodings to the intrinsinc mapping
00205     //  table
00206     //  Usage:
00207     //      XMLTransService::addEncoding (
00208     //          gMyEncodingNameString
00209     //          , new ENameMapFor<MyTransClassType>(gMyEncodingNameString)
00210     //      );
00211     // -----------------------------------------------------------------------
00212     static void addEncoding(const XMLCh* const encoding, ENameMap* const ownMapping);
00213 
00214 
00215 protected :
00216     // -----------------------------------------------------------------------
00217     //  Hidden constructors
00218     // -----------------------------------------------------------------------
00219     XMLTransService();
00220 
00221 
00222     // -----------------------------------------------------------------------
00223     //  Protected virtual methods.
00224     // -----------------------------------------------------------------------
00225     virtual XMLTranscoder* makeNewXMLTranscoder
00226     (
00227         const   XMLCh* const            encodingName
00228         ,       XMLTransService::Codes& resValue
00229         , const unsigned int            blockSize
00230     ) = 0;
00231 
00232 
00233 private :
00234     // -----------------------------------------------------------------------
00235     //  Unimplemented constructors and operators
00236     // -----------------------------------------------------------------------
00237     XMLTransService(const XMLTransService&);
00238     void operator=(const XMLTransService&);
00239 
00240 
00241     // -----------------------------------------------------------------------
00242     //  Hidden init method for platform utils to call
00243     // -----------------------------------------------------------------------
00244     friend class XMLPlatformUtils;
00245     void initTransService();
00246 };
00247 
00248 
00249 
00250 //
00251 //  This type of transcoder is for non-local code page encodings, i.e.
00252 //  named encodings. These are used internally by the scanner to internalize
00253 //  raw XML into the internal Unicode format, and by writer classes to
00254 //  convert that internal Unicode format (which comes out of the parser)
00255 //  back out to a format that the receiving client code wants to use.
00256 //
00257 class  XMLTranscoder
00258 {
00259 public :
00260     // -----------------------------------------------------------------------
00261     //  This enum is used by the transcodeTo() method to indicate how to
00262     //  react to unrepresentable characters. The transcodeFrom() method always
00263     //  works the same. It will consider any invalid data to be an error and
00264     //  throw.
00265     //
00266     //  The options mean:
00267     //      Throw   - Throw an exception
00268     //      RepChar - Use the replacement char
00269     // -----------------------------------------------------------------------
00270     enum UnRepOpts
00271     {
00272         UnRep_Throw
00273         , UnRep_RepChar
00274     };
00275 
00276 
00277     // -----------------------------------------------------------------------
00278     //  Public constructors and destructor
00279     // -----------------------------------------------------------------------
00280     virtual ~XMLTranscoder();
00281 
00282 
00283     // -----------------------------------------------------------------------
00284     //  The virtual transcoding interface
00285     // -----------------------------------------------------------------------
00286     virtual unsigned int transcodeFrom
00287     (
00288         const   XMLByte* const          srcData
00289         , const unsigned int            srcCount
00290         ,       XMLCh* const            toFill
00291         , const unsigned int            maxChars
00292         ,       unsigned int&           bytesEaten
00293         ,       unsigned char* const    charSizes
00294     ) = 0;
00295 
00296     virtual unsigned int transcodeTo
00297     (
00298         const   XMLCh* const    srcData
00299         , const unsigned int    srcCount
00300         ,       XMLByte* const  toFill
00301         , const unsigned int    maxBytes
00302         ,       unsigned int&   charsEaten
00303         , const UnRepOpts       options
00304     ) = 0;
00305 
00306     virtual bool canTranscodeTo
00307     (
00308         const   unsigned int    toCheck
00309     )   const = 0;
00310 
00311 
00312     // -----------------------------------------------------------------------
00313     //  Getter methods
00314     // -----------------------------------------------------------------------
00315     unsigned int getBlockSize() const;
00316 
00317     const XMLCh* getEncodingName() const;
00318 
00319 
00320 protected :
00321     // -----------------------------------------------------------------------
00322     //  Hidden constructors
00323     // -----------------------------------------------------------------------
00324     XMLTranscoder
00325     (
00326         const   XMLCh* const    encodingName
00327         , const unsigned int    blockSize
00328     );
00329 
00330 
00331     // -----------------------------------------------------------------------
00332     //  Protected helper methods
00333     // -----------------------------------------------------------------------
00334     void checkBlockSize(const unsigned int toCheck);
00335 
00336 
00337 private :
00338     // -----------------------------------------------------------------------
00339     //  Unimplemented constructors and operators
00340     // -----------------------------------------------------------------------
00341     XMLTranscoder(const XMLTranscoder&);
00342     void operator=(const XMLTranscoder&);
00343 
00344 
00345     // -----------------------------------------------------------------------
00346     //  Private data members
00347     //
00348     //  fBlockSize
00349     //      This is the block size indicated in the constructor. This lets
00350     //      the derived class preallocate appopriately sized buffers. This
00351     //      sets the maximum number of characters which can be internalized
00352     //      per call to transcodeFrom() and transcodeTo().
00353     //
00354     //  fEncodingName
00355     //      This is the name of the encoding this encoder is for. All basic
00356     //      XML transcoder's are for named encodings.
00357     // -----------------------------------------------------------------------
00358     unsigned int    fBlockSize;
00359     XMLCh*          fEncodingName;
00360 };
00361 
00362 
00363 //
00364 //  This class is a specialized transcoder that only transcodes between
00365 //  the internal XMLCh format and the local code page. It is specialized
00366 //  for the very common job of translating data from the client app's
00367 //  native code page to the internal format and vice versa.
00368 //
00369 class  XMLLCPTranscoder
00370 {
00371 public :
00372     // -----------------------------------------------------------------------
00373     //  Public constructors and destructor
00374     // -----------------------------------------------------------------------
00375     virtual ~XMLLCPTranscoder();
00376 
00377 
00378     // -----------------------------------------------------------------------
00379     //  The virtual transcoder API
00380     //
00381     //  NOTE:   All these APIs don't include null terminator characters in
00382     //          their parameters. So calcRequiredSize() returns the number
00383     //          of actual chars, not including the null. maxBytes and maxChars
00384     //          parameters refer to actual chars, not including the null so
00385     //          its assumed that the buffer is physically one char or byte
00386     //          larger.
00387     // -----------------------------------------------------------------------
00388     virtual unsigned int calcRequiredSize(const char* const srcText) = 0;
00389 
00390     virtual unsigned int calcRequiredSize(const XMLCh* const srcText) = 0;
00391 
00392     virtual char* transcode(const XMLCh* const toTranscode) = 0;
00393 
00394     virtual XMLCh* transcode(const char* const toTranscode) = 0;
00395 
00396     virtual bool transcode
00397     (
00398         const   char* const     toTranscode
00399         ,       XMLCh* const    toFill
00400         , const unsigned int    maxChars
00401     ) = 0;
00402 
00403     virtual bool transcode
00404     (
00405         const   XMLCh* const    toTranscode
00406         ,       char* const     toFill
00407         , const unsigned int    maxBytes
00408     ) = 0;
00409 
00410 
00411 protected :
00412     // -----------------------------------------------------------------------
00413     //  Hidden constructors
00414     // -----------------------------------------------------------------------
00415     XMLLCPTranscoder();
00416 
00417 
00418 private :
00419     // -----------------------------------------------------------------------
00420     //  Unimplemented constructors and operators
00421     // -----------------------------------------------------------------------
00422     XMLLCPTranscoder(const XMLLCPTranscoder&);
00423     void operator=(const XMLLCPTranscoder&);
00424 };
00425 
00426 
00427 // ---------------------------------------------------------------------------
00428 //  XMLTranscoder: Protected helper methods
00429 // ---------------------------------------------------------------------------
00430 inline unsigned int XMLTranscoder::getBlockSize() const

00431 {
00432     return fBlockSize;
00433 }
00434 
00435 inline const XMLCh* XMLTranscoder::getEncodingName() const

00436 {
00437     return fEncodingName;
00438 }
00439 
00440 #endif


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