1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "fastserializer.hxx" 29*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 30*cdf0e10cSrcweir #include <rtl/byteseq.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/xml/Attribute.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/xml/FastAttribute.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XFastAttributeList.hpp> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <string.h> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using ::rtl::OString; 39*cdf0e10cSrcweir using ::rtl::OUString; 40*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 41*cdf0e10cSrcweir using ::rtl::OUStringToOString; 42*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 43*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 44*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 45*cdf0e10cSrcweir using ::com::sun::star::uno::toUnoSequence; 46*cdf0e10cSrcweir using ::com::sun::star::xml::FastAttribute; 47*cdf0e10cSrcweir using ::com::sun::star::xml::Attribute; 48*cdf0e10cSrcweir using ::com::sun::star::xml::sax::SAXException; 49*cdf0e10cSrcweir using ::com::sun::star::xml::sax::XFastAttributeList; 50*cdf0e10cSrcweir using ::com::sun::star::xml::sax::XFastTokenHandler; 51*cdf0e10cSrcweir using ::com::sun::star::xml::sax::XFastSerializer; 52*cdf0e10cSrcweir using ::com::sun::star::io::XOutputStream; 53*cdf0e10cSrcweir using ::com::sun::star::io::NotConnectedException; 54*cdf0e10cSrcweir using ::com::sun::star::io::IOException; 55*cdf0e10cSrcweir using ::com::sun::star::io::BufferSizeExceededException; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir static rtl::ByteSequence aClosingBracket((const sal_Int8 *)">", 1); 58*cdf0e10cSrcweir static rtl::ByteSequence aSlashAndClosingBracket((const sal_Int8 *)"/>", 2); 59*cdf0e10cSrcweir static rtl::ByteSequence aColon((const sal_Int8 *)":", 1); 60*cdf0e10cSrcweir static rtl::ByteSequence aOpeningBracket((const sal_Int8 *)"<", 1); 61*cdf0e10cSrcweir static rtl::ByteSequence aOpeningBracketAndSlash((const sal_Int8 *)"</", 2); 62*cdf0e10cSrcweir static rtl::ByteSequence aQuote((const sal_Int8 *)"\"", 1); 63*cdf0e10cSrcweir static rtl::ByteSequence aEqualSignAndQuote((const sal_Int8 *)"=\"", 2); 64*cdf0e10cSrcweir static rtl::ByteSequence aSpace((const sal_Int8 *)" ", 1); 65*cdf0e10cSrcweir static rtl::ByteSequence aXmlHeader((const sal_Int8*) "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n", 56); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #define HAS_NAMESPACE(x) ((x & 0xffff0000) != 0) 68*cdf0e10cSrcweir #define NAMESPACE(x) (x >> 16) 69*cdf0e10cSrcweir #define TOKEN(x) (x & 0xffff) 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir namespace sax_fastparser { 72*cdf0e10cSrcweir FastSaxSerializer::FastSaxSerializer( ) : mxOutputStream(), mxFastTokenHandler(), maMarkStack() {} 73*cdf0e10cSrcweir FastSaxSerializer::~FastSaxSerializer() {} 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::startDocument( ) throw (SAXException, RuntimeException) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir if (!mxOutputStream.is()) 78*cdf0e10cSrcweir return; 79*cdf0e10cSrcweir writeBytes(toUnoSequence(aXmlHeader)); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir OUString FastSaxSerializer::escapeXml( const OUString& s ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir ::rtl::OUStringBuffer sBuf( s.getLength() ); 85*cdf0e10cSrcweir const sal_Unicode* pStr = s; 86*cdf0e10cSrcweir sal_Int32 nLen = s.getLength(); 87*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nLen; ++i) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir sal_Unicode c = pStr[ i ]; 90*cdf0e10cSrcweir switch( c ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir case '<': sBuf.appendAscii( "<" ); break; 93*cdf0e10cSrcweir case '>': sBuf.appendAscii( ">" ); break; 94*cdf0e10cSrcweir case '&': sBuf.appendAscii( "&" ); break; 95*cdf0e10cSrcweir case '\'': sBuf.appendAscii( "'" ); break; 96*cdf0e10cSrcweir case '"': sBuf.appendAscii( """ ); break; 97*cdf0e10cSrcweir default: sBuf.append( c ); break; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir return sBuf.makeStringAndClear(); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void FastSaxSerializer::write( const OUString& s ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir OString sOutput( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ) ); 106*cdf0e10cSrcweir writeBytes( Sequence< sal_Int8 >( 107*cdf0e10cSrcweir reinterpret_cast< const sal_Int8*>( sOutput.getStr() ), 108*cdf0e10cSrcweir sOutput.getLength() ) ); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::endDocument( ) throw (SAXException, RuntimeException) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir if (!mxOutputStream.is()) 114*cdf0e10cSrcweir return; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::writeId( ::sal_Int32 nElement ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir if( HAS_NAMESPACE( nElement ) ) { 120*cdf0e10cSrcweir writeBytes(mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement))); 121*cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 122*cdf0e10cSrcweir writeBytes(mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement))); 123*cdf0e10cSrcweir } else 124*cdf0e10cSrcweir writeBytes(mxFastTokenHandler->getUTF8Identifier(nElement)); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::startFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs ) 128*cdf0e10cSrcweir throw (SAXException, RuntimeException) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir if (!mxOutputStream.is()) 131*cdf0e10cSrcweir return; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir writeId(Element); 136*cdf0e10cSrcweir writeFastAttributeList(Attribs); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::startUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs ) 142*cdf0e10cSrcweir throw (SAXException, RuntimeException) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir if (!mxOutputStream.is()) 145*cdf0e10cSrcweir return; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir if (Namespace.getLength()) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir write(Namespace); 152*cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir write(Name); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir writeFastAttributeList(Attribs); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::endFastElement( ::sal_Int32 Element ) 163*cdf0e10cSrcweir throw (SAXException, RuntimeException) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir if (!mxOutputStream.is()) 166*cdf0e10cSrcweir return; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracketAndSlash)); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir writeId(Element); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::endUnknownElement( const OUString& Namespace, const OUString& Name ) 176*cdf0e10cSrcweir throw (SAXException, RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir if (!mxOutputStream.is()) 179*cdf0e10cSrcweir return; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracketAndSlash)); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir if (Namespace.getLength()) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir write(Namespace); 186*cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir write(Name); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::singleFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs ) 195*cdf0e10cSrcweir throw (SAXException, RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir if (!mxOutputStream.is()) 198*cdf0e10cSrcweir return; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir writeId(Element); 203*cdf0e10cSrcweir writeFastAttributeList(Attribs); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir writeBytes(toUnoSequence(aSlashAndClosingBracket)); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::singleUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs ) 209*cdf0e10cSrcweir throw (SAXException, RuntimeException) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir if (!mxOutputStream.is()) 212*cdf0e10cSrcweir return; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir if (Namespace.getLength()) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir write(Namespace); 219*cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir write(Name); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir writeFastAttributeList(Attribs); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir writeBytes(toUnoSequence(aSlashAndClosingBracket)); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::characters( const OUString& aChars ) 230*cdf0e10cSrcweir throw (SAXException, RuntimeException) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir if (!mxOutputStream.is()) 233*cdf0e10cSrcweir return; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir write( aChars ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream ) 239*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir mxOutputStream = xOutputStream; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler ) 245*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir mxFastTokenHandler = xFastTokenHandler; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir void FastSaxSerializer::writeFastAttributeList( const Reference< XFastAttributeList >& Attribs ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir Sequence< Attribute > aAttrSeq = Attribs->getUnknownAttributes(); 252*cdf0e10cSrcweir const Attribute *pAttr = aAttrSeq.getConstArray(); 253*cdf0e10cSrcweir sal_Int32 nAttrLength = aAttrSeq.getLength(); 254*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nAttrLength; i++) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir writeBytes(toUnoSequence(aSpace)); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir write(pAttr[i].Name); 259*cdf0e10cSrcweir writeBytes(toUnoSequence(aEqualSignAndQuote)); 260*cdf0e10cSrcweir write(escapeXml(pAttr[i].Value)); 261*cdf0e10cSrcweir writeBytes(toUnoSequence(aQuote)); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir Sequence< FastAttribute > aFastAttrSeq = Attribs->getFastAttributes(); 265*cdf0e10cSrcweir const FastAttribute *pFastAttr = aFastAttrSeq.getConstArray(); 266*cdf0e10cSrcweir sal_Int32 nFastAttrLength = aFastAttrSeq.getLength(); 267*cdf0e10cSrcweir for (sal_Int32 j = 0; j < nFastAttrLength; j++) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir writeBytes(toUnoSequence(aSpace)); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir sal_Int32 nToken = pFastAttr[j].Token; 272*cdf0e10cSrcweir writeId(nToken); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir writeBytes(toUnoSequence(aEqualSignAndQuote)); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir write(escapeXml(Attribs->getValue(pFastAttr[j].Token))); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir writeBytes(toUnoSequence(aQuote)); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // XServiceInfo 283*cdf0e10cSrcweir OUString FastSaxSerializer::getImplementationName() throw (RuntimeException) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir return OUString::createFromAscii( SERIALIZER_IMPLEMENTATION_NAME ); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir // XServiceInfo 289*cdf0e10cSrcweir sal_Bool FastSaxSerializer::supportsService(const OUString& ServiceName) throw (RuntimeException) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 292*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 295*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 296*cdf0e10cSrcweir return sal_True; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir return sal_False; 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // XServiceInfo 302*cdf0e10cSrcweir Sequence< OUString > FastSaxSerializer::getSupportedServiceNames(void) throw (RuntimeException) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir Sequence<OUString> seq(1); 305*cdf0e10cSrcweir seq.getArray()[0] = OUString::createFromAscii( SERIALIZER_SERVICE_NAME ); 306*cdf0e10cSrcweir return seq; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir OUString FastSaxSerializer::getImplementationName_Static() 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir return OUString::createFromAscii( SERIALIZER_IMPLEMENTATION_NAME ); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir Sequence< OUString > FastSaxSerializer::getSupportedServiceNames_Static(void) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir Sequence<OUString> aRet(1); 317*cdf0e10cSrcweir aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(SERIALIZER_SERVICE_NAME) ); 318*cdf0e10cSrcweir return aRet; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir void FastSaxSerializer::mark() 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir maMarkStack.push( ForMerge() ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir void FastSaxSerializer::mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir if ( maMarkStack.empty() ) 329*cdf0e10cSrcweir return; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir if ( maMarkStack.size() == 1 ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir mxOutputStream->writeBytes( maMarkStack.top().getData() ); 334*cdf0e10cSrcweir maMarkStack.pop(); 335*cdf0e10cSrcweir return; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir const Int8Sequence aMerge( maMarkStack.top().getData() ); 339*cdf0e10cSrcweir maMarkStack.pop(); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir switch ( eMergeType ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir case MERGE_MARKS_APPEND: maMarkStack.top().append( aMerge ); break; 344*cdf0e10cSrcweir case MERGE_MARKS_PREPEND: maMarkStack.top().prepend( aMerge ); break; 345*cdf0e10cSrcweir case MERGE_MARKS_POSTPONE: maMarkStack.top().postpone( aMerge ); break; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir void FastSaxSerializer::writeBytes( const Sequence< ::sal_Int8 >& aData ) throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir if ( maMarkStack.empty() ) 352*cdf0e10cSrcweir mxOutputStream->writeBytes( aData ); 353*cdf0e10cSrcweir else 354*cdf0e10cSrcweir maMarkStack.top().append( aData ); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData() 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir merge( maData, maPostponed, true ); 360*cdf0e10cSrcweir maPostponed.realloc( 0 ); 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir return maData; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir void FastSaxSerializer::ForMerge::prepend( const Int8Sequence &rWhat ) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir merge( maData, rWhat, false ); 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir void FastSaxSerializer::ForMerge::append( const Int8Sequence &rWhat ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir merge( maData, rWhat, true ); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir void FastSaxSerializer::ForMerge::postpone( const Int8Sequence &rWhat ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir merge( maPostponed, rWhat, true ); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend ) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir sal_Int32 nMergeLen = rMerge.getLength(); 383*cdf0e10cSrcweir if ( nMergeLen > 0 ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir sal_Int32 nTopLen = rTop.getLength(); 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir rTop.realloc( nTopLen + nMergeLen ); 388*cdf0e10cSrcweir if ( bAppend ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir // append the rMerge to the rTop 391*cdf0e10cSrcweir memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), nMergeLen ); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir else 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir // prepend the rMerge to the rTop 396*cdf0e10cSrcweir memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), nTopLen ); 397*cdf0e10cSrcweir memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen ); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir } // namespace sax_fastparser 403*cdf0e10cSrcweir 404