LibreOffice Module xmloff (master)  1
XMLTextListBlockContext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/container/XIndexReplace.hpp>
21 #include <com/sun/star/style/XStyle.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmltoken.hxx>
28 #include <txtlists.hxx>
29 #include <sal/log.hxx>
30 
31 
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::style;
36 using namespace ::com::sun::star::beans;
37 using namespace ::xmloff::token;
38 
39 
40 // OD 2008-05-07 #refactorlists#
41 // add optional parameter <bRestartNumberingAtSubList> and its handling
43  SvXMLImport& rImport,
44  XMLTextImportHelper& rTxtImp,
45  sal_uInt16 nPrfx,
46  const OUString& rLName,
47  const Reference< xml::sax::XAttributeList > & xAttrList,
48  const bool bRestartNumberingAtSubList )
49 : SvXMLImportContext( rImport, nPrfx, rLName )
50 , mrTxtImport( rTxtImp )
51 , msListStyleName()
52 , mxParentListBlock( )
53 , mnLevel( 0 )
54 , mbRestartNumbering( false )
55 , mbSetDefaults( false )
56 , msListId()
57 , msContinueListId()
58 {
59  static const char s_PropNameDefaultListId[] = "DefaultListId";
60  {
61  // get the parent list block context (if any); this is a bit ugly...
62  XMLTextListBlockContext * pLB(nullptr);
63  XMLTextListItemContext * pLI(nullptr);
64  XMLNumberedParaContext * pNP(nullptr);
65  rTxtImp.GetTextListHelper().ListContextTop(pLB, pLI, pNP);
66  mxParentListBlock = pLB;
67  }
68  // Inherit style name from parent list, as well as the flags whether
69  // numbering must be restarted and formats have to be created.
70  OUString sParentListStyleName;
71  if( mxParentListBlock.is() )
72  {
75  sParentListStyleName = msListStyleName;
76  mxNumRules = pParent->GetNumRules();
77  mnLevel = pParent->GetLevel() + 1;
79  bRestartNumberingAtSubList;
80  mbSetDefaults = pParent->mbSetDefaults;
81  msListId = pParent->GetListId();
83  }
84 
86 
87  bool bIsContinueNumberingAttributePresent( false );
88  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
89  for( sal_Int16 i=0; i < nAttrCount; i++ )
90  {
91  const OUString& rAttrName = xAttrList->getNameByIndex( i );
92  const OUString& rValue = xAttrList->getValueByIndex( i );
93 
94  OUString aLocalName;
95  sal_uInt16 nPrefix =
97  &aLocalName );
98  switch( rTokenMap.Get( nPrefix, aLocalName ) )
99  {
101 //FIXME: there is no UNO API for lists
102  // xml:id is also the list ID (#i92221#)
103  if ( mnLevel == 0 ) // root <list> element
104  {
105  msListId = rValue;
106  }
107  break;
110  bIsContinueNumberingAttributePresent = true;
111  break;
114  break;
116  if ( mnLevel == 0 ) // root <list> element
117  {
119  }
120  break;
121  }
122  }
123 
124  // Remember this list block.
126 
128  sParentListStyleName, msListStyleName,
130  if( !mxNumRules.is() )
131  return;
132 
133  if ( mnLevel != 0 ) // root <list> element
134  return;
135 
136  XMLTextListsHelper& rTextListsHelper( mrTxtImport.GetTextListHelper() );
137  // Inconsistent behavior regarding lists (#i92811#)
138  OUString sListStyleDefaultListId;
139  {
140  uno::Reference< beans::XPropertySet > xNumRuleProps( mxNumRules, UNO_QUERY );
141  if ( xNumRuleProps.is() )
142  {
143  uno::Reference< beans::XPropertySetInfo > xNumRulePropSetInfo(
144  xNumRuleProps->getPropertySetInfo());
145  if (xNumRulePropSetInfo.is() &&
146  xNumRulePropSetInfo->hasPropertyByName(
147  s_PropNameDefaultListId))
148  {
149  xNumRuleProps->getPropertyValue(s_PropNameDefaultListId)
150  >>= sListStyleDefaultListId;
151  SAL_WARN_IF( sListStyleDefaultListId.isEmpty(), "xmloff",
152  "no default list id found at numbering rules instance. Serious defect." );
153  }
154  }
155  }
156  if ( msListId.isEmpty() ) // no text:id property found
157  {
158  sal_Int32 nUPD( 0 );
159  sal_Int32 nBuild( 0 );
160  const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
161  if ( rImport.IsTextDocInOOoFileFormat() ||
162  ( bBuildIdFound && nUPD == 680 ) )
163  {
164  /* handling former documents written by OpenOffice.org:
165  use default list id of numbering rules instance, if existing
166  (#i92811#)
167  */
168  if ( !sListStyleDefaultListId.isEmpty() )
169  {
170  msListId = sListStyleDefaultListId;
171  if ( !bIsContinueNumberingAttributePresent &&
173  rTextListsHelper.IsListProcessed( msListId ) )
174  {
175  mbRestartNumbering = true;
176  }
177  }
178  }
179  if ( msListId.isEmpty() )
180  {
181  // generate a new list id for the list
182  msListId = rTextListsHelper.GenerateNewListId();
183  }
184  }
185 
186  if ( bIsContinueNumberingAttributePresent && !mbRestartNumbering &&
187  msContinueListId.isEmpty() )
188  {
189  const OUString& Last( rTextListsHelper.GetLastProcessedListId() );
190  if ( rTextListsHelper.GetListStyleOfLastProcessedList() == msListStyleName
191  && Last != msListId )
192  {
194  }
195  }
196 
197  if ( !msContinueListId.isEmpty() )
198  {
199  if ( !rTextListsHelper.IsListProcessed( msContinueListId ) )
200  {
201  msContinueListId.clear();
202  }
203  else
204  {
205  // search continue list chain for master list and
206  // continue the master list.
207  OUString sTmpStr =
208  rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId );
209  while ( !sTmpStr.isEmpty() )
210  {
211  msContinueListId = sTmpStr;
212 
213  sTmpStr =
214  rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId );
215  }
216  }
217  }
218 
219  if ( !rTextListsHelper.IsListProcessed( msListId ) )
220  {
221  // Inconsistent behavior regarding lists (#i92811#)
222  rTextListsHelper.KeepListAsProcessed(
224  sListStyleDefaultListId );
225  }
226 }
227 
229 {
230 }
231 
233 {
234  // Numbering has not to be restarted if it has been restarted within
235  // a child list.
237  if( pParent )
238  {
240  }
241 
242  // Restore current list block.
244 
245  // Any paragraph following the list within the same list item must not
246  // be numbered.
248 }
249 
251  sal_uInt16 nPrefix,
252  const OUString& rLocalName,
253  const Reference< xml::sax::XAttributeList > & xAttrList )
254 {
255  SvXMLImportContext *pContext = nullptr;
256 
257  const SvXMLTokenMap& rTokenMap =
259  bool bHeader = false;
260  switch( rTokenMap.Get( nPrefix, rLocalName ) )
261  {
263  bHeader = true;
264  [[fallthrough]];
266  pContext = new XMLTextListItemContext( GetImport(), mrTxtImport,
267  nPrefix, rLocalName,
268  xAttrList, bHeader );
269  break;
270  }
271 
272 
273  return pContext;
274 }
275 
276 
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
const OUString & GetContinueListId() const
sal_Int16 mnLevel
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
XMLTextImportHelper & mrTxtImport
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
const OUString & GetListId() const
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
void ListContextTop(XMLTextListBlockContext *&o_pListBlockContext, XMLTextListItemContext *&o_pListItemContext, XMLNumberedParaContext *&o_pNumberedParagraphContext)
peek at the top of the list context stack
Definition: txtlists.cxx:73
static css::uno::Reference< css::container::XIndexReplace > MakeNumRule(SvXMLImport &i_rImport, const css::uno::Reference< css::container::XIndexReplace > &i_xNumRule, const OUString &i_ParentStyleName, const OUString &i_StyleName, sal_Int16 &io_rLevel, bool *o_pRestartNumbering=nullptr, bool *io_pSetDefaults=nullptr)
Creates a NumRule from given style-name.
Definition: txtlists.cxx:401
virtual ~XMLTextListBlockContext() override
const SvXMLTokenMap & GetTextListBlockElemTokenMap()
Definition: txtimp.cxx:2570
int i
bool getBuildIds(sal_Int32 &rUPD, sal_Int32 &rBuild) const
returns the upd and build id (f.e.
Definition: xmlimp.cxx:1914
bool IsTextDocInOOoFileFormat() const
Definition: xmlimp.cxx:1904
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
XMLTextListBlockContext(SvXMLImport &rImport, XMLTextImportHelper &rTxtImp, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, const bool bRestartNumberingAtSubList=false)
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
void PushListContext(XMLTextListBlockContext *i_pListBlock)
list stack for importing:
Definition: txtlists.cxx:50
rtl::Reference< XMLTextListBlockContext > mxParentListBlock
XMLTextListsHelper & GetTextListHelper()
Definition: txtimp.cxx:741
SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
css::uno::Reference< css::container::XIndexReplace > mxNumRules
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
#define SAL_WARN_IF(condition, area, stream)
void SetListItem(XMLTextListItemContext *pListItem)
set list item on top of the list context stack
Definition: txtlists.cxx:88
Handling of tokens in XML:
void PopListContext()
pop the list context stack
Definition: txtlists.cxx:66
const css::uno::Reference< css::container::XIndexReplace > & GetNumRules() const
const SvXMLTokenMap & GetTextListBlockAttrTokenMap()
Definition: txtimp.cxx:2560