diff options
Diffstat (limited to 'sax/source/expatwrap')
-rw-r--r-- | sax/source/expatwrap/sax_expat.cxx | 31 | ||||
-rw-r--r-- | sax/source/expatwrap/saxwriter.cxx | 25 |
2 files changed, 52 insertions, 4 deletions
diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx index d9553113c759..e1f5161b7e3a 100644 --- a/sax/source/expatwrap/sax_expat.cxx +++ b/sax/source/expatwrap/sax_expat.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> #include <com/sun/star/xml/sax/XParser.hpp> #include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/io/XSeekable.hpp> #include <cppuhelper/factory.hxx> #include <cppuhelper/weak.hxx> @@ -135,6 +136,11 @@ OUString XmlChar2OUString( const XML_Char *p ) pThis->rDocumentLocator->getColumnNumber()\ ) );\ }\ + catch( com::sun::star::uno::RuntimeException &e ) {\ + pThis->bExceptionWasThrown = sal_True; \ + pThis->bRTExceptionWasThrown = sal_True; \ + pImpl->rtexception = e; \ + }\ }\ ((void)0) @@ -255,7 +261,9 @@ public: // module scope // Exception cannot be thrown through the C-XmlParser (possible resource leaks), // therefor the exception must be saved somewhere. SAXParseException exception; - sal_Bool bExceptionWasThrown; + RuntimeException rtexception; + sal_Bool bExceptionWasThrown; + sal_Bool bRTExceptionWasThrown; Locale locale; @@ -374,7 +382,8 @@ extern "C" // LocatorImpl //--------------------------------------------- class LocatorImpl : - public WeakImplHelper1< XLocator > + public WeakImplHelper2< XLocator, com::sun::star::io::XSeekable > + // should use a different interface for stream positions! { public: LocatorImpl( SaxExpatParser_Impl *p ) @@ -400,6 +409,20 @@ public: //XLocator return m_pParser->getEntity().structSource.sSystemId; } + // XSeekable (only for getPosition) + + virtual void SAL_CALL seek( sal_Int64 ) throw() + { + } + virtual sal_Int64 SAL_CALL getPosition() throw() + { + return XML_GetCurrentByteIndex( m_pParser->getEntity().pParser ); + } + virtual ::sal_Int64 SAL_CALL getLength() throw() + { + return 0; + } + private: SaxExpatParser_Impl *m_pParser; @@ -421,6 +444,7 @@ SaxExpatParser::SaxExpatParser( ) m_pImpl->rAttrList = Reference< XAttributeList > ( m_pImpl->pAttrList ); m_pImpl->bExceptionWasThrown = sal_False; + m_pImpl->bRTExceptionWasThrown = sal_False; } SaxExpatParser::~SaxExpatParser() @@ -721,6 +745,9 @@ void SaxExpatParser_Impl::parse( ) if( ! bContinue || this->bExceptionWasThrown ) { + if ( this->bRTExceptionWasThrown ) + throw rtexception; + // Error during parsing ! XML_Error xmlE = XML_GetErrorCode( getEntity().pParser ); OUString sSystemId = rDocumentLocator->getSystemId(); diff --git a/sax/source/expatwrap/saxwriter.cxx b/sax/source/expatwrap/saxwriter.cxx index 9be52cdd24c3..717767d86e11 100644 --- a/sax/source/expatwrap/saxwriter.cxx +++ b/sax/source/expatwrap/saxwriter.cxx @@ -208,6 +208,8 @@ public: // If there are invalid characters in the string it returns sal_False. // Than the calling method has to throw the needed Exception. inline sal_Bool comment(const rtl::OUString& rComment) throw( SAXException ); + + inline void clearBuffer() throw( SAXException ); }; const sal_Bool g_bValidCharsBelow32[32] = @@ -434,7 +436,7 @@ inline sal_Bool SaxWriterHelper::convertToXML( const sal_Unicode * pStr, OSL_ENSURE( nSurrogate != 0, "lone 2nd Unicode surrogate" ); nSurrogate = ( nSurrogate << 10 ) | ( c & 0x03ff ); - if( nSurrogate > 0x00010000 && nSurrogate <= 0x001FFFFF ) + if( nSurrogate >= 0x00010000 && nSurrogate <= 0x0010FFFF ) { sal_Int8 aBytes[] = { sal_Int8(0xF0 | ((nSurrogate >> 18) & 0x0F)), sal_Int8(0x80 | ((nSurrogate >> 12) & 0x3F)), @@ -693,6 +695,17 @@ inline void SaxWriterHelper::endDocument() throw( SAXException ) } } +inline void SaxWriterHelper::clearBuffer() throw( SAXException ) +{ + FinishStartElement(); + if (nCurrentPos > 0) + { + m_Sequence.realloc(nCurrentPos); + nCurrentPos = writeSequence(); + m_Sequence.realloc(SEQUENCESIZE); + } +} + inline sal_Bool SaxWriterHelper::processingInstruction(const rtl::OUString& rTarget, const rtl::OUString& rData) throw( SAXException ) { FinishStartElement(); @@ -851,7 +864,7 @@ inline sal_Int32 calcXMLByteLength( const sal_Unicode *pStr, sal_Int32 nStrLen, { // 2. surrogate: write as UTF-8 (if range is OK nSurrogate = ( nSurrogate << 10 ) | ( c & 0x03ff ); - if( nSurrogate > 0x00010000 && nSurrogate <= 0x001FFFFF ) + if( nSurrogate >= 0x00010000 && nSurrogate <= 0x0010FFFF ) nOutputLength += 4; nSurrogate = 0; } @@ -927,12 +940,20 @@ public: // XActiveDataSource virtual void SAL_CALL setOutputStream(const Reference< XOutputStream > & aStream) throw (RuntimeException) { + // temporary: set same stream again to clear buffer + if ( m_out == aStream && mp_SaxWriterHelper && m_bDocStarted ) + mp_SaxWriterHelper->clearBuffer(); + else + { + m_out = aStream; delete mp_SaxWriterHelper; mp_SaxWriterHelper = new SaxWriterHelper(m_out); m_bDocStarted = sal_False; m_nLevel = 0; m_bIsCDATA = sal_False; + + } } virtual Reference< XOutputStream > SAL_CALL getOutputStream(void) throw(RuntimeException) |