1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTextListBlockContext.cxx,v $
10 * $Revision: 1.13.2.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/container/XIndexReplace.hpp>
36 #include <com/sun/star/style/XStyle.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/xmlnumi.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include "XMLTextListItemContext.hxx"
44 #include "XMLTextListBlockContext.hxx"
45 #include "txtlists.hxx"
47 using ::rtl::OUString
;
48 using ::rtl::OUStringBuffer
;
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::com::sun::star::style
;
54 using namespace ::com::sun::star::beans
;
55 using namespace ::xmloff::token
;
57 TYPEINIT1( XMLTextListBlockContext
, SvXMLImportContext
);
59 // OD 2008-05-07 #refactorlists#
60 // add optional parameter <bRestartNumberingAtSubList> and its handling
61 XMLTextListBlockContext::XMLTextListBlockContext(
63 XMLTextImportHelper
& rTxtImp
,
65 const OUString
& rLName
,
66 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
67 const sal_Bool bRestartNumberingAtSubList
)
68 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
69 , mrTxtImport( rTxtImp
)
70 // --> OD 2008-04-22 #refactorlists#
73 , mxParentListBlock( )
75 // --> OD 2008-05-07 #refactorlists#
76 //, mbRestartNumbering( sal_True )
77 , mbRestartNumbering( sal_False
)
79 , mbSetDefaults( sal_False
)
80 // --> OD 2008-04-22 #refactorlists#
86 // get the parent list block context (if any); this is a bit ugly...
87 XMLTextListBlockContext
* pLB(0);
88 XMLTextListItemContext
* pLI(0);
89 XMLNumberedParaContext
* pNP(0);
90 rTxtImp
.GetTextListHelper().ListContextTop(pLB
, pLI
, pNP
);
91 mxParentListBlock
= pLB
;
93 // Inherit style name from parent list, as well as the flags whether
94 // numbering must be restarted and formats have to be created.
95 OUString sParentListStyleName
;
96 // --> OD 2008-11-27 #158694#
97 sal_Bool
bParentRestartNumbering( sal_False
);
99 if( mxParentListBlock
.Is() )
101 XMLTextListBlockContext
*pParent
=
102 (XMLTextListBlockContext
*)&mxParentListBlock
;
103 msListStyleName
= pParent
->GetListStyleName();
104 sParentListStyleName
= msListStyleName
;
105 mxNumRules
= pParent
->GetNumRules();
106 mnLevel
= pParent
->GetLevel() + 1;
107 // --> OD 2008-05-07 #refactorlists#
108 // mbRestartNumbering = pParent->IsRestartNumbering();
109 mbRestartNumbering
= pParent
->IsRestartNumbering() ||
110 bRestartNumberingAtSubList
;
112 // --> OD 2008-11-27 #158694#
113 bParentRestartNumbering
= pParent
->IsRestartNumbering();
115 mbSetDefaults
= pParent
->mbSetDefaults
;
116 // --> OD 2008-04-22 #refactorlists#
117 msListId
= pParent
->GetListId();
118 msContinueListId
= pParent
->GetContinueListId();
122 const SvXMLTokenMap
& rTokenMap
= mrTxtImport
.GetTextListBlockAttrTokenMap();
124 // --> OD 2008-05-07 #refactorlists#
125 bool bIsContinueNumberingAttributePresent( false );
127 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
128 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
130 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
131 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
135 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
137 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
139 case XML_TOK_TEXT_LIST_BLOCK_XMLID
:
141 //FIXME: there is no UNO API for lists
142 // --> OD 2008-07-31 #i92221# - xml:id is also the list ID
143 if ( mnLevel
== 0 ) // root <list> element
149 case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING
:
150 mbRestartNumbering
= !IsXMLToken(rValue
, XML_TRUE
);
151 // --> OD 2008-05-07 #refactorlists#
152 bIsContinueNumberingAttributePresent
= true;
155 case XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME
:
156 msListStyleName
= rValue
;
158 // --> OD 2008-04-22 #refactorlists#
159 case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_LIST
:
160 if ( mnLevel
== 0 ) // root <list> element
162 msContinueListId
= rValue
;
168 mxNumRules
= XMLTextListsHelper::MakeNumRule(GetImport(), mxNumRules
,
169 sParentListStyleName
, msListStyleName
,
170 mnLevel
, &mbRestartNumbering
, &mbSetDefaults
);
171 if( !mxNumRules
.is() )
174 // --> OD 2008-04-23 #refactorlists#
175 if ( mnLevel
== 0 ) // root <list> element
177 XMLTextListsHelper
& rTextListsHelper( mrTxtImport
.GetTextListHelper() );
178 // --> OD 2008-08-15 #i92811#
179 ::rtl::OUString sListStyleDefaultListId
;
181 uno::Reference
< beans::XPropertySet
> xNumRuleProps( mxNumRules
, UNO_QUERY
);
182 if ( xNumRuleProps
.is() )
184 uno::Reference
< beans::XPropertySetInfo
> xNumRulePropSetInfo(
185 xNumRuleProps
->getPropertySetInfo());
186 if ( xNumRulePropSetInfo
.is() &&
187 xNumRulePropSetInfo
->hasPropertyByName( mrTxtImport
.sPropNameDefaultListId
) )
189 xNumRuleProps
->getPropertyValue( mrTxtImport
.sPropNameDefaultListId
) >>= sListStyleDefaultListId
;
190 DBG_ASSERT( sListStyleDefaultListId
.getLength() != 0,
191 "no default list id found at numbering rules instance. Serious defect -> please inform OD." );
196 if ( msListId
.getLength() == 0 ) // no text:id property found
199 sal_Int32
nBuild( 0 );
200 const bool bBuildIdFound
= GetImport().getBuildIds( nUPD
, nBuild
);
201 if ( rImport
.IsTextDocInOOoFileFormat() ||
202 ( bBuildIdFound
&& nUPD
== 680 ) )
204 // handling former documents written by OpenOffice.org:
205 // use default list id of numbering rules instance, if existing
206 // --> OD 2008-08-15 #i92811#
207 if ( sListStyleDefaultListId
.getLength() != 0 )
209 msListId
= sListStyleDefaultListId
;
210 if ( !bIsContinueNumberingAttributePresent
&&
211 !mbRestartNumbering
&&
212 rTextListsHelper
.IsListProcessed( msListId
) )
214 mbRestartNumbering
= sal_True
;
219 if ( msListId
.getLength() == 0 )
221 // generate a new list id for the list
222 msListId
= rTextListsHelper
.GenerateNewListId();
226 if ( bIsContinueNumberingAttributePresent
&& !mbRestartNumbering
&&
227 msContinueListId
.getLength() == 0 )
229 ::rtl::OUString
Last( rTextListsHelper
.GetLastProcessedListId() );
230 if ( rTextListsHelper
.GetListStyleOfLastProcessedList() == msListStyleName
231 && Last
!= msListId
)
233 msContinueListId
= Last
;
237 if ( msContinueListId
.getLength() > 0 )
239 if ( !rTextListsHelper
.IsListProcessed( msContinueListId
) )
241 msContinueListId
= ::rtl::OUString();
245 // search continue list chain for master list and
246 // continue the master list.
247 ::rtl::OUString sTmpStr
=
248 rTextListsHelper
.GetContinueListIdOfProcessedList( msContinueListId
);
249 while ( sTmpStr
.getLength() > 0 )
251 msContinueListId
= sTmpStr
;
254 rTextListsHelper
.GetContinueListIdOfProcessedList( msContinueListId
);
259 if ( !rTextListsHelper
.IsListProcessed( msListId
) )
261 // --> OD 2008-08-15 #i92811#
262 rTextListsHelper
.KeepListAsProcessed(
263 msListId
, msListStyleName
, msContinueListId
,
264 sListStyleDefaultListId
);
270 // Remember this list block.
271 mrTxtImport
.GetTextListHelper().PushListContext( this );
274 XMLTextListBlockContext::~XMLTextListBlockContext()
278 void XMLTextListBlockContext::EndElement()
280 // Numbering has not to be restarted if it has been restarted within
282 XMLTextListBlockContext
*pParent
=
283 (XMLTextListBlockContext
*)&mxParentListBlock
;
286 pParent
->mbRestartNumbering
= mbRestartNumbering
;
289 // Restore current list block.
290 mrTxtImport
.GetTextListHelper().PopListContext();
292 // Any paragraph following the list within the same list item must not
294 mrTxtImport
.GetTextListHelper().SetListItem( 0 );
297 SvXMLImportContext
*XMLTextListBlockContext::CreateChildContext(
299 const OUString
& rLocalName
,
300 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
302 SvXMLImportContext
*pContext
= 0;
304 const SvXMLTokenMap
& rTokenMap
=
305 mrTxtImport
.GetTextListBlockElemTokenMap();
306 sal_Bool bHeader
= sal_False
;
307 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
309 case XML_TOK_TEXT_LIST_HEADER
:
311 case XML_TOK_TEXT_LIST_ITEM
:
312 pContext
= new XMLTextListItemContext( GetImport(), mrTxtImport
,
314 xAttrList
, bHeader
);
319 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
324 // --> OD 2008-04-22 #refactorlists#
325 const ::rtl::OUString
& XMLTextListBlockContext::GetListId() const
330 const ::rtl::OUString
& XMLTextListBlockContext::GetContinueListId() const
332 return msContinueListId
;