LibreOffice Module xmloff (master)  1
XMLTextListItemContext.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 <xmloff/xmlimp.hxx>
21 #include <xmloff/namespacemap.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include "txtparai.hxx"
25 #include <txtlists.hxx>
27 #include <xmloff/txtimp.hxx>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/style/XStyle.hpp>
31 #include <xmloff/xmlnumi.hxx>
34 
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::xmloff::token;
39 
40 
42  SvXMLImport& rImport,
43  XMLTextImportHelper& rTxtImp,
44  const sal_uInt16 nPrfx,
45  const OUString& rLName,
46  const Reference< xml::sax::XAttributeList > & xAttrList,
47  const bool bIsHeader )
48  : SvXMLImportContext( rImport, nPrfx, rLName ),
49  rTxtImport( rTxtImp ),
50  nStartValue( -1 ),
51  mnSubListCount( 0 ),
52  mxNumRulesOverride()
53 {
54  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
55  for( sal_Int16 i=0; i < nAttrCount; i++ )
56  {
57  const OUString& rAttrName = xAttrList->getNameByIndex( i );
58  const OUString& rValue = xAttrList->getValueByIndex( i );
59 
60  OUString aLocalName;
61  sal_uInt16 nPrefix =
63  &aLocalName );
64  if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix &&
65  IsXMLToken( aLocalName, XML_START_VALUE ) )
66  {
67  sal_Int32 nTmp = rValue.toInt32();
68  if( nTmp >= 0 && nTmp <= SHRT_MAX )
69  nStartValue = static_cast<sal_Int16>(nTmp);
70  }
71  else if ( nPrefix == XML_NAMESPACE_TEXT &&
72  IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) )
73  {
74  const OUString& sListStyleOverrideName = rValue;
75  if ( !sListStyleOverrideName.isEmpty() )
76  {
77  OUString sDisplayStyleName(
78  GetImport().GetStyleDisplayName( XmlStyleFamily::TEXT_LIST,
79  sListStyleOverrideName ) );
80  const Reference < container::XNameContainer >& rNumStyles =
81  rTxtImp.GetNumberingStyles();
82  if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
83  {
84  Reference < style::XStyle > xStyle;
85  Any aAny = rNumStyles->getByName( sDisplayStyleName );
86  aAny >>= xStyle;
87 
88  uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
89  aAny = xPropSet->getPropertyValue("NumberingRules");
90  aAny >>= mxNumRulesOverride;
91  }
92  else
93  {
94  const SvxXMLListStyleContext* pListStyle =
95  rTxtImp.FindAutoListStyle( sListStyleOverrideName );
96  if( pListStyle )
97  {
98  mxNumRulesOverride = pListStyle->GetNumRules();
99  if( !mxNumRulesOverride.is() )
100  {
101  pListStyle->CreateAndInsertAuto();
102  mxNumRulesOverride = pListStyle->GetNumRules();
103  }
104  }
105  }
106  }
107  }
108  else if ( (XML_NAMESPACE_XML == nPrefix) &&
109  IsXMLToken(aLocalName, XML_ID) )
110  {
111 //FIXME: there is no UNO API for list items
112  }
113  }
114 
115  // If this is a <text:list-item> element, then remember it as a sign
116  // that a bullet has to be generated.
117  if( !bIsHeader ) {
118  rTxtImport.GetTextListHelper().SetListItem( this );
119  }
120 
121 }
122 
124 {
125 }
126 
128 {
129  // finish current list item
131 }
132 
134  sal_uInt16 nPrefix,
135  const OUString& rLocalName,
136  const Reference< xml::sax::XAttributeList > & xAttrList )
137 {
138  SvXMLImportContext *pContext = nullptr;
139 
140  const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap();
141  bool bHeading = false;
142  switch( rTokenMap.Get( nPrefix, rLocalName ) )
143  {
144  case XML_TOK_TEXT_H:
145  bHeading = true;
146  [[fallthrough]];
147  case XML_TOK_TEXT_P:
148  pContext = new XMLParaContext( GetImport(),
149  nPrefix, rLocalName,
150  xAttrList, bHeading );
151  if (rTxtImport.IsProgress())
153 
154  break;
155  case XML_TOK_TEXT_LIST:
156  ++mnSubListCount;
157  pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
158  nPrefix, rLocalName,
159  xAttrList,
160  (mnSubListCount > 1) );
161  break;
162  }
163 
164  return pContext;
165 }
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
const SvxXMLListStyleContext * FindAutoListStyle(const OUString &rName) const
Definition: txtimp.cxx:2466
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
bool IsProgress() const
Definition: txtimp.cxx:655
XMLTextImportHelper & rTxtImport
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
SvXMLTokenMap const & GetTextElemTokenMap()
Definition: txtimp.cxx:746
XMLTextListItemContext(SvXMLImport &rImport, XMLTextImportHelper &rTxtImp, const sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, const bool bIsHeader)
void CreateAndInsertAuto() const
Definition: xmlnumi.cxx:1078
virtual ~XMLTextListItemContext() override
SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
constexpr sal_uInt16 XML_NAMESPACE_XML
void Increment(sal_Int32 nInc=1)
int i
constexpr sal_uInt16 XML_NAMESPACE_TEXT
ProgressBarHelper * GetProgressBarHelper()
Definition: xmlimp.cxx:1520
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
XMLTextListsHelper & GetTextListHelper()
Definition: txtimp.cxx:741
const css::uno::Reference< css::container::XNameContainer > & GetNumberingStyles() const
Definition: txtimp.cxx:673
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
void SetListItem(XMLTextListItemContext *pListItem)
set list item on top of the list context stack
Definition: txtlists.cxx:88
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
Handling of tokens in XML:
const css::uno::Reference< css::container::XIndexReplace > & GetNumRules() const
Definition: xmlnumi.hxx:64