diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 65f34812d60f..2703be612729 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -287,6 +287,8 @@ void DomainMapper_Impl::SetDocumentSettingsProperty( const ::rtl::OUString& rPro void DomainMapper_Impl::RemoveLastParagraph( ) { + if (m_aTextAppendStack.empty()) + return; uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; if (!xTextAppend.is()) return; @@ -322,9 +324,12 @@ void DomainMapper_Impl::PushProperties(ContextType eId) // beginning with the second section group a section has to be inserted // into the document SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() ); - uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; - if(xTextAppend.is()) - pSectionContext_->SetStart( xTextAppend->getEnd() ); + if (!m_aTextAppendStack.empty()) + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) + pSectionContext_->SetStart( xTextAppend->getEnd() ); + } } m_aPropertyStacks[eId].push( pInsert ); m_aContextStack.push(eId); @@ -699,7 +704,9 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap ) ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() ); TextAppendContext& rAppendContext = m_aTextAppendStack.top(); - uno::Reference< text::XTextAppend > xTextAppend = rAppendContext.xTextAppend; + uno::Reference< text::XTextAppend > xTextAppend; + if (!m_aTextAppendStack.empty()) + xTextAppend = rAppendContext.xTextAppend; PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); #ifdef DEBUG_DOMAINMAPPER @@ -986,6 +993,8 @@ util::DateTime lcl_DateStringToDateTime( const ::rtl::OUString& rDateTime ) } void DomainMapper_Impl::appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap ) { + if (m_aTextAppendStack.empty()) + return; uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; if(xTextAppend.is() && ! getTableManager( ).isIgnore()) { @@ -1087,6 +1096,8 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter( uno::Reference< text::XTextRange >& xBefore ) { uno::Reference< beans::XPropertySet > xRet; + if (m_aTextAppendStack.empty()) + return xRet; uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; if(xTextAppend.is()) { @@ -1127,6 +1138,8 @@ void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType) GetPageStyles(), m_xTextFactory, eType == SectionPropertyMap::PAGE_FIRST ); + if (!xPageStyle.is()) + return; try { PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); @@ -1164,6 +1177,8 @@ void DomainMapper_Impl::PushPageFooter(SectionPropertyMap::PageType eType) GetPageStyles(), m_xTextFactory, eType == SectionPropertyMap::PAGE_FIRST ); + if (!xPageStyle.is()) + return; try { PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); @@ -1192,7 +1207,8 @@ void DomainMapper_Impl::PopPageHeaderFooter() //header and footer always have an empty paragraph at the end //this has to be removed RemoveLastParagraph( ); - m_aTextAppendStack.pop(); + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.pop(); } @@ -1201,7 +1217,9 @@ void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote ) try { PropertyMapPtr pTopContext = GetTopContext(); - uno::Reference< text::XText > xFootnoteText( GetTextFactory()->createInstance( + uno::Reference< text::XText > xFootnoteText; + if (GetTextFactory().is()) + xFootnoteText.set( GetTextFactory()->createInstance( bIsFootnote ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Footnote") ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote") )), uno::UNO_QUERY_THROW ); @@ -1322,6 +1340,8 @@ void DomainMapper_Impl::PushAnnotation() try { PropertyMapPtr pTopContext = GetTopContext(); + if (!GetTextFactory().is()) + return; m_xAnnotationField = uno::Reference< beans::XPropertySet >( GetTextFactory()->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.Annotation") ) ), uno::UNO_QUERY_THROW ); @@ -1339,7 +1359,8 @@ void DomainMapper_Impl::PushAnnotation() void DomainMapper_Impl::PopFootOrEndnote() { RemoveLastParagraph(); - m_aTextAppendStack.pop(); + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.pop(); } @@ -1709,12 +1730,19 @@ void DomainMapper_Impl::PushFieldContext() dmapper_logger->element("pushFieldContext"); #endif - uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; - //insert a dummy char to make sure the start range doesn't move together with the to-be-appended text - xTextAppend->appendTextPortion(::rtl::OUString( '-' ), uno::Sequence< beans::PropertyValue >() ); - uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() ); - xCrsr->goLeft( 1, false ); - m_aFieldStack.push( FieldContextPtr( new FieldContext( xCrsr->getStart() ) ) ); + uno::Reference< text::XTextAppend > xTextAppend; + if (!m_aTextAppendStack.empty()) + xTextAppend = m_aTextAppendStack.top().xTextAppend; + uno::Reference< text::XTextRange > xStart; + if (xTextAppend.is()) + { + //insert a dummy char to make sure the start range doesn't move together with the to-be-appended text + xTextAppend->appendTextPortion(::rtl::OUString( '-' ), uno::Sequence< beans::PropertyValue >() ); + uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() ); + xCrsr->goLeft( 1, false ); + xStart = xCrsr->getStart(); + } + m_aFieldStack.push( FieldContextPtr( new FieldContext( xStart ) ) ); } /*------------------------------------------------------------------------- //the current field context waits for the completion of the command @@ -2245,15 +2273,18 @@ void DomainMapper_Impl::handleToc if( !bFromOutline && !bFromEntries && !sTemplate.getLength() ) bFromOutline = true; - uno::Reference< beans::XPropertySet > xTOC( - m_xTextFactory->createInstance - ( bTableOfFigures ? - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM - ("com.sun.star.text.IllustrationsIndex")) - : sTOCServiceName), - uno::UNO_QUERY_THROW); - xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(::rtl::OUString())); - if( !bTableOfFigures ) + uno::Reference< beans::XPropertySet > xTOC; + if (m_xTextFactory.is()) + xTOC.set( + m_xTextFactory->createInstance + ( bTableOfFigures ? + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.text.IllustrationsIndex")) + : sTOCServiceName), + uno::UNO_QUERY_THROW); + if (xTOC.is()) + xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(::rtl::OUString())); + if( !bTableOfFigures && xTOC.is() ) { xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_LEVEL ), uno::makeAny( nMaxLevel ) ); xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline )); @@ -2438,8 +2469,11 @@ void DomainMapper_Impl::CloseFieldCommand() dmapper_logger->endElement(); #endif - xFieldInterface = m_xTextFactory->createInstance(sServiceName); - xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW); + if (m_xTextFactory.is()) + { + xFieldInterface = m_xTextFactory->createInstance(sServiceName); + xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW); + } } PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); switch( aIt->second.eFieldId ) @@ -2661,12 +2695,15 @@ void DomainMapper_Impl::CloseFieldCommand() case FIELD_NEXT : break; case FIELD_NEXTIF : break; case FIELD_PAGE : - xFieldProperties->setPropertyValue( - rPropNameSupplier.GetName(PROP_NUMBERING_TYPE), - uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); - xFieldProperties->setPropertyValue( - rPropNameSupplier.GetName(PROP_SUB_TYPE), - uno::makeAny( text::PageNumberType_CURRENT )); + if (xFieldProperties.is()) + { + xFieldProperties->setPropertyValue( + rPropNameSupplier.GetName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + xFieldProperties->setPropertyValue( + rPropNameSupplier.GetName(PROP_SUB_TYPE), + uno::makeAny( text::PageNumberType_CURRENT )); + } break; case FIELD_REF: @@ -2902,7 +2939,9 @@ void DomainMapper_Impl::PopFieldContext() CloseFieldCommand(); //insert the field, TC or TOC - uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + uno::Reference< text::XTextAppend > xTextAppend; + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.top().xTextAppend; if(xTextAppend.is()) { try @@ -2986,33 +3025,41 @@ void DomainMapper_Impl::AddBookmark( const ::rtl::OUString& rBookmarkName, const if( aBookmarkIter != m_aBookmarkMap.end() ) { static const rtl::OUString sBookmarkService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark")); - uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( sBookmarkService ), uno::UNO_QUERY_THROW ); - uno::Reference< text::XTextCursor > xCursor; - uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText(); - if( aBookmarkIter->second.m_bIsStartOfText ) - xCursor = xText->createTextCursorByRange( xText->getStart() ); - else + if (m_xTextFactory.is()) { - xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange ); - xCursor->goRight( 1, false ); - } + uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( sBookmarkService ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextCursor > xCursor; + uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText(); + if( aBookmarkIter->second.m_bIsStartOfText ) + xCursor = xText->createTextCursorByRange( xText->getStart() ); + else + { + xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange ); + xCursor->goRight( 1, false ); + } - xCursor->gotoRange( xTextAppend->getEnd(), true ); - uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW ); - //todo: make sure the name is not used already! - if ( aBookmarkIter->second.m_sBookmarkName.getLength() > 0 ) - xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName ); - else - xBkmNamed->setName( rBookmarkName ); - xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() ); + xCursor->gotoRange( xTextAppend->getEnd(), true ); + uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW ); + //todo: make sure the name is not used already! + if ( aBookmarkIter->second.m_sBookmarkName.getLength() > 0 ) + xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName ); + else + xBkmNamed->setName( rBookmarkName ); + xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() ); + } m_aBookmarkMap.erase( aBookmarkIter ); } else { //otherwise insert a text range as marker - uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() ); - bool bIsStart = !xCursor->goLeft(1, false); - uno::Reference< text::XTextRange > xCurrent = xCursor->getStart(); + bool bIsStart = true; + uno::Reference< text::XTextRange > xCurrent; + if (xTextAppend.is()) + { + uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() ); + bIsStart = !xCursor->goLeft(1, false); + xCurrent = xCursor->getStart(); + } m_aBookmarkMap.insert(BookmarkMap_t::value_type( rId, BookmarkInsertPosition( bIsStart, rBookmarkName, xCurrent ) )); } } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index bfe5cffc08f5..7cadff2d091e 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -506,7 +506,8 @@ void SectionPropertyMap::ApplyBorderToPageStyles( if( m_pBorderLines[nBorder] ) { const ::rtl::OUString sBorderName = rPropNameSupplier.GetName( aBorderIds[nBorder] ); - xFirst->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] )); + if (xFirst.is()) + xFirst->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] )); if(xSecond.is()) xSecond->setPropertyValue( sBorderName, uno::makeAny( *m_pBorderLines[nBorder] )); } @@ -541,7 +542,8 @@ void SectionPropertyMap::SetBorderDistance( uno::Reference< beans::XPropertySet nDist = nMargin - nDistance; } const ::rtl::OUString sBorderDistanceName = rPropNameSupplier.GetName( eDistId ); - xStyle->setPropertyValue( sBorderDistanceName, uno::makeAny( nDist )); + if (xStyle.is()) + xStyle->setPropertyValue( sBorderDistanceName, uno::makeAny( nDist )); } @@ -554,7 +556,8 @@ uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties( { PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); const ::rtl::OUString sTextColumns = rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ); - xColumnContainer->getPropertyValue(sTextColumns) >>= xColumns; + if (xColumnContainer.is()) + xColumnContainer->getPropertyValue(sTextColumns) >>= xColumns; uno::Reference< beans::XPropertySet > xColumnPropSet( xColumns, uno::UNO_QUERY_THROW ); if( !m_bEvenlySpaced && (sal_Int32(m_aColWidth.size()) == (m_nColumnCount + 1 )) && @@ -673,8 +676,10 @@ void SectionPropertyMap::CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Imp bool bHasHeader = false; rtl::OUString sHeaderIsOn = rPropNameSupplier.GetName( PROP_HEADER_IS_ON ); - xPrevStyle->getPropertyValue( sHeaderIsOn ) >>= bHasPrevHeader; - xStyle->getPropertyValue( sHeaderIsOn ) >>= bHasHeader; + if (xPrevStyle.is()) + xPrevStyle->getPropertyValue( sHeaderIsOn ) >>= bHasPrevHeader; + if (xStyle.is()) + xStyle->getPropertyValue( sHeaderIsOn ) >>= bHasHeader; bool bCopyHeader = bHasPrevHeader && !bHasHeader; if ( bCopyHeader ) @@ -684,11 +689,13 @@ void SectionPropertyMap::CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Imp bool bHasFooter = false; rtl::OUString sFooterIsOn = rPropNameSupplier.GetName( PROP_FOOTER_IS_ON ); - xPrevStyle->getPropertyValue( sFooterIsOn ) >>= bHasPrevFooter; - xStyle->getPropertyValue( sFooterIsOn ) >>= bHasFooter; + if (xPrevStyle.is()) + xPrevStyle->getPropertyValue( sFooterIsOn ) >>= bHasPrevFooter; + if (xStyle.is()) + xStyle->getPropertyValue( sFooterIsOn ) >>= bHasFooter; bool bCopyFooter = bHasPrevFooter && !bHasFooter; - if ( bCopyFooter ) + if ( bCopyFooter && xStyle.is() ) xStyle->setPropertyValue( sFooterIsOn, uno::makeAny( sal_True ) ); // Copying the text properties @@ -705,11 +712,13 @@ void SectionPropertyMap::CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Imp clog << rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr( ) << endl; #endif // TODO has to be copied - uno::Reference< text::XTextCopy > xTxt( - xStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextCopy > xTxt; + if (xStyle.is()) + xTxt.set(xStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW ); - uno::Reference< text::XTextCopy > xPrevTxt( - xPrevStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextCopy > xPrevTxt; + if (xPrevStyle.is()) + xPrevTxt.set(xPrevStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW ); xTxt->copyText( xPrevTxt ); }