2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* $RCSfile: XMLTextListBlockContext.cxx,v $
|
2008-06-13 08:19:20 +00:00
|
|
|
* $Revision: 1.12 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:22:15 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 10:13:54 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_xmloff.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#include <com/sun/star/container/XIndexReplace.hpp>
|
|
|
|
#include <com/sun/star/style/XStyle.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2007-06-27 15:09:39 +00:00
|
|
|
#include <xmloff/xmlimp.hxx>
|
|
|
|
#include <xmloff/xmlnumi.hxx>
|
|
|
|
#include <xmloff/nmspmap.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "xmlnmspe.hxx"
|
2007-06-27 15:09:39 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "XMLTextListItemContext.hxx"
|
|
|
|
#include "XMLTextListBlockContext.hxx"
|
|
|
|
|
2008-03-12 10:03:13 +00:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::style;
|
|
|
|
using namespace ::com::sun::star::beans;
|
2001-06-29 20:07:26 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
TYPEINIT1( XMLTextListBlockContext, SvXMLImportContext );
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
// OD 2008-05-07 #refactorlists#
|
|
|
|
// add optional parameter <bRestartNumberingAtSubList> and its handling
|
2000-09-18 16:07:07 +00:00
|
|
|
XMLTextListBlockContext::XMLTextListBlockContext(
|
|
|
|
SvXMLImport& rImport,
|
|
|
|
XMLTextImportHelper& rTxtImp,
|
2008-06-13 08:19:20 +00:00
|
|
|
sal_uInt16 nPrfx,
|
|
|
|
const OUString& rLName,
|
|
|
|
const Reference< xml::sax::XAttributeList > & xAttrList,
|
|
|
|
const sal_Bool bRestartNumberingAtSubList )
|
2006-06-19 17:46:27 +00:00
|
|
|
: SvXMLImportContext( rImport, nPrfx, rLName )
|
2008-06-13 08:19:20 +00:00
|
|
|
, mrTxtImport( rTxtImp )
|
|
|
|
// --> OD 2008-04-22 #refactorlists#
|
|
|
|
, msListStyleName()
|
|
|
|
// <--
|
|
|
|
, mxParentListBlock( rTxtImp.GetListBlock() )
|
|
|
|
, mnLevel( 0 )
|
|
|
|
// --> OD 2008-05-07 #refactorlists#
|
|
|
|
//, mbRestartNumbering( sal_True )
|
|
|
|
, mbRestartNumbering( sal_False )
|
|
|
|
// <--
|
|
|
|
, mbSetDefaults( sal_False )
|
|
|
|
// --> OD 2008-04-22 #refactorlists#
|
|
|
|
, msListId()
|
|
|
|
, msContinueListId()
|
|
|
|
// <--
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// Inherit style name from parent list, as well as the flags whether
|
|
|
|
// numbering must be restarted and formats have to be created.
|
2008-06-13 08:19:20 +00:00
|
|
|
OUString sParentListStyleName;
|
|
|
|
if( mxParentListBlock.Is() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
XMLTextListBlockContext *pParent =
|
2008-06-13 08:19:20 +00:00
|
|
|
(XMLTextListBlockContext *)&mxParentListBlock;
|
|
|
|
msListStyleName = pParent->GetListStyleName();
|
|
|
|
sParentListStyleName = msListStyleName;
|
|
|
|
mxNumRules = pParent->GetNumRules();
|
|
|
|
mnLevel = pParent->GetLevel() + 1;
|
|
|
|
// --> OD 2008-05-07 #refactorlists#
|
|
|
|
// mbRestartNumbering = pParent->IsRestartNumbering();
|
|
|
|
mbRestartNumbering = pParent->IsRestartNumbering() ||
|
|
|
|
bRestartNumberingAtSubList;
|
|
|
|
// <--
|
|
|
|
mbSetDefaults = pParent->mbSetDefaults;
|
|
|
|
// --> OD 2008-04-22 #refactorlists#
|
|
|
|
msListId = pParent->GetListId();
|
|
|
|
msContinueListId = pParent->GetContinueListId();
|
|
|
|
// <--
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
const SvXMLTokenMap& rTokenMap = mrTxtImport.GetTextListBlockAttrTokenMap();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
// --> OD 2008-05-07 #refactorlists#
|
|
|
|
bool bIsContinueNumberingAttributePresent( false );
|
|
|
|
// <--
|
2000-09-18 16:07:07 +00:00
|
|
|
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
|
|
|
|
for( sal_Int16 i=0; i < nAttrCount; i++ )
|
|
|
|
{
|
|
|
|
const OUString& rAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
const OUString& rValue = xAttrList->getValueByIndex( i );
|
|
|
|
|
|
|
|
OUString aLocalName;
|
|
|
|
sal_uInt16 nPrefix =
|
|
|
|
GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
|
|
|
|
&aLocalName );
|
|
|
|
switch( rTokenMap.Get( nPrefix, aLocalName ) )
|
|
|
|
{
|
|
|
|
case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING:
|
2008-06-13 08:19:20 +00:00
|
|
|
mbRestartNumbering = !IsXMLToken(rValue, XML_TRUE);
|
|
|
|
// --> OD 2008-05-07 #refactorlists#
|
|
|
|
bIsContinueNumberingAttributePresent = true;
|
|
|
|
// <--
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
case XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME:
|
2008-06-13 08:19:20 +00:00
|
|
|
msListStyleName = rValue;
|
|
|
|
break;
|
|
|
|
// --> OD 2008-04-22 #refactorlists#
|
|
|
|
case XML_TOK_TEXT_LIST_BLOCK_ID:
|
|
|
|
if ( mnLevel == 0 ) // root <list> element
|
|
|
|
{
|
|
|
|
msListId = rValue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_LIST:
|
|
|
|
if ( mnLevel == 0 ) // root <list> element
|
|
|
|
{
|
|
|
|
msContinueListId = rValue;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
if ( msListStyleName.getLength() &&
|
|
|
|
msListStyleName != sParentListStyleName )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-07-13 07:37:19 +00:00
|
|
|
OUString sDisplayStyleName(
|
|
|
|
GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
|
2008-06-13 08:19:20 +00:00
|
|
|
msListStyleName ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
const Reference < XNameContainer >& rNumStyles =
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.GetNumberingStyles();
|
2004-07-13 07:37:19 +00:00
|
|
|
if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
Reference < XStyle > xStyle;
|
2004-07-13 07:37:19 +00:00
|
|
|
Any aAny = rNumStyles->getByName( sDisplayStyleName );
|
2000-09-18 16:07:07 +00:00
|
|
|
aAny >>= xStyle;
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
// --> OD 2008-05-07 #refactorlists# - no longer needed
|
|
|
|
// // If the style has not been used, the restart numbering has
|
|
|
|
// // to be set never.
|
|
|
|
// if ( mbRestartNumbering && !xStyle->isInUse() )
|
|
|
|
// {
|
|
|
|
// mbRestartNumbering = sal_False;
|
|
|
|
// }
|
|
|
|
// <--
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY );
|
2008-06-13 08:19:20 +00:00
|
|
|
aAny = xPropSet->getPropertyValue( mrTxtImport.sNumberingRules );
|
|
|
|
aAny >>= mxNumRules;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const SvxXMLListStyleContext *pListStyle =
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.FindAutoListStyle( msListStyleName );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( pListStyle )
|
|
|
|
{
|
2008-06-13 08:19:20 +00:00
|
|
|
mxNumRules = pListStyle->GetNumRules();
|
|
|
|
// --> OD 2008-05-07 #refactorlists# - no longer needed
|
|
|
|
// sal_Bool bUsed = mxNumRules.is();
|
|
|
|
// <--
|
|
|
|
if( !mxNumRules.is() )
|
2000-10-23 09:17:35 +00:00
|
|
|
{
|
2000-09-18 16:07:07 +00:00
|
|
|
pListStyle->CreateAndInsertAuto();
|
2008-06-13 08:19:20 +00:00
|
|
|
mxNumRules = pListStyle->GetNumRules();
|
2000-10-23 09:17:35 +00:00
|
|
|
}
|
2008-06-13 08:19:20 +00:00
|
|
|
// --> OD 2008-05-07 #refactorlists# - no longer needed
|
|
|
|
// if( mbRestartNumbering && !bUsed )
|
|
|
|
// mbRestartNumbering = sal_False;
|
|
|
|
// <--
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
if( !mxNumRules.is() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// If no style name has been specified for this style and for any
|
|
|
|
// parent or if no num rule this the specified name is existing,
|
|
|
|
// create a new one.
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
mxNumRules =
|
2000-10-23 09:17:35 +00:00
|
|
|
SvxXMLListStyleContext::CreateNumRule( GetImport().GetModel() );
|
2008-06-13 08:19:20 +00:00
|
|
|
DBG_ASSERT( mxNumRules.is(), "go no numbering rule" );
|
|
|
|
if( !mxNumRules.is() )
|
2000-09-18 16:07:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Because its a new num rule, numbering mist be restarted never.
|
2008-06-13 08:19:20 +00:00
|
|
|
mbRestartNumbering = sal_False;
|
|
|
|
mbSetDefaults = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
const sal_Int32 nLevelCount = mxNumRules->getCount();
|
|
|
|
if( mnLevel >= nLevelCount )
|
|
|
|
mnLevel = sal::static_int_cast< sal_Int16 >(nLevelCount-1);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
if( mbSetDefaults )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// Because there is no list style sheet for this style, a default
|
|
|
|
// format must be set for any level of this num rule.
|
2008-06-13 08:19:20 +00:00
|
|
|
SvxXMLListStyleContext::SetDefaultStyle( mxNumRules, mnLevel,
|
2004-07-13 07:37:19 +00:00
|
|
|
sal_False );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
// --> OD 2008-04-23 #refactorlists#
|
|
|
|
if ( mnLevel == 0 ) // root <list> element
|
|
|
|
{
|
|
|
|
if ( msListId.getLength() == 0 ) // no text:id property found
|
|
|
|
{
|
|
|
|
sal_Int32 nUPD( 0 );
|
|
|
|
sal_Int32 nBuild( 0 );
|
|
|
|
const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
|
|
|
|
if ( rImport.IsTextDocInOOoFileFormat() ||
|
|
|
|
( bBuildIdFound && nUPD == 680 ) )
|
|
|
|
{
|
|
|
|
// handling former documents written by OpenOffice.org:
|
|
|
|
// use default list id of numbering rules instance, if existing
|
|
|
|
uno::Reference< beans::XPropertySet > xNumRuleProps( mxNumRules, UNO_QUERY );
|
|
|
|
if ( xNumRuleProps.is() )
|
|
|
|
{
|
|
|
|
uno::Reference< beans::XPropertySetInfo > xNumRulePropSetInfo(
|
|
|
|
xNumRuleProps->getPropertySetInfo());
|
|
|
|
if ( xNumRulePropSetInfo.is() &&
|
|
|
|
xNumRulePropSetInfo->hasPropertyByName( mrTxtImport.sPropNameDefaultListId) )
|
|
|
|
{
|
|
|
|
xNumRuleProps->getPropertyValue( mrTxtImport.sPropNameDefaultListId ) >>= msListId;
|
|
|
|
DBG_ASSERT( msListId.getLength() != 0,
|
|
|
|
"no default list id found at numbering rules instance. Serious defect -> please inform OD." );
|
|
|
|
if ( !bIsContinueNumberingAttributePresent &&
|
|
|
|
!mbRestartNumbering &&
|
|
|
|
mrTxtImport.IsListProcessed( msListId ) )
|
|
|
|
{
|
|
|
|
mbRestartNumbering = sal_True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( msListId.getLength() == 0 )
|
|
|
|
{
|
|
|
|
// generate a new list id for the list
|
|
|
|
msListId = mrTxtImport.GenerateNewListId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bIsContinueNumberingAttributePresent && !mbRestartNumbering &&
|
|
|
|
msContinueListId.getLength() == 0 )
|
|
|
|
{
|
|
|
|
if ( mrTxtImport.GetListStyleOfLastProcessedList() == msListStyleName &&
|
|
|
|
mrTxtImport.GetLastProcessedListId() != msListId )
|
|
|
|
{
|
|
|
|
msContinueListId = mrTxtImport.GetLastProcessedListId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( msContinueListId.getLength() > 0 )
|
|
|
|
{
|
|
|
|
if ( !mrTxtImport.IsListProcessed( msContinueListId ) )
|
|
|
|
{
|
|
|
|
msContinueListId = ::rtl::OUString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// search continue list chain for master list and
|
|
|
|
// continue the master list.
|
|
|
|
::rtl::OUString sTmpStr =
|
|
|
|
mrTxtImport.GetContinueListIdOfProcessedList( msContinueListId );
|
|
|
|
while ( sTmpStr.getLength() > 0 )
|
|
|
|
{
|
|
|
|
msContinueListId = sTmpStr;
|
|
|
|
|
|
|
|
sTmpStr =
|
|
|
|
mrTxtImport.GetContinueListIdOfProcessedList( msContinueListId );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !mrTxtImport.IsListProcessed( msListId ) )
|
|
|
|
{
|
|
|
|
mrTxtImport.KeepListAsProcessed( msListId, msListStyleName, msContinueListId );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// <--
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// Remember this list block.
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.SetListBlock( this );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// There is no list item by now.
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.SetListItem( 0 );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XMLTextListBlockContext::~XMLTextListBlockContext()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLTextListBlockContext::EndElement()
|
|
|
|
{
|
|
|
|
// Numbering has not to be restarted if it has been restarted within
|
|
|
|
// a child list.
|
|
|
|
XMLTextListBlockContext *pParent =
|
2008-06-13 08:19:20 +00:00
|
|
|
(XMLTextListBlockContext *)&mxParentListBlock;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( pParent )
|
|
|
|
{
|
2008-06-13 08:19:20 +00:00
|
|
|
pParent->mbRestartNumbering = mbRestartNumbering;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore current list block.
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.SetListBlock( pParent );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// Any paragraph following the list within the same list item mist not
|
|
|
|
// be numbered.
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.SetListItem( 0 );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *XMLTextListBlockContext::CreateChildContext(
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
|
|
|
const Reference< xml::sax::XAttributeList > & xAttrList )
|
|
|
|
{
|
|
|
|
SvXMLImportContext *pContext = 0;
|
|
|
|
|
|
|
|
const SvXMLTokenMap& rTokenMap =
|
2008-06-13 08:19:20 +00:00
|
|
|
mrTxtImport.GetTextListBlockElemTokenMap();
|
2000-09-18 16:07:07 +00:00
|
|
|
sal_Bool bHeader = sal_False;
|
|
|
|
switch( rTokenMap.Get( nPrefix, rLocalName ) )
|
|
|
|
{
|
|
|
|
case XML_TOK_TEXT_LIST_HEADER:
|
|
|
|
bHeader = sal_True;
|
|
|
|
case XML_TOK_TEXT_LIST_ITEM:
|
2008-06-13 08:19:20 +00:00
|
|
|
pContext = new XMLTextListItemContext( GetImport(), mrTxtImport,
|
2000-09-18 16:07:07 +00:00
|
|
|
nPrefix, rLocalName,
|
|
|
|
xAttrList, bHeader );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !pContext )
|
|
|
|
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
// --> OD 2008-04-22 #refactorlists#
|
|
|
|
const ::rtl::OUString& XMLTextListBlockContext::GetListId() const
|
|
|
|
{
|
|
|
|
return msListId;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-06-13 08:19:20 +00:00
|
|
|
const ::rtl::OUString& XMLTextListBlockContext::GetContinueListId() const
|
|
|
|
{
|
|
|
|
return msContinueListId;
|
|
|
|
}
|
|
|
|
// <--
|