24#include <com/sun/star/io/IOException.hpp>
25#include <com/sun/star/lang/DisposedException.hpp>
26#include <com/sun/star/xml/sax/SAXException.hpp>
27#include <com/sun/star/xml/sax/XLocator.hpp>
29#include <osl/diagnose.h>
41class Locator :
public ::cppu::WeakImplHelper< XLocator >
69 throw DisposedException();
128 return !
maStack.empty() && (
maStack.back().first.mnEndRecId >= 0);
141 "ContextStack::pushContext - nested incomplete context record identifiers" );
142 maStack.emplace_back( rRecInfo, rxContext );
147 OSL_ENSURE( !
maStack.empty(),
"ContextStack::popContext - no context on stack" );
151 if( rContextInfo.second.is() )
152 rContextInfo.second->endRecord( rContextInfo.first.mnStartRecId );
164 return rStrm.readMemory( &ornByte, 1 ) == 1;
172 if( !lclReadByte( nByte, rStrm ) )
return false;
173 ornValue = nByte & 0x7F;
174 if( (nByte & 0x80) == 0 )
return true;
175 if( !lclReadByte( nByte, rStrm ) )
return false;
176 ornValue |= sal_Int32( nByte & 0x7F ) << 7;
177 if( (nByte & 0x80) == 0 )
return true;
178 if( !lclReadByte( nByte, rStrm ) )
return false;
179 ornValue |= sal_Int32( nByte & 0x7F ) << 14;
180 if( (nByte & 0x80) == 0 )
return true;
181 if( !lclReadByte( nByte, rStrm ) )
return false;
182 ornValue |= sal_Int32( nByte & 0x7F ) << 21;
186bool lclReadRecordHeader( sal_Int32& ornRecId, sal_Int32& ornRecSize, BinaryInputStream& rStrm )
189 lclReadCompressedInt( ornRecId, rStrm ) && (ornRecId >= 0) &&
190 lclReadCompressedInt( ornRecSize, rStrm ) && (ornRecSize >= 0);
193bool lclReadNextRecord( sal_Int32& ornRecId,
StreamDataSequence& orData, BinaryInputStream& rStrm )
195 sal_Int32 nRecSize = 0;
196 bool bValid = lclReadRecordHeader( ornRecId, nRecSize, rStrm );
199 orData.realloc( nRecSize );
200 bValid = (nRecSize == 0) || (
rStrm.readData( orData, nRecSize ) == nRecSize);
226 OSL_ENSURE( pRecs,
"RecordInfoProvider::RecordInfoProvider - missing record list" );
242 throw SAXException();
250 sal_Int32 nRecId = 0;
263 OSL_ENSURE(
mxStack->getCurrentRecId() == pEndRecInfo->mnStartRecId,
"RecordParser::parseStream - context records mismatch" );
265 if( xCurrContext.is() )
269 xCurrContext->startRecord( nRecId, aRecStrm );
270 xCurrContext->endRecord( nRecId );
277 if( (
mxStack->getCurrentRecId() == nRecId) && !
mxStack->hasCurrentEndRecId() )
281 if( xCurrContext.is() )
284 xCurrContext = xCurrContext->createRecordContext( nRecId, aRecStrm );
289 mxStack->pushContext( *pStartRecInfo, xCurrContext );
291 if( xCurrContext.is() )
295 xCurrContext->startRecord( nRecId, aRecStrm );
298 xCurrContext->endRecord( nRecId );
315 RecordInfoMap::const_iterator aIt =
maStartMap.find( nRecId );
316 return (aIt ==
maStartMap.end()) ? nullptr : &aIt->second;
321 RecordInfoMap::const_iterator aIt =
maEndMap.find( nRecId );
322 return (aIt ==
maEndMap.end()) ? nullptr : &aIt->second;
void seekToStart()
Seeks the stream to the beginning, if stream is seekable.
::rtl::Reference< FragmentHandler > mxHandler
void setFragmentHandler(const ::rtl::Reference< FragmentHandler > &rxHandler)
const RecordInfo * getEndRecordInfo(sal_Int32 nRecId) const
Returns a RecordInfo struct that contains the passed record identifier as context end identifier.
const RecordInfo * getStartRecordInfo(sal_Int32 nRecId) const
Returns a RecordInfo struct that contains the passed record identifier as context start identifier.
::std::unique_ptr< prv::ContextStack > mxStack
RecordInputSource maSource
::rtl::Reference< prv::Locator > mxLocator
const RecordInputSource & getInputSource() const
void parseStream(const RecordInputSource &rInputSource)
void pushContext(const RecordInfo &rRec, const ContextHandlerRef &rxContext)
::std::pair< RecordInfo, ContextHandlerRef > ContextInfo
FragmentHandlerRef mxHandler
::std::vector< ContextInfo > ContextInfoVec
sal_Int32 getCurrentRecId() const
ContextStack(FragmentHandlerRef xHandler)
ContextHandlerRef getCurrentContext() const
bool hasCurrentEndRecId() const
virtual sal_Int32 SAL_CALL getLineNumber() override
virtual OUString SAL_CALL getSystemId() override
virtual sal_Int32 SAL_CALL getColumnNumber() override
virtual OUString SAL_CALL getPublicId() override
Locator(RecordParser *pParser)
css::uno::Sequence< sal_Int8 > StreamDataSequence
Describes record identifiers used to create contexts in a binary stream.
sal_Int32 mnEndRecId
Record identifier for context end, -1 = no record.
sal_Int32 mnStartRecId
Record identifier for context start.
rtl::Reference< FragmentHandler > mxHandler