dbertoni    00/09/27 09:24:32

  Modified:    c/src/PlatformSupport DOMStringHelper.cpp
                        DOMStringHelper.hpp DoubleSupport.cpp
                        DoubleSupport.hpp PlatformSupportInit.cpp
                        URISupport.cpp Writer.cpp Writer.hpp
  Added:       c/src/PlatformSupport XalanFileOutputStream.cpp
                        XalanFileOutputStream.hpp XalanNullOutputStream.cpp
                        XalanNullOutputStream.hpp XalanOutputStream.cpp
                        XalanOutputStream.hpp
                        XalanOutputStreamPrintWriter.cpp
                        XalanOutputStreamPrintWriter.hpp
                        XalanStdOutputStream.cpp XalanStdOutputStream.hpp
                        XalanToXercesTranscoderWrapper.cpp
                        XalanToXercesTranscoderWrapper.hpp
                        XalanTranscodingServices.cpp
                        XalanTranscodingServices.hpp
                        XalanUTF16Transcoder.cpp XalanUTF16Transcoder.hpp
  Removed:     c/src/PlatformSupport TextOutputStream.cpp
                        TextOutputStream.hpp
  Log:
  Output transcoding support.
  
  Revision  Changes    Path
  1.35      +176 -30   xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp
  
  Index: DOMStringHelper.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- DOMStringHelper.cpp       2000/09/20 18:19:22     1.34
  +++ DOMStringHelper.cpp       2000/09/27 16:23:35     1.35
  @@ -98,7 +98,7 @@
   
   #include "DoubleSupport.hpp"
   #include "STLHelper.hpp"
  -#include "TextOutputStream.hpp"
  +#include "XalanOutputStream.hpp"
   #include "XalanAutoPtr.hpp"
   #include "XalanUnicode.hpp"
   
  @@ -406,7 +406,7 @@
   
   
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  -OutputString(TextOutputStream&               theStream,
  +OutputString(XalanOutputStream&              theStream,
                         const CharVectorType&  theString)
   {
        if (theString.size() > 0)
  @@ -435,7 +435,7 @@
   
   
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  -OutputString(TextOutputStream&               theStream,
  +OutputString(XalanOutputStream&              theStream,
                         const XalanDOMChar*    theString)
   {
        if (theString != 0)
  @@ -757,13 +757,13 @@
   
   
   
  -template <class Type>
  +template <class Type, class SizeType>
   int
   doCompare(
                        const Type*             theLHS,
  -                     unsigned int    theLHSLength,
  +                     SizeType                theLHSLength,
                        const Type*             theRHS,
  -                     unsigned int    theRHSLength)
  +                     SizeType                theRHSLength)
   {
        int                                     theResult = 0;
   
  @@ -772,7 +772,7 @@
                Type            theLHSChar = Type(0);
                Type            theRHSChar = Type(0);
   
  -             unsigned int    i = 0;
  +             SizeType        i = 0;
   
                for(; i < theLHSLength && i < theRHSLength; i++)
                {
  @@ -1550,9 +1550,11 @@
   
   
   
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  -TranscodeToLocalCodePage(
  +static bool
  +doTranscodeToLocalCodePage(
                        const XalanDOMChar*             sourceString,
  +                     unsigned int                    sourceStringLength,
  +                     bool                                    
sourceStringIsNullTerminated,
                        CharVectorType&                 targetVector,
                        bool                                    terminate)
   {
  @@ -1562,49 +1564,120 @@
                if (terminate == true)
                {
                        targetVector.resize(1);
  +
  +                     targetVector.back() = '\0';
                }
                else
                {
  -                     targetVector.resize(1);
  +                     targetVector.resize(0);
                }
   
           return true;
        }
   
  -     const unsigned int                      len = length(sourceString);
  +     const XalanDOMChar*             tempSource = 0;
   
  +     // If our char sizes are not the same, we have to use a temp buffer.
        XalanArrayAutoPtr<wchar_t>      tempSourceJanitor;
   
  -     const XalanDOMChar*                     tempSource = sourceString;
  +#if !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH)
  +     // This is a short-cut for when the sourceString is mull-terminated 
_and_
  +     // XalanDOMChar and wchar_t are the same thing.
  +     if (sourceStringIsNullTerminated == true)
  +     {
  +             tempSource = sourceString;
  +     }
  +     else
  +#endif
  +     {
  +             if (sourceStringIsNullTerminated == true)
  +             {
  +                     sourceStringLength = length(sourceString);
  +             }
   
  -    // See if our XalanDOMChar and wchar_t as the same on this platform
  -    if (sizeof(XalanDOMChar) != sizeof(wchar_t))
  -    {
  -             //
  -             //  If either the passed length was non-zero or our char sizes 
are not 
  -             //  same, we have to use a temp buffer.
  -             //
  -             tempSourceJanitor.reset(new wchar_t[len + 1]);
  +             tempSourceJanitor.reset(new wchar_t[sourceStringLength + 1]);
   
  -        for (unsigned int index = 0; index < len; index++)
  +             for (unsigned int index = 0; index < sourceStringLength; 
++index)
                {
  -            tempSourceJanitor[index] = wchar_t(sourceString[index]);
  +                     tempSourceJanitor[index] = wchar_t(sourceString[index]);
                }
   
  -             tempSourceJanitor[len] = 0;
  +             tempSourceJanitor[sourceStringLength] = 0;
   
                tempSource = tempSourceJanitor.get();
  -    }
  +     }
   
  -    // See now many chars we need to transcode this guy
  +    // See now many chars we need to transcode.
       const unsigned int targetLen = ::wcstombs(0, tempSource, 0);
   
  -     targetVector.resize(targetLen);
  +     // Resize, adding one byte if terminating...
  +     targetVector.resize(terminate == true ? targetLen + 1 : targetLen);
   
  +    //  And transcode our temp source buffer to the local buffer. Terminate
       //
  -    //  And transcode our temp source buffer to the local buffer. Cap it
  -    //  off since the converter won't do it (because the null is beyond
  -    //  where the target will fill up.)
  +    if (wcstombs(&targetVector[0], tempSource, targetLen) == size_t(-1))
  +     {
  +             return false;
  +     }
  +     else
  +     {
  +             if (terminate == true)
  +             {
  +                     targetVector.back() = '\0';
  +             }
  +
  +             return true;
  +     }
  +}
  +
  +
  +
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  +TranscodeToLocalCodePage(
  +                     const XalanDOMChar*             sourceString,
  +                     unsigned int                    sourceStringLength,
  +                     CharVectorType&                 targetVector,
  +                     bool                                    terminate)
  +{
  +#if 1
  +     return doTranscodeToLocalCodePage(sourceString, sourceStringLength, 
false, targetVector, terminate);
  +#else
  +    // Short circuit if it's a null pointer, or of length 0.
  +    if (!sourceString || (!sourceString[0]))
  +    {
  +             if (terminate == true)
  +             {
  +                     targetVector.resize(1);
  +
  +                     targetVector.back() = '\0';
  +             }
  +             else
  +             {
  +                     targetVector.resize(0);
  +             }
  +
  +        return true;
  +     }
  +
  +     // If our char sizes are not the same, we have to use a temp buffer.
  +     XalanArrayAutoPtr<wchar_t>      tempSourceJanitor(new 
wchar_t[sourceStringLength + 1]);
  +
  +     for (unsigned int index = 0; index < sourceStringLength; ++index)
  +     {
  +             tempSourceJanitor[index] = wchar_t(sourceString[index]);
  +     }
  +
  +     tempSourceJanitor[sourceStringLength] = 0;
  +
  +     const XalanDOMChar*     const   tempSource = tempSourceJanitor.get();
  +
  +    // See now many chars we need to transcode.
  +    const unsigned int targetLen = ::wcstombs(0, tempSource, 0);
  +
  +     // Resize, adding one byte if terminating...
  +     targetVector.resize(terminate == true ? targetLen + 1 : targetLen);
  +
  +    //  And transcode our temp source buffer to the local buffer. Terminate
       //
       if (wcstombs(&targetVector[0], tempSource, targetLen) == size_t(-1))
        {
  @@ -1614,9 +1687,82 @@
        {
                if (terminate == true)
                {
  -                     targetVector.resize(targetVector.size() + 1);
  +                     targetVector.back() = '\0';
                }
   
                return true;
        }
  +#endif
  +}
  +
  +
  +
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  +TranscodeToLocalCodePage(
  +                     const XalanDOMChar*             sourceString,
  +                     CharVectorType&                 targetVector,
  +                     bool                                    terminate)
  +{
  +#if 1
  +     return doTranscodeToLocalCodePage(sourceString, 0, true, targetVector, 
terminate);
  +#else
  +    // Short circuit if it's a null pointer, or of length 0.
  +    if (!sourceString || (!sourceString[0]))
  +    {
  +             if (terminate == true)
  +             {
  +                     targetVector.resize(1);
  +
  +                     targetVector.back() = '\0';
  +             }
  +             else
  +             {
  +                     targetVector.resize(0);
  +             }
  +
  +        return true;
  +     }
  +
  +#if !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH)
  +     const XalanDOMChar*     const   tempSource = sourceString;
  +#else
  +    assert(sizeof(XalanDOMChar) != sizeof(wchar_t));
  +
  +     const unsigned int                      len = length(sourceString);
  +
  +     // If our char sizes are not the same, we have to use a temp buffer.
  +     XalanArrayAutoPtr<wchar_t>      tempSourceJanitor(new wchar_t[len + 1]);
  +
  +     for (unsigned int index = 0; index < len; ++index)
  +     {
  +             tempSourceJanitor[index] = wchar_t(sourceString[index]);
  +     }
  +
  +     tempSourceJanitor[len] = 0;
  +
  +     const XalanDOMChar*     const   tempSource = tempSourceJanitor.get();
  +#endif
  +
  +    // See now many chars we need to transcode.
  +    const unsigned int targetLen = ::wcstombs(0, tempSource, 0);
  +
  +     // Resize, adding one byte if terminating...
  +     targetVector.resize(terminate == true ? targetLen + 1 : targetLen);
  +
  +    //  And transcode our temp source buffer to the local buffer. Terminate
  +    //
  +    if (wcstombs(&targetVector[0], tempSource, targetLen) == size_t(-1))
  +     {
  +             return false;
  +     }
  +     else
  +     {
  +             if (terminate == true)
  +             {
  +                     targetVector.back() = '\0';
  +             }
  +
  +             return true;
  +     }
  +#endif
   }
  
  
  
  1.30      +35 -14    xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp
  
  Index: DOMStringHelper.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- DOMStringHelper.hpp       2000/09/19 14:43:23     1.29
  +++ DOMStringHelper.hpp       2000/09/27 16:23:55     1.30
  @@ -92,7 +92,7 @@
   
   
   
  -class TextOutputStream;
  +class XalanOutputStream;
   
   
   
  @@ -704,7 +704,7 @@
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
   OutputString(
  -                     TextOutputStream&               theStream,
  +                     XalanOutputStream&              theStream,
                        const CharVectorType&   theString);
   
   
  @@ -736,7 +736,7 @@
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
   OutputString(
  -                     TextOutputStream&               theStream,
  +                     XalanOutputStream&              theStream,
                        const XalanDOMChar*             theString);
   
   
  @@ -768,7 +768,7 @@
    */
   inline void
   OutputString(
  -                     TextOutputStream&               theStream,
  +                     XalanOutputStream&              theStream,
                        const XalanDOMString&   theString)
   {
        if (isEmpty(theString) == false)
  @@ -807,9 +807,9 @@
    * @param theString the string to output
    * @see OutputString
    */
  -inline TextOutputStream&
  +inline XalanOutputStream&
   operator<<(
  -                     TextOutputStream&               theStream,
  +                     XalanOutputStream&              theStream,
                        const CharVectorType&   theString)
   {
        OutputString(theStream, theString);
  @@ -851,9 +851,9 @@
    * @param theString target string
    * @see OutputString
    */
  -inline TextOutputStream&
  +inline XalanOutputStream&
   operator<<(
  -                     TextOutputStream&               theStream,
  +                     XalanOutputStream&              theStream,
                        const XalanDOMChar*             theString)
   {
        OutputString(theStream,
  @@ -897,9 +897,9 @@
    * @param theString target string
    * @see OutputString
    */
  -inline TextOutputStream&
  +inline XalanOutputStream&
   operator<<(
  -                     TextOutputStream&               theStream,
  +                     XalanOutputStream&              theStream,
                        const XalanDOMString&   theString)
   {
        OutputString(theStream,
  @@ -1963,11 +1963,12 @@
   
   
   /**
  - * Convert XalanDOMString to C++ standard library
  + * Convert a XalanDOMChar string to C++ standard library
    * vector, transcoding to the default local code
    * page.
    * 
    * @param sourceString The source string
  + * @param sourceStringLength The source string length.
    * @param targetVector The target string
    * @param terminate If true, the transcoded string will be null-terminated
    * @return true if successful, false if not.
  @@ -1975,12 +1976,31 @@
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
   TranscodeToLocalCodePage(
                        const XalanDOMChar*             sourceString,
  +                     unsigned int                    sourceStringLength,
                        CharVectorType&                 targetVector,
                        bool                                    terminate = 
false);
   
   
   
   /**
  + * Convert a XalanDOMChar string to C++ standard library
  + * vector, transcoding to the default local code
  + * page.  The string _must_ be null-terminated.
  + * 
  + * @param sourceString The source string
  + * @param targetVector The target string
  + * @param terminate If true, the transcoded string will be null-terminated
  + * @return true if successful, false if not.
  + */
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  +TranscodeToLocalCodePage(
  +                     const XalanDOMChar*             sourceString,
  +                     CharVectorType&                 targetVector,
  +                     bool                                    terminate = 
false);
  +
  +
  +
  +/**
    * Convert XalanDOMString to C++ standard library
    * vector, transcoding to the default local code
    * page.  Null-terminate the sttring...
  @@ -2012,9 +2032,10 @@
   inline bool
   TranscodeToLocalCodePage(
                        const XalanDOMString&   sourceString,
  -                     CharVectorType&                 targetVector)
  +                     CharVectorType&                 targetVector,
  +                     bool                                    terminate = 
false)
   {
  -     return TranscodeToLocalCodePage(c_wstr(sourceString), targetVector);
  +     return TranscodeToLocalCodePage(c_wstr(sourceString), targetVector, 
terminate);
   }
   
   
  @@ -2032,7 +2053,7 @@
   {
        CharVectorType  theResult;
   
  -     TranscodeToLocalCodePage(sourceString, theResult);
  +     TranscodeToLocalCodePage(sourceString, theResult, true);
   
        return theResult;
   }
  
  
  
  1.13      +38 -58    xml-xalan/c/src/PlatformSupport/DoubleSupport.cpp
  
  Index: DoubleSupport.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DoubleSupport.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DoubleSupport.cpp 2000/09/19 14:43:24     1.12
  +++ DoubleSupport.cpp 2000/09/27 16:23:57     1.13
  @@ -57,61 +57,22 @@
   #include "DoubleSupport.hpp"
   
   
  -#if defined(NO_STD_LIMITS)
  -#    if defined(__GNUC__)
  -#            include <math.h>
  -#            if defined(SOLARIS)
  -#                    include <nan.h>
  -#            else
  -#                    include <bits/nan.h>
  -#            endif
  -#    else
  -#            error Unsupported platform!!!
  -#    endif
  -#else
  -#    include <limits>
  -#endif
   
  +#include <cmath>
   
   
  +
   #include "DOMStringHelper.hpp"
   #include "XalanUnicode.hpp"
   
   
  -
  -#if defined(NO_STD_LIMITS)
  -#    if defined(__GNUC__)
  -
  -#            if defined(SOLARIS)
  -                     static const unsigned char      __nan_bits[] = { 0x7f, 
0xf0,0xc0,0x0,0x0,0x0,0x0,0x0 };
  -                     const double                            
DoubleSupport::s_NaN = *reinterpret_cast<const double*>(__nan_bits);
  -#            else
  -                     const double    DoubleSupport::s_NaN = NAN;
  -#            endif
  -
  -             const double    DoubleSupport::s_positiveInfinity = HUGE_VAL;
  -             const double    DoubleSupport::s_negativeInfinity = -HUGE_VAL;
  -
  -#    else
  -#            error Unsupported platform!!!
  -#    endif
  -#else
  -
  -#if defined(XALAN_NO_NAMESPACES)
  -typedef numeric_limits<double>                       NumericLimitsType;
  -#else
  -typedef std::numeric_limits<double>          NumericLimitsType;
  -#endif
  -
  -const double DoubleSupport::s_NaN = NumericLimitsType::quiet_NaN();
  -const double DoubleSupport::s_positiveInfinity = 
NumericLimitsType::infinity();
  -const double DoubleSupport::s_negativeInfinity = 
NumericLimitsType::signaling_NaN();
   
  -#endif
  +const double DoubleSupport::s_NaN = sqrt(-2);
  +const double DoubleSupport::s_positiveInfinity = HUGE_VAL;
  +const double DoubleSupport::s_negativeInfinity = 
-DoubleSupport::s_positiveInfinity;
   
   
   
  -#if defined(XALAN_NEED_SPECIAL_NAN_SUPPORT)
   const unsigned long* DoubleSupport::s_NaNFirstDWORD =
   #if defined(XALAN_OLD_STYLE_CASTS)
                                        (const unsigned long*)&s_NaN;
  @@ -121,7 +82,6 @@
   
   const unsigned long* DoubleSupport::s_NaNSecondDWORD =
                                        s_NaNFirstDWORD + 1;
  -#endif
   
   
   
  @@ -232,10 +192,14 @@
                        double  theLHS,
                        double  theRHS)
   {
  -     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     if (isNaN(theLHS) == true)
        {
  -             return getNaN();
  +             return theLHS;
        }
  +     else if (isNaN(theRHS) == true)
  +     {
  +             return theRHS;
  +     }
        else
        {
                return theLHS + theRHS;
  @@ -249,9 +213,13 @@
                        double  theLHS,
                        double  theRHS)
   {
  -     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     if (isNaN(theLHS) == true)
  +     {
  +             return theLHS;
  +     }
  +     else if (isNaN(theRHS) == true)
        {
  -             return getNaN();
  +             return theRHS;
        }
        else
        {
  @@ -266,9 +234,13 @@
                        double  theLHS,
                        double  theRHS)
   {
  -     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     if (isNaN(theLHS) == true)
  +     {
  +             return theLHS;
  +     }
  +     else if (isNaN(theRHS) == true)
        {
  -             return getNaN();
  +             return theRHS;
        }
        else
        {
  @@ -283,11 +255,15 @@
                        double  theLHS,
                        double  theRHS)
   {
  -     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     if (isNaN(theLHS) == true)
  +     {
  +             return theLHS;
  +     }
  +     else if (isNaN(theRHS) == true)
        {
  -             return getNaN();
  +             return theRHS;
        }
  -     else if (theRHS != 0)
  +     else if (theRHS != 0.0L)
        {
                return theLHS / theRHS;
        }
  @@ -295,12 +271,12 @@
        {
                // These are special cases, since we can't actually
                // do the division...
  -             if (theLHS == 0)
  +             if (theLHS == 0.0L)
                {
                        // This is NaN...
                        return DoubleSupport::getNaN();
                }
  -             else if (theLHS > 0.0)
  +             else if (theLHS > 0.0L)
                {
                        // This is positive infinity...
                        return DoubleSupport::getPositiveInfinity();
  @@ -320,9 +296,13 @@
                        double  theLHS,
                        double  theRHS)
   {
  -     if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  +     if (isNaN(theLHS) == true)
  +     {
  +             return theLHS;
  +     }
  +     else if (isNaN(theRHS) == true)
        {
  -             return getNaN();
  +             return theRHS;
        }
        else
        {
  
  
  
  1.6       +0 -12     xml-xalan/c/src/PlatformSupport/DoubleSupport.hpp
  
  Index: DoubleSupport.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DoubleSupport.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DoubleSupport.hpp 2000/07/10 01:04:09     1.5
  +++ DoubleSupport.hpp 2000/09/27 16:23:59     1.6
  @@ -91,9 +91,6 @@
        static bool
        isNaN(double    theNumber)
        {
  -#if !defined(XALAN_NEED_SPECIAL_NAN_SUPPORT)
  -             return theNumber == s_NaN;
  -#else
                // Compare the two DWORDs of the double as unsigned longs.
                const unsigned long* const      theFirstDWORD =
                        reinterpret_cast<const unsigned long*>(&theNumber);
  @@ -103,7 +100,6 @@
   
                return *theFirstDWORD == *s_NaNFirstDWORD &&
                           *theSecondDWORD == *s_NaNSecondDWORD;
  -#endif
        }
   
        /**
  @@ -115,11 +111,7 @@
        static bool
        isPositiveInfinity(double       theNumber)
        {
  -#if !defined(XALAN_NEED_SPECIAL_NAN_SUPPORT)
  -             return theNumber == s_positiveInfinity;
  -#else
                return !isNaN(theNumber) && theNumber == s_positiveInfinity;
  -#endif
        }
   
        /**
  @@ -131,11 +123,7 @@
        static bool
        isNegativeInfinity(double       theNumber)
        {
  -#if !defined(XALAN_NEED_SPECIAL_NAN_SUPPORT)
  -             return theNumber == s_negativeInfinity;
  -#else
                return !isNaN(theNumber) && theNumber == s_negativeInfinity;
  -#endif
        }
   
        // These can be used to initialize values, but should not
  
  
  
  1.3       +5 -0      xml-xalan/c/src/PlatformSupport/PlatformSupportInit.cpp
  
  Index: PlatformSupportInit.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/PlatformSupportInit.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PlatformSupportInit.cpp   2000/09/05 02:24:45     1.2
  +++ PlatformSupportInit.cpp   2000/09/27 16:24:01     1.3
  @@ -64,6 +64,7 @@
   #include "PrintWriter.hpp"
   #include "URISupport.hpp"
   #include "XalanNumberFormat.hpp"
  +#include "XalanTranscodingServices.hpp"
   
   
   
  @@ -101,6 +102,8 @@
   {
        DOMStringHelperInitialize();
   
  +     XalanTranscodingServices::initialize();
  +
        PrintWriter::initialize();
   
        NamedNodeMapAttributeList::initialize();
  @@ -122,6 +125,8 @@
        NamedNodeMapAttributeList::terminate();
   
        PrintWriter::terminate();
  +
  +     XalanTranscodingServices::terminate();
   
        DOMStringHelperTerminate();
   }
  
  
  
  1.10      +31 -28    xml-xalan/c/src/PlatformSupport/URISupport.cpp
  
  Index: URISupport.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/URISupport.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- URISupport.cpp    2000/09/19 14:43:26     1.9
  +++ URISupport.cpp    2000/09/27 16:24:07     1.10
  @@ -84,7 +84,6 @@
   
   
   
  -
   XalanDOMString
   URISupport::getURLStringFromString(const XalanDOMString&     urlString)
   {
  @@ -92,43 +91,47 @@
   
        // Let's see what sort of URI we have...
        const unsigned int      len = length(theNormalizedURI);
  -     const unsigned int      index = indexOf(theNormalizedURI, 
XalanUnicode::charColon);
  -
  -     bool                            protocolPresent = false;
   
  -     if (index != len)
  +     if (len != 0)
        {
  -             // $$$ ToDo: XMLURL::lookupByName() is supposed to be static, 
but is not.
  -             const XMLURL::Protocols         theProtocol =
  -                     
XMLURL().lookupByName(c_wstr(substring(theNormalizedURI, 0 , index)));
  +             const unsigned int      index = indexOf(theNormalizedURI, 
XalanUnicode::charColon);
  +
  +             bool                            protocolPresent = false;
   
  -             if (theProtocol != XMLURL::Unknown)
  +             if (index != len)
                {
  -                     protocolPresent = true;
  +                     // $$$ ToDo: XMLURL::lookupByName() is supposed to be 
static, but is not.
  +                     const XMLURL::Protocols         theProtocol =
  +                             
XMLURL().lookupByName(c_wstr(substring(theNormalizedURI, 0 , index)));
  +
  +                     if (theProtocol != XMLURL::Unknown)
  +                     {
  +                             protocolPresent = true;
  +                     }
                }
  -     }
   
  -     if (protocolPresent == true)
  -     {
  -             NormalizeURIText(theNormalizedURI);
  -     }
  -     else
  -     {
  -             // Assume it's a file specification...
  -             XalanArrayAutoPtr<XMLCh>        
theFullPath(XMLPlatformUtils::getFullPath(c_wstr(urlString)));
  -             assert(theFullPath.get() != 0);
  +             if (protocolPresent == true)
  +             {
  +                     NormalizeURIText(theNormalizedURI);
  +             }
  +             else
  +             {
  +                     // Assume it's a file specification...
  +                     XalanArrayAutoPtr<XMLCh>        
theFullPath(XMLPlatformUtils::getFullPath(c_wstr(urlString)));
  +                     assert(theFullPath.get() != 0);
   
  -             theNormalizedURI = theFullPath.get();
  -             assert(length(theNormalizedURI) > 0);
  +                     theNormalizedURI = theFullPath.get();
  +                     assert(length(theNormalizedURI) > 0);
   
  -             NormalizeURIText(theNormalizedURI);
  +                     NormalizeURIText(theNormalizedURI);
   
  -             const XalanDOMString    theFilePrefix(
  -                                     indexOf(theNormalizedURI, 
XalanUnicode::charSolidus) == 0 ?
  -                                     s_fileProtocolString1 :
  -                                     s_fileProtocolString2);
  +                     const XalanDOMString    theFilePrefix(
  +                                             indexOf(theNormalizedURI, 
XalanUnicode::charSolidus) == 0 ?
  +                                             s_fileProtocolString1 :
  +                                             s_fileProtocolString2);
   
  -             theNormalizedURI = theFilePrefix + theNormalizedURI;
  +                     theNormalizedURI = theFilePrefix + theNormalizedURI;
  +             }
        }
   
        return theNormalizedURI;
  
  
  
  1.3       +2 -2      xml-xalan/c/src/PlatformSupport/Writer.cpp
  
  Index: Writer.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/Writer.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Writer.cpp        2000/09/19 14:43:48     1.2
  +++ Writer.cpp        2000/09/27 16:24:08     1.3
  @@ -71,7 +71,7 @@
   
   
   
  -TextOutputStream*
  +XalanOutputStream*
   Writer::getStream()
   {
        return 0;
  @@ -79,7 +79,7 @@
   
   
   
  -const TextOutputStream*
  +const XalanOutputStream*
   Writer::getStream() const
   {
        return 0;
  
  
  
  1.10      +3 -3      xml-xalan/c/src/PlatformSupport/Writer.hpp
  
  Index: Writer.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/Writer.hpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Writer.hpp        2000/09/19 14:43:49     1.9
  +++ Writer.hpp        2000/09/27 16:24:09     1.10
  @@ -73,7 +73,7 @@
   
   
   
  -class TextOutputStream;
  +class XalanOutputStream;
   
   
   
  @@ -102,13 +102,13 @@
        /**
         * Get the stream associated with the writer...
         */
  -     virtual TextOutputStream*
  +     virtual XalanOutputStream*
        getStream();
   
        /**
         * Get the stream associated with the writer...
         */
  -     virtual const TextOutputStream*
  +     virtual const XalanOutputStream*
        getStream() const;
   
   
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanFileOutputStream.cpp
  
  Index: XalanFileOutputStream.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file...
  #include "XalanFileOutputStream.hpp"
  
  
  
  #include <cerrno>
  #include <strstream>
  
  
  
  #include <PlatformSupport/DOMStringHelper.hpp>
  #include <PlatformSupport/XalanAutoPtr.hpp>
  
  
  
  
  XalanFileOutputStream::XalanFileOutputStream(const XalanDOMString&            
theFileName) :
        XalanOutputStream(),
        m_fileName(theFileName),
        m_handle(0)
  {
        const XalanArrayAutoPtr<char>   tmpName(theFileName.transcode());
  
        m_handle = fopen(tmpName.get(), "wb");
  
      if (m_handle == 0)
        {
                throw XalanFileOutputStreamOpenException(theFileName,
                                                                                
                errno);
        }
  }
  
  
  
  XalanFileOutputStream::~XalanFileOutputStream()
  {
      if (m_handle != 0)
        {
                fclose(m_handle);
        }
  }
  
  
  
  void
  XalanFileOutputStream::doFlush()
  {
        fflush(m_handle);
  }
  
  
  
  void
  XalanFileOutputStream::writeData(
                        const char*             theBuffer,
                        unsigned long   theBufferLength)
  {
        const size_t    theBytesWritten =
                fwrite(theBuffer,
                           1,
                           theBufferLength,
                           m_handle);
  
        if(theBytesWritten != theBufferLength)
        {
                throw XalanFileOutputStreamWriteException(m_fileName,
                                                                                
                 errno);
        }
  }
  
  
  
  static XalanDOMString
  FormatMessageLocal(
                        const XalanDOMString&   theMessage,
                        const XalanDOMString&   theFileName,
                        int                                     theErrorCode)
  {
        XalanDOMString  theResult(clone(theMessage));
  
        theResult += theFileName;
  
  #if !defined(XALAN_NO_NAMESPACES)
  using std::ostrstream;
  #endif
  
        ostrstream      theFormatter;
  
        theFormatter << ".  The error code was "
                                 << theErrorCode << "." << '\0';
  
        theResult += theFormatter.str();
  
        delete theFormatter.str();
        return theResult;
  }
  
  
  
  
XalanFileOutputStream::XalanFileOutputStreamOpenException::XalanFileOutputStreamOpenException(
                const XalanDOMString&   theFileName,
                int                                     theErrorCode) :
        XalanOutputStreamException(FormatMessageLocal(
                                "Error opening file: ",
                                theFileName,
                                theErrorCode),
                        
XALAN_STATIC_UCODE_STRING("XalanFileOutputStreamOpenException"))
  {
  }
  
  
  
  
XalanFileOutputStream::XalanFileOutputStreamOpenException::~XalanFileOutputStreamOpenException()
  {
  }
  
  
  
  
XalanFileOutputStream::XalanFileOutputStreamWriteException::XalanFileOutputStreamWriteException(
                const XalanDOMString&   theFileName,
                int                                     theErrorCode) :
        XalanOutputStreamException(FormatMessageLocal(
                                "Error writing file: ",
                                theFileName,
                                theErrorCode),
                        
XALAN_STATIC_UCODE_STRING("XalanFileOutputStreamWriteException"))
  {
  }
  
  
  
  
XalanFileOutputStream::XalanFileOutputStreamWriteException::~XalanFileOutputStreamWriteException()
  {
  }
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanFileOutputStream.hpp
  
  Index: XalanFileOutputStream.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANFILEOUTPUTSTREAM_HEADER_GUARD_1357924680)
  #define XALANFILEOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  #include <cstdio>
  #include <vector>
  
  
  
  // Base class header file.
  #include <PlatformSupport/XalanOutputStream.hpp>
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanFileOutputStream : public 
XalanOutputStream
  {
  public :
  
        /**
         * Construct an XalanFileOutputStream exception object.
         * 
         * @param theFileName name of file causing the exception
         */
      XalanFileOutputStream(const XalanDOMString&               theFileName);
  
      virtual
        ~XalanFileOutputStream();
  
  
        class XALAN_PLATFORMSUPPORT_EXPORT XalanFileOutputStreamOpenException : 
public XalanOutputStream::XalanOutputStreamException
        {
        public:
  
                /**
                 * Construct an XalanFileOutputStreamOpen exception object for 
an exception
                 * that occurred on opening a text file stream.
                 * 
                 * @param theFileName  name of file causing the exception
                 * @param theErrorCode number of error encountered
                 */
                XalanFileOutputStreamOpenException(
                        const XalanDOMString&   theFileName,
                        int                                             
theErrorCode);
  
                virtual
                ~XalanFileOutputStreamOpenException();
        };
  
        class XALAN_PLATFORMSUPPORT_EXPORT XalanFileOutputStreamWriteException 
: public XalanOutputStream::XalanOutputStreamException
        {
        public:
  
                /**
                 * Construct an XalanFileOutputStreamOpen exception object for 
an exception
                 * that occurred while writing to a text file stream.
                 * 
                 * @param theFileName  name of file causing the exception
                 * @param theErrorCode number of error encountered
                 */
                XalanFileOutputStreamWriteException(
                        const XalanDOMString&   theFileName,
                        int                                             
theErrorCode);
  
                virtual
                ~XalanFileOutputStreamWriteException();
        };
  
  protected:
  
        virtual void
        writeData(
                        const char*             theBuffer,
                        unsigned long   theBufferLength);
  
        virtual void
        doFlush();
  
  private:
  
      // These are not implemented...
      XalanFileOutputStream(const XalanFileOutputStream&);
  
      XalanFileOutputStream&
        operator=(const XalanFileOutputStream&);
  
        void
        flushBuffer();
  
        void
        doWrite(const XalanDOMChar*             theBuffer);
  
        void
        doWrite(
                        const char*             theBuffer,
                        unsigned long   theBufferLength);
  
      bool
        operator==(const XalanFileOutputStream&) const;
  
        // Data members...
        const XalanDOMString    m_fileName;
  
        FILE*                                   m_handle;
  };
  
  
  
  #endif        // XALANFILEOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanNullOutputStream.cpp
  
  Index: XalanNullOutputStream.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file...
  #include "XalanNullOutputStream.hpp"
  
  
  
  XalanNullOutputStream::XalanNullOutputStream() :
        XalanOutputStream()
  {
  }
  
  
  
  XalanNullOutputStream::~XalanNullOutputStream()
  {
  }
  
  
  
  void
  XalanNullOutputStream::flush()
  {
  }
  
  
  
  void
  XalanNullOutputStream::write(char     /* theChar */)
  {
  }
  
  
  
  void
  XalanNullOutputStream::write(XalanDOMChar     /* theChar */)
  {
  }
  
  
  
  void
  XalanNullOutputStream::write(const XalanDOMChar*              /* theBuffer */)
  {
  }
  
  
  
  void
  XalanNullOutputStream::write(const char*              /* theBuffer */)
  {
  }
  
  
  
  void
  XalanNullOutputStream::write(
                        const char*             /* theBuffer */,
                        unsigned long   /* theBufferLength */)
  {
  }
  
  
  
  void
  XalanNullOutputStream::write(
                        const XalanDOMChar*             /* theBuffer */,
                        unsigned long                   /* theBufferLength */)
  {
  }
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanNullOutputStream.hpp
  
  Index: XalanNullOutputStream.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANNULLOUTPUTSTREAM_HEADER_GUARD_1357924680)
  #define XALANNULLOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  // Base class header file.
  #include <PlatformSupport/XalanOutputStream.hpp>
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanNullOutputStream : public 
XalanOutputStream
  {
  public :
  
        explicit
      XalanNullOutputStream();
  
      virtual
        ~XalanNullOutputStream();
  
      // These are inherited from XalanOutputStream...
      virtual void
        flush();
  
      virtual void
        write(char      theChar);
  
      virtual void
        write(XalanDOMChar      theChar);
  
      virtual void
        write(const XalanDOMChar*       theBuffer);
  
      virtual void
        write(const char*       theBuffer);
  
      virtual void
        write(
                        const char*             theBuffer,
                        unsigned long   theBufferLength);
  
      virtual void
        write(
                        const XalanDOMChar*             theBuffer,
                        unsigned long                   theBufferLength);
  
  private:
  
      // These are not implemented...
      XalanNullOutputStream(const XalanNullOutputStream&);
  
      XalanNullOutputStream&
        operator=(const XalanNullOutputStream&);
  
      bool
        operator==(const XalanNullOutputStream&) const;
  };
  
  
  
  #endif        // NULLTEXTOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanOutputStream.cpp
  
  Index: XalanOutputStream.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file...
  #include "XalanOutputStream.hpp"
  
  
  
  #include <util/TransService.hpp>
  #include <util/XMLException.hpp>
  
  
  
  #include "XalanTranscodingServices.hpp"
  
  
  
  XalanOutputStream::XalanOutputStream(
                        BufferType::size_type                   theBufferSize,
                        TranscodeVectorType::size_type  theTranscoderBlockSize) 
:
        m_transcoderBlockSize(theTranscoderBlockSize),
        m_transcoder(0),
        m_bufferSize(theBufferSize),
        m_buffer(),
        m_encoding(),
        m_writeAsUTF16(false)
  {
  }
  
  
  
  XalanOutputStream::~XalanOutputStream()
  {
        XalanTranscodingServices::destroyTranscoder(m_transcoder);
  }
  
  
  
  void
  XalanOutputStream::flush()
  {
        flushBuffer();
  
        doFlush();
  }
  
  
  
  void
  XalanOutputStream::write(char theChar)
  {
        write(&theChar, 1);
  }
  
  
  
  void
  XalanOutputStream::write(XalanDOMChar theChar)
  {
        write(&theChar, 1);
  }
  
  
  
  void
  XalanOutputStream::write(
                        const XalanDOMChar*             theBuffer,
                        unsigned long                   theBufferLength)
  {
        assert(theBuffer != 0);
  
        if (theBufferLength + m_buffer.size() > m_bufferSize)
        {
                flushBuffer();
        }
  
        if (theBufferLength > m_bufferSize)
        {
                doWrite(theBuffer);
        }
        else
        {
                m_buffer.insert(m_buffer.end(),
                                                theBuffer,
                                                theBuffer + theBufferLength);
        }
  }
  
  
  
  void
  XalanOutputStream::write(const XalanDOMChar*  theBuffer)
  {
        if (theBuffer != 0)
        {
                write(theBuffer, length(theBuffer));
        }
  }
  
  
  
  void
  XalanOutputStream::write(const char*  theBuffer)
  {
        assert(theBuffer != 0);
  
        flushBuffer();
  
        writeData(theBuffer,
                      strlen(theBuffer));
  }
  
  
  
  void
  XalanOutputStream::write(
                        const char*             theBuffer,
                        unsigned long   theBufferLength)
  {
        assert(theBuffer != 0);
  
        flushBuffer();
  
        writeData(theBuffer,
                          theBufferLength);
  }
  
  
  
  void
  XalanOutputStream::transcode(
                        const XalanDOMChar*             theBuffer,
                        TranscodeVectorType&    theDestination)
  {
        // This is a special version that will short-cut when
        // transocding to the local code page.  On platforms
        // where XalanDOMChar == wchar_t, it saves copying
        // to a temporary buffer for the purposes of null-
        // terminating the string.
        if (m_transcoder == 0)
        {
                if (TranscodeToLocalCodePage(
                                theBuffer,
                                theDestination) == false)
                {
                        throw TranscodingException();
                }
        }
        else
        {
                transcode(theBuffer, length(theBuffer), theDestination);
        }
  }
  
  
  
  void
  XalanOutputStream::transcode(
                        const XalanDOMChar*             theBuffer,
                        unsigned long                   theBufferLength,
                        TranscodeVectorType&    theDestination)
  {
        if (m_transcoder == 0)
        {
                if (TranscodeToLocalCodePage(
                                theBuffer,
                                theBufferLength,
                                theDestination) == false)
                {
                        throw TranscodingException();
                }
        }
        else
        {
                bool                                    fDone = false;
  
                // Keep track of the total bytes we've added to the
                // destination vector, and the total bytes we've
                // eaten from theBuffer.
                unsigned int                    theTotalBytesFilled = 0;
                unsigned int                    theTotalBytesEaten = 0;
  
                // Keep track of the current position in the input buffer,
                // and amount remaining in the buffer, since we may not be
                // able to transcode it all at once.
                const XalanDOMChar*             theBufferPosition = theBuffer;
                unsigned int                    theRemainingBufferLength = 
theBufferLength;
  
                // Keep track of the destination size, and the target size, 
which is
                // the size of the destination that has not yet been filled with
                // transcoded characters.  Double the buffer size, in case we're
                // transcoding to a 16-bit encoding.
                // $$$ ToDo: We need to know the size of an encoding, so we can
                // do the right thing with the destination size.
                unsigned int                    theDestinationSize = 
theBufferLength * 2;
                unsigned int                    theTargetSize = 
theDestinationSize;
  
                do
                {
                        // Resize the buffer...
                        theDestination.resize(theDestinationSize + 1);
  
                        unsigned int                                            
theSourceBytesEaten = 0;
                        unsigned int                                            
theTargetBytesEaten = 0;
  
                        XalanTranscodingServices::eCode         theResult =
                                m_transcoder->transcode(
                                                theBufferPosition,
                                                theRemainingBufferLength,
  #if defined(XALAN_OLD_STYLE_CASTS)
                                                (XMLByte*)&theDestination[0] + 
theTotalBytesFilled,
  #else
                                                
reinterpret_cast<XMLByte*>(&theDestination[0]) + theTotalBytesFilled,
  #endif
                                                theTargetSize,
                                                theSourceBytesEaten,
                                                theTargetBytesEaten);
  
                        if(theResult != XalanTranscodingServices::OK)
                        {
                                throw TranscodingException();
                        }
  
                        theTotalBytesFilled += theTargetBytesEaten;
                        theTotalBytesEaten += theSourceBytesEaten;
  
                        if (theTotalBytesEaten == theBufferLength)
                        {
                                fDone = true;
                        }
                        else
                        {
                                assert(theTotalBytesEaten < theBufferLength);
  
                                // Update everything...
                                theBufferPosition += theSourceBytesEaten;
                                theRemainingBufferLength -= theSourceBytesEaten;
  
                                // The new target size will always be the
                                // current destination size, since we
                                // grow by a factor of 2.  This will
                                // need to change if the factor is
                                // every changed.
                                theTargetSize = theDestinationSize;
  
                                // Grow the destination by a factor of
                                // two 2.  See the previous comment if
                                // you want to change this.
                                theDestinationSize = theDestinationSize * 2;
                        }
                } while(fDone == false);
  
                // Resize things, if there are any extra bytes...
                if (theDestination.size() != theTotalBytesFilled)
                {
                        theDestination.resize(theTotalBytesFilled);
                }
        }
  }
  
  
  
  const XalanDOMString&
  XalanOutputStream::getOutputEncoding() const
  {
        return m_encoding;
  }
  
  
  
  void
  XalanOutputStream::setOutputEncoding(const XalanDOMString&    theEncoding)
  {
        // Flush, just in case.  This should problably be an error...
        flushBuffer();
  
        XalanTranscodingServices::destroyTranscoder(m_transcoder);
  
        XalanTranscodingServices::eCode         theCode = 
XalanTranscodingServices::OK;
  
        // This turns on an optimization that we can only do if
        // XalanDOMChar == sizeof(ushort).  See doWrite().
  #if !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH)
        if (XalanTranscodingServices::encodingIsUTF16(theEncoding) == true)
        {
                m_writeAsUTF16 = true;
        }
        else
  #endif
        {
                m_transcoder = XalanTranscodingServices::makeNewTranscoder(
                                        theEncoding,
                                        theCode,
                                        m_transcoderBlockSize);
  
                if (theCode == XalanTranscodingServices::UnsupportedEncoding)
                {
                        throw UnsupportedEncodingException(theEncoding);
                }
                else if (theCode != XalanTranscodingServices::OK)
                {
                        throw TranscoderInternalFailureException(theEncoding);
                }
  
                assert(m_transcoder != 0);
        }
  
        m_encoding = theEncoding;
  
        const XalanTranscodingServices::XalanXMLByteVectorType  theProlog =
                XalanTranscodingServices::getStreamProlog(theEncoding);
  
  #if defined(XALAN_OLD_STYLE_CASTS)
        write((const char*)theProlog[0], theProlog.size());
  #else
        write(reinterpret_cast<const char*>(&theProlog[0]), theProlog.size());
  #endif
  }
  
  
  
  void
  XalanOutputStream::flushBuffer()
  {
        if (m_buffer.size() > 0)
        {
                m_buffer.push_back(0);
  
                doWrite(m_buffer.begin());
  
                m_buffer.clear();
        }
  }
  
  
  
  void
  XalanOutputStream::doWrite(const XalanDOMChar*        theBuffer)
  {
        assert(theBuffer != 0);
  
        try
        {
                if (m_writeAsUTF16 == true)
                {
                        assert(sizeof(XalanDOMChar) == sizeof(char) * 2);
  
                        // This is a hack to write UTF-16 through as if it
                        // were just chars.  Saves lots of time "transcoding."
  #if defined(XALAN_OLD_STYLE_CASTS)
                        writeData((const char*)theBuffer, length(theBuffer) * 
2);
  #else
                        writeData(reinterpret_cast<const char*>(theBuffer), 
length(theBuffer) * 2);
  #endif
                }
                else
                {
                        TranscodeVectorType             theTranscodedData;
  
                        transcode(theBuffer, theTranscodedData);
  
                        assert(&theTranscodedData[0] != 0);
  
                        writeData(&theTranscodedData[0],
                                          theTranscodedData.size());
                }
        }
        catch(const XalanOutputStreamException&)
        {
                // Have to catch this error and flush any output remaining...
                m_buffer.clear();
  
                throw;
        }
  }
  
  
  
  void
  XalanOutputStream::setBufferSize(BufferType::size_type                
theBufferSize)
  {
        flushBuffer();
  
        m_bufferSize = theBufferSize;
  
        if (m_buffer.size() < m_bufferSize)
        {
                // Enlarge the buffer...
                m_buffer.reserve(theBufferSize);
        }
        else if (m_buffer.size() > m_bufferSize)
        {
                // Shrink the buffer.
  
                // Create a temp buffer and make it
                // the correct size.
                BufferType      temp;
                
                temp.reserve(theBufferSize);
                
                // Swap temp with m_buffer so that
                // m_buffer is now the correct size.
                temp.swap(m_buffer);
        }
  }
  
  
  
  XalanOutputStream::XalanOutputStreamException::XalanOutputStreamException(
                        const XalanDOMString&   theMessage,
                        const XalanDOMString&   theType) :
        XSLException(theMessage, theType)
  {
  }
  
  
  
  XalanOutputStream::XalanOutputStreamException::~XalanOutputStreamException()
  {
  }
  
  
  
  XalanOutputStream::UnknownEncodingException::UnknownEncodingException() :
        XalanOutputStreamException(
                        XALAN_STATIC_UCODE_STRING("Unknown error occurred while 
transcoding!"),
                        XALAN_STATIC_UCODE_STRING("UnknownEncodingException"))
  {
  }
  
  
  
  XalanOutputStream::UnknownEncodingException::~UnknownEncodingException()
  {
  }
  
  
  
  
XalanOutputStream::UnsupportedEncodingException::UnsupportedEncodingException(const
 XalanDOMString&   theEncoding) :
        XalanOutputStreamException(
                        XALAN_STATIC_UCODE_STRING("Unsupported encoding: ") + 
theEncoding,
                        
XALAN_STATIC_UCODE_STRING("UnsupportedEncodingException")),
        m_encoding(theEncoding)
  {
  }
  
  
  
  
XalanOutputStream::UnsupportedEncodingException::~UnsupportedEncodingException()
  {
  }
  
  
  
  
XalanOutputStream::TranscoderInternalFailureException::TranscoderInternalFailureException(const
 XalanDOMString&       theEncoding) :
        XalanOutputStreamException(
                        XALAN_STATIC_UCODE_STRING("Unknown error occurred while 
transcoding to ") +
                                        theEncoding +
                                        XALAN_STATIC_UCODE_STRING("!"),
                        
XALAN_STATIC_UCODE_STRING("TranscoderInternalFailureException")),
        m_encoding(theEncoding)
  {
  }
  
  
  
  
XalanOutputStream::TranscoderInternalFailureException::~TranscoderInternalFailureException()
  {
  }
  
  
  
  XalanOutputStream::TranscodingException::TranscodingException() :
        XalanOutputStreamException(
                        XALAN_STATIC_UCODE_STRING("An error occurred while 
transcoding!"),
                        XALAN_STATIC_UCODE_STRING("TranscodingException"))
  {
  }
  
  
  
  XalanOutputStream::TranscodingException::~TranscodingException()
  {
  }
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanOutputStream.hpp
  
  Index: XalanOutputStream.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANOUTPUTSTREAM_HEADER_GUARD_1357924680)
  #define XALANOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  #include <vector>
  
  
  
  #include <XalanDOM/XalanDOMString.hpp>
  
  
  
  #include <PlatformSupport/XSLException.hpp>
  
  
  
  class XalanOutputTranscoder;
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputStream
  {
  public :
  
        enum { eDefaultBufferSize = 512, eDefaultTranscoderBlockSize = 1024 };
  
  
  #if defined(XALAN_NO_NAMESPACES)
        typedef vector<XalanDOMChar>            BufferType;
  
        typedef vector<char>                            TranscodeVectorType;
  #else
        typedef std::vector<XalanDOMChar>       BufferType;
  
        typedef std::vector<char>                       TranscodeVectorType;
  #endif
  
        explicit
        XalanOutputStream(
                        BufferType::size_type                   theBufferSize = 
eDefaultBufferSize,
                        TranscodeVectorType::size_type  theTranscoderBlockSize 
= eDefaultTranscoderBlockSize);
  
        virtual
        ~XalanOutputStream();
  
        /**
         * Flush the stream's buffer.
         */
      virtual void
        flush();
  
        /**
         * Write a character to the output stream.  The character
         * will not be transcoded.
         *
         * @param theChar       the character to write
         */
      virtual void
        write(char      theChar);
  
        /**
         * Write a wide character to the output stream.  The character
         * will be transcoded, if an output encoding is specified.
         *
         * @param theChar       the character to write
         */
      virtual void
        write(XalanDOMChar      theChar);
  
        /**
         * Write a null-terminated string to the output file.  The character
         * will not be transcoded.
         *
         * @param theBuffer       character buffer to write
         */
      virtual void
        write(const char*       theBuffer);
  
        /**
         * Write a null-terminated wide string to the output file.  The string
         * will be transcoded, if an output encoding is specified.
         *
         * @param theBuffer       character buffer to write
         */
      virtual void
        write(const XalanDOMChar*       theBuffer);
  
        /**
         * Write a specified number of characters to the output stream.  The 
string
         * will not be transcoded.
         *
         * @param theBuffer       character buffer to write
         * @param theBufferLength number of characters to write
         */
      virtual void
        write(
                        const char*             theBuffer,
                        unsigned long   theBufferLength);
  
        /**
         * Write a specified number of characters to the output stream.  The 
string
         * will be transcoded, if an output encoding is specified.
         *
         * @param theBuffer       character buffer to write
         * @param theBufferLength number of characters to write
         */
      virtual void
        write(
                        const XalanDOMChar*             theBuffer,
                        unsigned long                   theBufferLength);
  
        /**
         * Get the output encoding for the stream.
         *
         * @return The encoding name
         */
        virtual const XalanDOMString&
        getOutputEncoding() const;
  
        /**
         * Set the output encoding for the stream.
         *
         * @param theEncoding The encoding name
         */
        virtual void
        setOutputEncoding(const XalanDOMString&         theEncoding);
  
        /**
         * Set the size of the output buffer.
         *
         * @param theBufferSize The buffer size.
         */
        virtual void
        setBufferSize(BufferType::size_type             theBufferSize);
  
  
        class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputStreamException : public 
XSLException
        {
        public:
  
                XalanOutputStreamException(
                        const XalanDOMString&   theMessage,
                        const XalanDOMString&   theType);
  
                virtual
                ~XalanOutputStreamException();
        };
  
        class XALAN_PLATFORMSUPPORT_EXPORT UnknownEncodingException : public 
XalanOutputStreamException
        {
        public:
  
                explicit
                UnknownEncodingException();
  
                virtual
                ~UnknownEncodingException();
        };
  
        class XALAN_PLATFORMSUPPORT_EXPORT UnsupportedEncodingException : 
public XalanOutputStreamException
        {
        public:
  
                UnsupportedEncodingException(const XalanDOMString&      
theEncoding);
  
                virtual
                ~UnsupportedEncodingException();
  
                const XalanDOMString&
                getEncoding() const
                {
                        return m_encoding;
                }
  
        private:
  
                const XalanDOMString&   m_encoding;
        };
  
        class XALAN_PLATFORMSUPPORT_EXPORT TranscoderInternalFailureException : 
public XalanOutputStreamException
        {
        public:
  
                TranscoderInternalFailureException(const XalanDOMString&        
theEncoding);
  
                virtual
                ~TranscoderInternalFailureException();
  
                const XalanDOMString&
                getEncoding() const
                {
                        return m_encoding;
                }
  
        private:
  
                const XalanDOMString&   m_encoding;
        };
  
        class XALAN_PLATFORMSUPPORT_EXPORT TranscodingException : public 
XalanOutputStreamException
        {
        public:
  
                explicit
                TranscodingException();
  
                virtual
                ~TranscodingException();
        };
  
  protected:
  
        /**
         * Transcode a null-terminated wide string.
         *
         * @param theBuffer The string to transcode.
         * @param theDestination The destination vector.
         */
        void
        transcode(
                        const XalanDOMChar*             theBuffer,
                        TranscodeVectorType&    theDestination);
  
        /**
         * Transcode a wide string.
         *
         * @param theBuffer The string to transcode.
         * @param theBufferLength The length of the string.
         * @param theDestination The destination vector.
         */
        void
        transcode(
                        const XalanDOMChar*             theBuffer,
                        unsigned long                   theBufferLength,
                        TranscodeVectorType&    theDestination);
  
        virtual void
        writeData(const char*           theBuffer,
                          unsigned long         theBufferLength) = 0;
  
        virtual void
        doFlush() = 0;
  
  private:
  
      // These are not implemented...
      XalanOutputStream(const XalanOutputStream&);
  
      XalanOutputStream&
        operator=(const XalanOutputStream&);
  
      bool
        operator==(const XalanOutputStream&) const;
  
        // Utility functions...
        void
        flushBuffer();
  
        void
        doWrite(const XalanDOMChar*             theBuffer);
  
  
        const TranscodeVectorType::size_type    m_transcoderBlockSize;
  
        XalanOutputTranscoder*                                  m_transcoder;
  
        BufferType::size_type                                   m_bufferSize;
  
        BufferType                                                              
m_buffer;
  
        XalanDOMString                                                  
m_encoding;
  
        bool                                                                    
m_writeAsUTF16;
  };
  
  
  
  #endif        // XALANOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  1.1                  
xml-xalan/c/src/PlatformSupport/XalanOutputStreamPrintWriter.cpp
  
  Index: XalanOutputStreamPrintWriter.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file.
  #include "XalanOutputStreamPrintWriter.hpp"
  
  
  
  #include <cassert>
  
  
  
  #include <XalanDOM/XalanDOMString.hpp>
  
  
  
  #include "DOMStringHelper.hpp"
  #include "XalanOutputStream.hpp"
  
  
  
  XalanOutputStreamPrintWriter::XalanOutputStreamPrintWriter(
                        XalanOutputStream&      theOutputStream,
                        bool                            fAutoFlush) :
        PrintWriter(fAutoFlush),
        m_OutputStream(theOutputStream)
  {
  }
  
  
  
  XalanOutputStreamPrintWriter::~XalanOutputStreamPrintWriter()
  {
        flush();
  }
  
  
  
  bool
  XalanOutputStreamPrintWriter::checkError() const
  {
        return false;
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::close()
  {
        flush();
  }
  
  
  void
  XalanOutputStreamPrintWriter::flush()
  {
        m_OutputStream.flush();
  }
  
  
  
  XalanOutputStream*
  XalanOutputStreamPrintWriter::getStream()
  {
        return &m_OutputStream;
  }
  
  
  
  const XalanOutputStream*
  XalanOutputStreamPrintWriter::getStream() const
  {
        return &m_OutputStream;
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::write(
                        const char*             s,
                        unsigned int    theOffset,
                        unsigned int    theLength)
  {
        assert(s != 0);
  
        if (theLength == -1)
        {
                if (theOffset == 0)
                {
                        m_OutputStream.write(s);
                }
                else
                {
                        m_OutputStream.write(s + theOffset);
                }
        }
        else
        {
                const long      theStopIndex = theOffset + theLength;
  
                for (long i = theOffset; i < theStopIndex; i++)
                {
                        m_OutputStream.write(s[i]);
                }
        }
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::write(
                        const XMLCh*    s,
                        unsigned int    theOffset,
                        unsigned int    theLength)
  {
        assert(s != 0);
  
        if (theLength == -1)
        {
                if (theOffset == 0)
                {
                        m_OutputStream.write(s);
                }
                else
                {
                        m_OutputStream.write(s + theOffset);
                }
        }
        else
        {
                const long      theStopIndex = theOffset + theLength;
  
                for (long i = theOffset; i < theStopIndex; i++)
                {
                        m_OutputStream.write(s[i]);
                }
        }
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::write(XMLCh     c)
  {
        m_OutputStream.write(c);
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::write(
                        const DOMString&        s,
                        unsigned int            theOffset,
                        unsigned int            theLength)
  {
        write(c_wstr(s), theOffset, theLength);
  }
  
  
  
  #if !defined(XALAN_BOOL_AS_INT)
  void
  XalanOutputStreamPrintWriter::print(bool      b)
  {
        if (b == true)
        {
                print(s_trueString);
        }
        else
        {
                print(s_falseString);
        }
  }
  #endif
  
  
  
  void
  XalanOutputStreamPrintWriter::print(char      c)
  {
        write(c);
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::print(
                        const char*             s,
                        unsigned int    theLength)
  {
        write(s,
                  0,
                  theLength);
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::print(
                        const XMLCh*    s,
                        unsigned int    theLength)
  {
        assert(s != 0);
        assert(theLength >= 0 || theLength == -1);
  
        write(s,
                  0,
                  theLength);
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::print(double    d)
  {
        m_OutputStream.write(c_wstr(DoubleToDOMString(d)));
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::print(int       i)
  {
        m_OutputStream.write(c_wstr(LongToDOMString(i)));
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::print(long      l)
  {
        m_OutputStream.write(c_wstr(LongToDOMString(l)));
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::print(const DOMString&  s)
  {
        m_OutputStream.write(c_wstr(s));
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println()
  {
        m_OutputStream.write(c_wstr(s_newlineString));
  
        flush();
  }
  
  
  
  #if !defined(XALAN_BOOL_AS_INT)
  void
  XalanOutputStreamPrintWriter::println(bool    b)
  {
        print(b);
  
        println();
  }
  #endif
  
  
  
  void
  XalanOutputStreamPrintWriter::println(char    c)
  {
        print(c);
  
        println();
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println(
                        const char*             s,
                        unsigned int    theLength)
  {
        print(s, theLength);
  
        println();
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println(
                        const XMLCh*    s,
                        unsigned int    theLength)
  {
        print(s, theLength);
  
        println();
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println(double  d)
  {
        print(d);
  
        println();
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println(int             i)
  {
        print(i);
  
        println();
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println(long    l)
  {
        print(l);
  
        println();
  }
  
  
  
  void
  XalanOutputStreamPrintWriter::println(const DOMString&        s)
  {
        print(s);
  
        println();
  }
  
  
  
  1.1                  
xml-xalan/c/src/PlatformSupport/XalanOutputStreamPrintWriter.hpp
  
  Index: XalanOutputStreamPrintWriter.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANOUTPUTSTREAMPRINTWRITER_HEADER_GUARD_1357924680)
  #define XALANOUTPUTSTREAMPRINTWRITER_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  #include <PlatformSupport/PrintWriter.hpp>
  
  
  
  class XalanOutputStream;
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputStreamPrintWriter : public 
PrintWriter
  {
  public:
  
        /**
         * Construct a XalanOutputStreamPrintWriter instance. 
         *
         * @param theOutputStream output stream to write
         * @param fAutoFlush      if true, the output will not be buffered
         */
        XalanOutputStreamPrintWriter(
                        XalanOutputStream&      theOutputStream,
                        bool                            fAutoFlush = false);
  
        virtual
        ~XalanOutputStreamPrintWriter();
  
        // These methods are inherited from PrintWriter ...
  
        virtual bool
      checkError() const;
  
        virtual void
        close();
  
        virtual void
        flush();
  
        virtual XalanOutputStream*
        getStream();
  
        virtual const XalanOutputStream*
        getStream() const;
  
  
        // Output functions...
  
        virtual void
        write(const char*       s,
                  unsigned int  theOffset = 0,
                  unsigned int  theLength = UINT_MAX);
  
        virtual void
        write(const XalanDOMChar*       s,
                  unsigned int                  theOffset = 0,
                  unsigned int                  theLength = UINT_MAX);
  
        virtual void
        write(XalanDOMChar              c);
  
        virtual void
        write(const XalanDOMString&             s,
                  unsigned int                          theOffset = 0,
                  unsigned int                          theLength = UINT_MAX);
  
  #if !defined(XALAN_BOOL_AS_INT)
        virtual void
        print(bool      b);
  #endif
  
        virtual void
        print(char      c);
  
        virtual void
        print(const char*       s,
                  unsigned int  theLength = UINT_MAX);
  
        virtual void
        print(const XalanDOMChar*       s,
                  unsigned int                  theLength = UINT_MAX);
  
        virtual void
        print(double    d);
  
        virtual void
        print(int       i);
  
        virtual void
        print(long      l);
  
        virtual void
        print(const XalanDOMString&             s);
  
        virtual void
        println();
  
  #if !defined(XALAN_BOOL_AS_INT)
        virtual void
        println(bool    b);
  #endif
  
        virtual void
        println(char    c);
  
        virtual void
        println(const char*             s,
                    unsigned int        theLength = UINT_MAX);
  
        virtual void
        println(const XalanDOMChar*             s,
                        unsigned int                    theLength = UINT_MAX);
  
        virtual void
        println(double  d);
  
        virtual void
        println(int             i);
  
        virtual void
        println(long    l);
  
        virtual void
        println(const XalanDOMString&   s);
  
  protected:
  
        XalanOutputStream&      m_OutputStream;
  
  private:
  
        // Not implemented
        XalanOutputStreamPrintWriter(const XalanOutputStreamPrintWriter&);
  
        XalanOutputStreamPrintWriter&
        operator=(const XalanOutputStreamPrintWriter&);
  
        bool
        operator==(const XalanOutputStreamPrintWriter&);
  };
  
  
  
  #endif        // XALANOUTPUTSTREAMPRINTWRITER_HEADER_GUARD_1357924680
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanStdOutputStream.cpp
  
  Index: XalanStdOutputStream.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file...
  #include "XalanStdOutputStream.hpp"
  
  
  
  #include <cerrno>
  #include <iostream>
  #include <strstream>
  
  
  
  #include <PlatformSupport/DOMStringHelper.hpp>
  
  
  
  #if !defined(XALAN_NO_NAMESPACES)
  using std::ostream;
  using std::cerr;
  #endif
  
  
  
  XalanStdOutputStream::XalanStdOutputStream(ostream&   theOutputStream) :
        XalanOutputStream(),
        m_outputStream(theOutputStream)
  {
        // This will make sure that cerr is not buffered...
        if (&m_outputStream == &cerr)
        {
                setBufferSize(0);
        }
  }
  
  
  
  XalanStdOutputStream::~XalanStdOutputStream()
  {
  }
  
  
  
  void
  XalanStdOutputStream::doFlush()
  {
        m_outputStream.flush();
  }
  
  
  
  void
  XalanStdOutputStream::writeData(
                        const char*             theBuffer,
                        unsigned long   theBufferLength)
  {
        m_outputStream.write(theBuffer, theBufferLength);
  
        if(!m_outputStream)
        {
                throw XalanStdOutputStreamWriteException(errno);
        }
  }
  
  
  
  static DOMString
  FormatMessageLocal(
                        const DOMString&        theMessage,
                        int                                     theErrorCode)
  {
  #if !defined(XALAN_NO_NAMESPACES)
  using std::ostrstream;
  #endif
  
        DOMString       theResult(clone(theMessage));
  
        ostrstream   theFormatter;
  
        theFormatter << ".  The error code was "
                                 << theErrorCode
                                 << "." << '\0';
  
        theResult += theFormatter.str();
  
        delete theFormatter.str();
        return theResult;
  }
  
  
  
  
XalanStdOutputStream::XalanStdOutputStreamWriteException::XalanStdOutputStreamWriteException(
                int                                     theErrorCode) :
        XalanOutputStreamException(FormatMessageLocal("Error writing to 
standard stream!",
                                                                                
                           theErrorCode),
                                                                    
XALAN_STATIC_UCODE_STRING("XercesStdTextOutputStreamWriteException"))
  {
  }
  
  
  
  
XalanStdOutputStream::XalanStdOutputStreamWriteException::~XalanStdOutputStreamWriteException()
  {
  }
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanStdOutputStream.hpp
  
  Index: XalanStdOutputStream.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANSTDOUTPUTSTREAM_HEADER_GUARD_1357924680)
  #define XALANSTDOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  #if defined(XALAN_NO_IOSFWD)
  #include <ostream>
  #else
  #include <iosfwd>
  #endif
  
  
  
  // Base class header file.
  #include <PlatformSupport/XalanOutputStream.hpp>
  
  
  
  // A base class for all text output streams.
  class XALAN_PLATFORMSUPPORT_EXPORT XalanStdOutputStream : public 
XalanOutputStream
  {
  public:
  
        /**
         * Construct a XalanStdOutputStream instance for output to the
         * standard output device.
         *
         * @param theOutputStream output stream to use
         */
      XalanStdOutputStream(
  #if defined (XALAN_NO_NAMESPACES)
                        ostream&                theOutputStream);
  #else
                        std::ostream&   theOutputStream);
  #endif
  
      virtual
        ~XalanStdOutputStream();
  
        class XALAN_PLATFORMSUPPORT_EXPORT XalanStdOutputStreamWriteException : 
public XalanOutputStream::XalanOutputStreamException
        {
        public:
  
                XalanStdOutputStreamWriteException(
                        int                                     theErrorCode);
  
                virtual
                ~XalanStdOutputStreamWriteException();
  
        };
  
  protected:
  
        virtual void
        writeData(const char*           theBuffer,
                          unsigned long         theBufferLength);
  
        virtual void
        doFlush();
  
  private:
  
      // These are not implemented...
      XalanStdOutputStream(const XalanStdOutputStream&);
  
      XalanStdOutputStream&
        operator=(const XalanStdOutputStream&);
  
        // Data members...
  #if defined (XALAN_NO_NAMESPACES)
        ostream&                m_outputStream;
  #else
        std::ostream&   m_outputStream;
  #endif
  };
  
  
  
  #endif        // XERCESSTDTEXTOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  1.1                  
xml-xalan/c/src/PlatformSupport/XalanToXercesTranscoderWrapper.cpp
  
  Index: XalanToXercesTranscoderWrapper.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #include "XalanToXercesTranscoderWrapper.hpp"
  
  
  
  #include <cassert>
  
  
  
  #include <util/TransService.hpp>
  #include <util/XMLException.hpp>
  
  
  
  XalanToXercesTranscoderWrapper::XalanToXercesTranscoderWrapper(XMLTranscoder* 
theTranscoder) :
        XalanOutputTranscoder(),
        m_transcoder(theTranscoder)
  {
  }
  
  
  
  XalanToXercesTranscoderWrapper::~XalanToXercesTranscoderWrapper()
  {
        delete m_transcoder;
  }
  
  
  
  XalanToXercesTranscoderWrapper::eCode
  XalanToXercesTranscoderWrapper::transcode(
                        const XalanDOMChar*             theSourceData,
                        unsigned int                    theSourceCount,
                        XalanXMLByte*                   theTarget,
                        unsigned int                    theTargetSize,
                        unsigned int&                   
theSourceCharsTranscoded,
                        unsigned int&                   theTargetBytesUsed)
  {
        eCode   theCode = XalanTranscodingServices::OK;
  
        try
        {
                theTargetBytesUsed = m_transcoder->transcodeTo(
                        theSourceData,
                        theSourceCount,
                        theTarget,
                        theTargetSize,
                        theSourceCharsTranscoded,
                        XMLTranscoder::UnRep_Throw);
        }
        catch(const XMLException&)
        {
                theSourceCharsTranscoded = 0;
                theTargetBytesUsed = 0;
                theCode = XalanTranscodingServices::InternalFailure;
        }
  
        return theCode;
  }
  
  
  
  1.1                  
xml-xalan/c/src/PlatformSupport/XalanToXercesTranscoderWrapper.hpp
  
  Index: XalanToXercesTranscoderWrapper.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANTOXERCESTRANSCODERWRAPPER_HEADER_GUARD_1357924680)
  #define XALANTOXERCESTRANSCODERWRAPPER_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  // Base class header file...
  #include <PlatformSupport/XalanTranscodingServices.hpp>
  
  
  
  class XMLTranscoder;
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanToXercesTranscoderWrapper : public 
XalanOutputTranscoder
  {
  public:
  
        explicit
        XalanToXercesTranscoderWrapper(XMLTranscoder*   theTranscoder);
     
        virtual
        ~XalanToXercesTranscoderWrapper();
  
        virtual eCode
        transcode(
                        const XalanDOMChar*             theSourceData,
                        unsigned int                    theSourceCount,
                        XalanXMLByte*                   theTarget,
                        unsigned int                    theTargetSize,
                        unsigned int&                   
theSourceCharsTranscoded,
                        unsigned int&                   theTargetBytesUsed);
  
  private:
  
        // Not implemented...
        XalanToXercesTranscoderWrapper(const XalanToXercesTranscoderWrapper&);
  
        XalanToXercesTranscoderWrapper&
        operator=(const XalanToXercesTranscoderWrapper&);
  
  
        XMLTranscoder* const    m_transcoder;
  };
  
  
  
  #endif        // XALANTOXERCESTRANSCODERWRAPPER_HEADER_GUARD_1357924680
  
  
  
  1.1                  
xml-xalan/c/src/PlatformSupport/XalanTranscodingServices.cpp
  
  Index: XalanTranscodingServices.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #include "XalanTranscodingServices.hpp"
  
  
  
  #include <cassert>
  
  
  
  #include <util/PlatformUtils.hpp>
  #include <util/TransService.hpp>
  
  
  
  #include "DOMStringHelper.hpp"
  #include "XalanToXercesTranscoderWrapper.hpp"
  #include "XalanUTF16Transcoder.hpp"
  
  
  
  const XalanDOMChar    XalanTranscodingServices::s_UTF8String[] =
  {
        XalanUnicode::charLetter_U,
        XalanUnicode::charLetter_T,
        XalanUnicode::charLetter_F, 
        XalanUnicode::charHyphenMinus,
        XalanUnicode::charDigit_8,
        0
  };
  
  
  
  const XalanDOMChar    XalanTranscodingServices::s_UTF16String[] =
  {
        XalanUnicode::charLetter_U,
        XalanUnicode::charLetter_T,
        XalanUnicode::charLetter_F, 
        XalanUnicode::charHyphenMinus,
        XalanUnicode::charDigit_1,
        XalanUnicode::charDigit_6,
        0
  };
  
  
  
  static XalanTranscodingServices::eCode
  translateCode(XMLTransService::Codes  theCode)
  {
        if (theCode == XMLTransService::Ok)
        {
                return XalanTranscodingServices::OK;
        }
        else if (theCode == XMLTransService::UnsupportedEncoding)
        {
                return XalanTranscodingServices::UnsupportedEncoding;
        }
        else if (theCode == XMLTransService::InternalFailure)
        {
                return XalanTranscodingServices::InternalFailure;
        }
        else
        {
                assert(theCode == XMLTransService::SupportFilesNotFound);
  
                return XalanTranscodingServices::SupportFilesNotFound;
        }
  }
  
  
  
  XalanOutputTranscoder*
  XalanTranscodingServices::makeNewTranscoder(
                        const XalanDOMString&   theEncodingName,
                        eCode&                                  theResult,
                        unsigned int                    theBlockSize)
  {
        assert(XMLPlatformUtils::fgTransService != 0);
  
        XalanOutputTranscoder*  theTranscoder = 0;
  
        XMLTransService::Codes  theCode = XMLTransService::Ok;
  
        if (encodingIsUTF16(theEncodingName) == true)
        {
                theResult = OK;
  
                theTranscoder = new XalanUTF16Transcoder;
        }
        else
        {
                XMLTranscoder*  theXercesTranscoder = 
                        XMLPlatformUtils::fgTransService->makeNewTranscoderFor(
                                        c_wstr(theEncodingName),
                                        theCode,
                                        theBlockSize);
  
                theResult = translateCode(theCode);
                assert(theResult == XMLTransService::Ok ||
                           theXercesTranscoder == 0);
  
                if (theResult == XMLTransService::Ok)
                {
                        theTranscoder = new 
XalanToXercesTranscoderWrapper(theXercesTranscoder);
                }
        }
  
        return theTranscoder;
  }
  
  
  
  void
  XalanTranscodingServices::destroyTranscoder(XalanOutputTranscoder*    
theTranscoder)
  {
        delete theTranscoder;
  }
  
  
  
  bool
  XalanTranscodingServices::encodingIsUTF16(const XalanDOMChar* theEncodingName)
  {
        return compareIgnoreCase(c_wstr(theEncodingName), s_UTF16String) == 0 ? 
true : false;
  }
  
  
  bool
  XalanTranscodingServices::encodingIsUTF16(const XalanDOMString&               
theEncodingName)
  {
        return encodingIsUTF16(c_wstr(theEncodingName));
  }
  
  
  
  // Some vectors for containing byte-order marks, or other leading bytes
  // that would indicate the encoding.
  static const XalanTranscodingServices::XalanXMLByteVectorType s_dummyVector;
  static XalanTranscodingServices::XalanXMLByteVectorType                       
s_UTF8Vector;
  static XalanTranscodingServices::XalanXMLByteVectorType                       
s_UTF16Vector;
  
  
  
  const XalanTranscodingServices::XalanXMLByteVectorType&
  XalanTranscodingServices::getStreamProlog(const XalanDOMString&               
theEncodingName)
  {
        if (compareIgnoreCase(c_wstr(theEncodingName), s_UTF16String) == 0)
        {
                return s_UTF16Vector;
        }
  #if 0
        // We won't do this for now...
        else if (compareIgnoreCase(c_wstr(theEncodingName), s_UTF8String) == 0)
        {
                return s_UTF8Vector;
        }
  #endif
        else
        {
                return s_dummyVector;
        }
  }
  
  
  
  XalanOutputTranscoder::XalanOutputTranscoder()
  {
  }
  
  
  
  XalanOutputTranscoder::~XalanOutputTranscoder()
  {
  }
  
  
  
  void
  XalanTranscodingServices::initialize()
  {
        s_UTF8Vector.reserve(3);
  
        // These are the characters that comprise the
        // UTF-8 byte-order mark.
        s_UTF8Vector.push_back(0xEF);
        s_UTF8Vector.push_back(0xBB);
        s_UTF8Vector.push_back(0xBF);
  
        s_UTF16Vector.reserve(2);
  
        // The byte order mark varies, since we're writing
        // UTF-16 out in the platform's endian-ness.
  #if defined(XALAN_LITLE_ENDIAN)
        s_UTF16Vector.push_back(0xFF);
        s_UTF16Vector.push_back(0xFE);
  #elif defined(XALAN_BIG_ENDIAN)
        s_UTF16Vector.push_back(0xFE);
        s_UTF16Vector.push_back(0xFF);
  #else
  #error The platform must define the byte order!
  #endif
  }
  
  
  
  void
  XalanTranscodingServices::terminate()
  {
        XalanXMLByteVectorType().swap(s_UTF16Vector);
        XalanXMLByteVectorType().swap(s_UTF8Vector);
  }
  
  
  
  1.1                  
xml-xalan/c/src/PlatformSupport/XalanTranscodingServices.hpp
  
  Index: XalanTranscodingServices.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680)
  #define XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  #include <vector>
  
  
  
  #include <XalanDOM/XalanDOMString.hpp>
  
  
  
  class XalanOutputTranscoder;
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanTranscodingServices
  {
  public:
  
        typedef unsigned char   XalanXMLByte;
  
  #if defined(XALAN_NO_NAMESPACES)
        typedef vector<XalanXMLByte>            XalanXMLByteVectorType;
  #else
        typedef std::vector<XalanXMLByte>       XalanXMLByteVectorType;
  #endif
  
        /**
         * Perform static initialization.  See class PlatformSupportInit.
         */
        static void
        initialize();
  
        /**
         * Perform static shut down.  See class PlatformSupportInit.
         */
        static void
        terminate();
  
      enum eCode
      {
                OK,
                UnsupportedEncoding,
                InternalFailure,
                SupportFilesNotFound
      };
  
  
        /**
         * Create a transcoder instance for the specified encoding.
         * 
         * @param theEncodingName The name of the desired output encoding.
         * @param theResult The error code.
         * @param theTarget The target array for storing the transcoded data.
         * @param theBlockSize The block size the transcoder should use.
         * @return The new transcoder, or 0 if there was an error.
         */
        static XalanOutputTranscoder*
        makeNewTranscoder(
                        const XalanDOMString&   theEncodingName,
                        eCode&                                  theResult,
                        unsigned int                    theBlockSize);
  
        /**
         * Destroy a transcoder instance.
         * 
         * @theTranscoder The transcoder to destroy.
         */
        static void
        destroyTranscoder(XalanOutputTranscoder*        theTranscoder);
  
        /**
         * Determine if the encoding name supplied is equuvalent to UTF-16.
         * 
         * @param theEncodingName The name of the desired output encoding.
         * @return true or false
         */
        static bool
        encodingIsUTF16(const XalanDOMChar*             theEncodingName);
  
        /**
         * Determine if the encoding name supplied is equuvalent to UTF-16.
         * 
         * @param theEncodingName The name of the desired output encoding.
         * @return true or false
         */
        static bool
        encodingIsUTF16(const XalanDOMString&   theEncodingName);
  
        /**
         * Get a vector that contains any leading bytes that should be
         * written to an XML stream for the specified encoding.  For example,
         * if the encoding is UTF-16, the vector will contain the appropriate
         * byte order mark for the current platform.  If there is no
         * prolog for the encoding, or the encoding is unknown, an empty
         * vector is returned.
         * 
         * @param theEncodingName The name of the desired output encoding.
         * @return A reference to a vector containing the appropriate bytes.
         */
        static const XalanXMLByteVectorType&
        getStreamProlog(const XalanDOMString&   theEncodingName);
  
  private:
  
        static const XalanDOMChar       s_UTF8String[];
        static const XalanDOMChar       s_UTF16String[];
  };
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputTranscoder
  {
  public:
  
        typedef XalanTranscodingServices::XalanXMLByte  XalanXMLByte;
        typedef XalanTranscodingServices::eCode                 eCode;
  
        explicit
        XalanOutputTranscoder();
  
        virtual
        ~XalanOutputTranscoder();
  
        /**
         * Transcode data from UTF-16 to the transcoder's encoding.  If 
successfull,
         * theResult will be set to OK.  If not, it will be set to one of the 
other
         * codes.
         *
         * @param theSourceData The source data to transcode
         * @param theSourceCount The length of the source data.
         * @param theTarget The target array for storing the transcoded data.
         * @param theTargetSize The number of characters that can be stored in 
the target.
         * @param theSourceCharsTranscoded The count of the source characters 
that were transcoded.
         * @param theTargetBytesUsed The number of characters stored in the 
target array
         * @return The result code.
         */
        virtual eCode
        transcode(
                        const XalanDOMChar*             theSourceData,
                        unsigned int                    theSourceCount,
                        XalanXMLByte*                   theTarget,
                        unsigned int                    theTargetSize,
                        unsigned int&                   
theSourceCharsTranscoded,
                        unsigned int&                   theTargetBytesUsed) = 0;
  
  private:
  
        // Not implemented...
        XalanOutputTranscoder(const XalanOutputTranscoder&      theSource);
  
        bool
        operator==(const XalanOutputTranscoder& theRHS) const;
  
        XalanOutputTranscoder&
        operator=(const XalanOutputTranscoder&  theRHS);
  };
  
  
  
  #endif        // NULLTEXTOUTPUTSTREAM_HEADER_GUARD_1357924680
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanUTF16Transcoder.cpp
  
  Index: XalanUTF16Transcoder.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #include "XalanUTF16Transcoder.hpp"
  
  
  
  #include <cassert>
  
  
  
  XalanUTF16Transcoder::XalanUTF16Transcoder() :
        XalanOutputTranscoder()
  {
  }
  
  
  
  XalanUTF16Transcoder::~XalanUTF16Transcoder()
  {
  }
  
  
  
  XalanUTF16Transcoder::eCode
  XalanUTF16Transcoder::transcode(
                        const XalanDOMChar*             theSourceData,
                        unsigned int                    theSourceCount,
                        XalanXMLByte*                   theTarget,
                        unsigned int                    theTargetSize,
                        unsigned int&                   
theSourceCharsTranscoded,
                        unsigned int&                   theTargetBytesUsed)
  {
        unsigned int    theSourceEaten = 0;
        unsigned int    theTargetPosition = 0;
  
        while(theSourceEaten < theSourceCount)
        {
                // Swap bytes to big endian...
                if (theTargetPosition + 1 >= theTargetSize)
                {
                        break;
                }
                else
                {
                        const XMLByte   theHighByte = 
XMLByte((theSourceData[theSourceEaten] & 0xFF00) >> 8);
                        const XMLByte   theLowByte = 
XMLByte(theSourceData[theSourceEaten] & 0x00FF);
  
  #if defined(XALAN_LITLE_ENDIAN)
                        theTarget[theTargetPosition++] = theLowByte;
                        theTarget[theTargetPosition++] = theHighByte;
  #elif defined(XALAN_BIG_ENDIAN)
                        theTarget[theTargetPosition++] = theHighByte;
                        theTarget[theTargetPosition++] = theLowByte;
  #else
  #error The platform must define the byte order!
  #endif
  
                        ++theSourceEaten;
                }
        }
  
        theSourceCharsTranscoded = theSourceEaten;
  
        theTargetBytesUsed = theTargetPosition;
  
        return XalanTranscodingServices::OK;
  }
  
  
  
  1.1                  xml-xalan/c/src/PlatformSupport/XalanUTF16Transcoder.hpp
  
  Index: XalanUTF16Transcoder.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(XALANUTF16TRANSCODER_HEADER_GUARD_1357924680)
  #define XALANUTF16TRANSCODER_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  // Base class header file...
  #include <PlatformSupport/XalanTranscodingServices.hpp>
  
  
  
  class XALAN_PLATFORMSUPPORT_EXPORT XalanUTF16Transcoder : public 
XalanOutputTranscoder
  {
  public:
  
        explicit
        XalanUTF16Transcoder();
     
        virtual
        ~XalanUTF16Transcoder();
  
        /**
         * Transcode data from UTF-16 to UTF-16.  Used for the time being, 
because, on some
         * platforms, we store UTF-16 in 4-byte wchar_t.
         *
         * @param theSourceData The source data to transcode
         * @param theSourceCount The length of the source data.
         * @param theResult The error code, if any.
         * @param theTarget The target array for storing the transcoded data.
         * @param theTargetSize The number of characters that can be stored in 
the target.
         * @param theSourceCharsTranscoded The count of the source characters 
that were transcoded.
         * @param theTargetBytesUsed The number of characters stored in the 
target array
         * @return The result code.
         */
        virtual eCode
        transcode(
                        const XalanDOMChar*             theSourceData,
                        unsigned int                    theSourceCount,
                        XalanXMLByte*                   theTarget,
                        unsigned int                    theTargetSize,
                        unsigned int&                   
theSourceCharsTranscoded,
                        unsigned int&                   theTargetBytesUsed);
  
  private:
  
        // Not implemented...
        XalanUTF16Transcoder(const XalanUTF16Transcoder&);
  
        XalanUTF16Transcoder&
        operator=(const XalanUTF16Transcoder&);
  };
  
  
  
  #endif        // XALANUTF16TRANSCODER_HEADER_GUARD_1357924680
  
  
  

Reply via email to