dbertoni    01/06/15 10:55:11

  Modified:    c/src/XMLSupport FormatterToXML.hpp FormatterToXML.cpp
  Log:
  New, experimental direct output.
  
  Revision  Changes    Path
  1.32      +65 -7     xml-xalan/c/src/XMLSupport/FormatterToXML.hpp
  
  Index: FormatterToXML.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToXML.hpp,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- FormatterToXML.hpp        2001/05/02 15:43:15     1.31
  +++ FormatterToXML.hpp        2001/06/15 17:55:07     1.32
  @@ -85,6 +85,7 @@
   
   class AttributeList;
   class Writer;
  +class XalanOutputStream;
   
   
   
  @@ -131,6 +132,7 @@
         *                          standalone document declaration
         *
         * @param format                        should be used only by derived classes.
  +      * @param fBufferData           If true, data will be buffered in the formatter
         */
        FormatterToXML(
                        Writer&                                 writer,
  @@ -143,7 +145,8 @@
                        const XalanDOMString&   doctypePublic = XalanDOMString(),
                        bool                                    xmlDecl = true,
                        const XalanDOMString&   standalone = XalanDOMString(),
  -                     eFormat                                 format = 
OUTPUT_METHOD_XML);
  +                     eFormat                                 format = 
OUTPUT_METHOD_XML,
  +                     bool                                    fBufferData = true);
   
        virtual
        ~FormatterToXML();
  @@ -203,13 +206,13 @@
                        const XMLCh* const      ch,
                        const unsigned int      length);
   
  -     const Writer&
  +     const Writer*
        getWriter() const
        {
                return m_writer;
        }
   
  -     Writer&
  +     Writer*
        getWriter()
        {
                return m_writer;
  @@ -314,8 +317,13 @@
        /** 
         * The writer where the XML will be written.
         */
  -     Writer&         m_writer;
  +     Writer* const                           m_writer;
   
  +     /** 
  +      * The stream where the XML will be written.
  +      */
  +     XalanOutputStream* const        m_stream;
  +
        /**
         * Output a line break.
         */
  @@ -324,6 +332,7 @@
   
        /**
         * Append a wide character to the buffer.
  +      *
         * Characters that are not representable
         * in the encoding are not written as
         * entities.
  @@ -340,9 +349,6 @@
   
        /**
         * Append a wide character to the buffer.
  -      * Characters that are not representable
  -      * in the encoding are not written as
  -      * entities.
         *
         * @ch the character to append.
         */
  @@ -358,6 +364,10 @@
         * Append a null-terminated array of wide characters to
         * the buffer.
         *
  +      * Characters that are not representable
  +      * in the encoding are not written as
  +      * entities.
  +      *
         * @chars the array to append
         */
        void
  @@ -375,6 +385,10 @@
        /**
         * Append an array of wide character to the buffer.
         *
  +      * Characters that are not representable
  +      * in the encoding are not written as
  +      * entities.
  +      *
         * @chars the array to append
         * @start the offset into the array to start from
         * @length the number of characters to append
  @@ -401,6 +415,10 @@
        /**
         * Append a string to the buffer.
         *
  +      * Characters that are not representable
  +      * in the encoding are not written as
  +      * entities.
  +      *
         * @param str the string to append
         */
        void
  @@ -693,6 +711,17 @@
        /**
         * Append a wide character to the buffer.
         * Characters that are not representable
  +      * in the encoding are not written as
  +      * entities.
  +      *
  +      * @ch the character to append.
  +      */
  +     void
  +     accumNameAsByteDirect(XalanDOMChar      ch);
  +
  +     /**
  +      * Append a wide character to the buffer.
  +      * Characters that are not representable
         * in the encoding are written as entities.
         *
         * @ch the character to append.
  @@ -701,6 +730,16 @@
        accumContentAsByte(XalanDOMChar         ch);
   
        /**
  +      * Append a wide character to the stream with buffering.
  +      * Characters that are not representable
  +      * in the encoding are written as entities.
  +      *
  +      * @ch the character to append.
  +      */
  +     void
  +     accumContentAsByteDirect(XalanDOMChar   ch);
  +
  +     /**
         * Append a wide character to the buffer.
         * Characters that are not representable
         * in the encoding are not written as
  @@ -713,11 +752,30 @@
   
        /**
         * Append a wide character to the buffer.
  +      * Characters that are not representable
  +      * in the encoding are not written as
  +      * entities.
  +      *
  +      * @ch the character to append.
  +      */
  +     void
  +     accumNameAsCharDirect(XalanDOMChar      ch);
  +
  +     /**
  +      * Append a wide character to the buffer.
         *
         * @ch the character to append.
         */
        void
        accumContentAsChar(XalanDOMChar         ch);
  +
  +     /**
  +      * Append a wide character to the stream without buffering.
  +      *
  +      * @ch the character to append.
  +      */
  +     void
  +     accumContentAsCharDirect(XalanDOMChar   ch);
   
        /**
         * Output the doc type declaration.
  
  
  
  1.49      +119 -20   xml-xalan/c/src/XMLSupport/FormatterToXML.cpp
  
  Index: FormatterToXML.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToXML.cpp,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- FormatterToXML.cpp        2001/06/06 21:46:05     1.48
  +++ FormatterToXML.cpp        2001/06/15 17:55:08     1.49
  @@ -97,9 +97,11 @@
                        const XalanDOMString&   doctypePublic,
                        bool                                    xmlDecl,
                        const XalanDOMString&   standalone,
  -                     eFormat                                 format) :
  +                     eFormat                                 format,
  +                     bool                                    fBufferData) :
        FormatterListener(format),
  -     m_writer(writer),
  +     m_writer(&writer),
  +     m_stream(m_writer->getStream()),
        m_maxCharacter(0),
   #if !defined(XALAN_NO_DEFAULT_BUILTIN_ARRAY_INITIALIZATION)
        m_attrCharsMap(),
  @@ -150,18 +152,16 @@
                }
        }
   
  -     XalanOutputStream* const        theStream = m_writer.getStream();
  -
  -     if (theStream != 0)
  +     if (m_stream != 0)
        {
                try
                {
  -                     theStream->setOutputEncoding(m_encoding);
  +                     m_stream->setOutputEncoding(m_encoding);
                }
                catch(const XalanOutputStream::UnsupportedEncodingException&)
                {
                        // Default to UTF-8 if the requested encoding is not 
supported...
  -                     
theStream->setOutputEncoding(XalanDOMString(XalanTranscodingServices::s_utf8String));
  +                     
m_stream->setOutputEncoding(XalanDOMString(XalanTranscodingServices::s_utf8String));
   
                        m_encoding = XalanTranscodingServices::s_utf8String;
                }
  @@ -174,20 +174,38 @@
        if (XalanTranscodingServices::getBytesEqualChars(m_encoding) == true)
        {
                m_bytesEqualChars = true;
  +
  +             if (fBufferData == false)
  +             {
  +                     m_accumNameFunction = &FormatterToXML::accumNameAsByteDirect;
   
  -             m_byteBuf.resize(s_maxBufferSize);
  +                     m_accumContentFunction = 
&FormatterToXML::accumContentAsByteDirect;
  +             }
  +             else
  +             {
  +                     m_byteBuf.resize(s_maxBufferSize);
   
  -             m_accumNameFunction = &FormatterToXML::accumNameAsByte;
  +                     m_accumNameFunction = &FormatterToXML::accumNameAsByte;
   
  -             m_accumContentFunction = &FormatterToXML::accumContentAsByte;
  +                     m_accumContentFunction = &FormatterToXML::accumContentAsByte;
  +             }
        }
        else
        {
  -             m_charBuf.resize(s_maxBufferSize);
  +             if (fBufferData == false)
  +             {
  +                     m_accumNameFunction = &FormatterToXML::accumNameAsCharDirect;
   
  -             m_accumNameFunction = &FormatterToXML::accumNameAsChar;
  +                     m_accumContentFunction = 
&FormatterToXML::accumContentAsCharDirect;
  +             }
  +             else
  +             {
  +                     m_charBuf.resize(s_maxBufferSize);
  +
  +                     m_accumNameFunction = &FormatterToXML::accumNameAsChar;
   
  -             m_accumContentFunction = &FormatterToXML::accumContentAsChar;
  +                     m_accumContentFunction = &FormatterToXML::accumContentAsChar;
  +             }
        }
   
        // Do this last so we initialize the map according to the value of
  @@ -302,6 +320,23 @@
   
   
   void
  +FormatterToXML::accumNameAsByteDirect(XalanDOMChar   ch)
  +{
  +     assert(m_stream != 0);
  +
  +     if (ch > m_maxCharacter)
  +     {
  +             m_stream->write(char(XalanUnicode::charQuestionMark));
  +     }
  +     else
  +     {
  +             m_stream->write(char(ch));
  +     }
  +}
  +
  +
  +
  +void
   FormatterToXML::accumContentAsByte(XalanDOMChar              ch)
   {
        if (ch > m_maxCharacter)
  @@ -322,11 +357,26 @@
   
   
   void
  +FormatterToXML::accumContentAsByteDirect(XalanDOMChar        ch)
  +{
  +     if (ch > m_maxCharacter)
  +     {
  +             writeNumberedEntityReference(ch);
  +     }
  +     else
  +     {
  +             m_stream->write(char(ch));
  +     }
  +}
  +
  +
  +
  +void
   FormatterToXML::accumNameAsChar(XalanDOMChar ch)
   {
        if (ch > m_maxCharacter)
        {
  -             m_charBuf[m_pos++] = char(XalanUnicode::charQuestionMark);
  +             m_charBuf[m_pos++] = XalanUnicode::charQuestionMark;
        }
        else
        {
  @@ -342,6 +392,21 @@
   
   
   void
  +FormatterToXML::accumNameAsCharDirect(XalanDOMChar   ch)
  +{
  +     if (ch > m_maxCharacter)
  +     {
  +             m_stream->write(XalanUnicode::charQuestionMark);
  +     }
  +     else
  +     {
  +             m_stream->write(ch);
  +     }
  +}
  +
  +
  +
  +void
   FormatterToXML::accumContentAsChar(XalanDOMChar      ch)
   {
        if (ch > m_maxCharacter)
  @@ -362,6 +427,21 @@
   
   
   void
  +FormatterToXML::accumContentAsCharDirect(XalanDOMChar        ch)
  +{
  +     if (ch > m_maxCharacter)
  +     {
  +             writeNumberedEntityReference(ch);
  +     }
  +     else
  +     {
  +             m_stream->write(ch);
  +     }
  +}
  +
  +
  +
  +void
   FormatterToXML::accumName(const XalanDOMChar*        chars)
   {
        for(; *chars!= 0; ++chars)
  @@ -583,7 +663,7 @@
   {
        assert(m_charBuf.size() > 0 && m_charBuf.size() >= m_pos);
   
  -     m_writer.write(&m_charBuf[0], 0, m_pos);
  +     m_writer->write(&m_charBuf[0], 0, m_pos);
   
        m_pos = 0;
   }
  @@ -595,7 +675,7 @@
   {
        assert(m_byteBuf.size() > 0 && m_byteBuf.size() >= m_pos);
   
  -     m_writer.write(&m_byteBuf[0], 0, m_pos);
  +     m_writer->write(&m_byteBuf[0], 0, m_pos);
   
        m_pos = 0;
   }
  @@ -605,13 +685,20 @@
   void
   FormatterToXML::flush()
   {
  -     if (m_bytesEqualChars == true)
  +     if (m_stream != 0)
        {
  -             flushBytes();
  +             m_stream->flush();
        }
        else
        {
  -             flushChars();
  +             if (m_bytesEqualChars == true)
  +             {
  +                     flushBytes();
  +             }
  +             else
  +             {
  +                     flushChars();
  +             }
        }
   }
   
  @@ -620,7 +707,9 @@
   void
   FormatterToXML::flushWriter()
   {
  -     m_writer.flush();
  +     assert(m_writer != 0);
  +
  +     m_writer->flush();
   }
   
   
  @@ -1124,6 +1213,15 @@
                        const XMLCh* const      chars,
                        const unsigned int      length)
   {
  +#if 1
  +     // We need to do normalization, which is slower,
  +     // but there you have it...
  +     if (length > 0)
  +     {
  +             characters(chars, length);
  +     }
  +#else
  +     // We'ed like to be able to do this...
        if(m_inEntityRef == false && length != 0)
        {
                assert(isXMLWhitespace(chars, 0, length));
  @@ -1152,6 +1250,7 @@
                        }
                }
        }
  +#endif
   }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to