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 #include <sal/log.hxx>
35 
36 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::xmloff::token;
40 
41 
43  SvXMLImport& rImport,
44  XMLTextImportHelper& rTxtImp,
45  const Reference< xml::sax::XFastAttributeList > & xAttrList,
46  const bool bIsHeader )
47  : SvXMLImportContext( rImport ),
48  rTxtImport( rTxtImp ),
49  nStartValue( -1 ),
50  mnSubListCount( 0 ),
51  mxNumRulesOverride()
52 {
53  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
54  {
55  if( !bIsHeader && aIter.getToken() == XML_ELEMENT(TEXT, XML_START_VALUE) )
56  {
57  sal_Int32 nTmp = aIter.toInt32();
58  if( nTmp >= 0 && nTmp <= SHRT_MAX )
59  nStartValue = static_cast<sal_Int16>(nTmp);
60  }
61  else if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_OVERRIDE) )
62  {
63  OUString sListStyleOverrideName = aIter.toString();
64  if ( !sListStyleOverrideName.isEmpty() )
65  {
66  OUString sDisplayStyleName(
67  GetImport().GetStyleDisplayName( XmlStyleFamily::TEXT_LIST,
68  sListStyleOverrideName ) );
69  const Reference < container::XNameContainer >& rNumStyles =
70  rTxtImp.GetNumberingStyles();
71  if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
72  {
73  Reference < style::XStyle > xStyle;
74  Any aAny = rNumStyles->getByName( sDisplayStyleName );
75  aAny >>= xStyle;
76 
77  uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
78  aAny = xPropSet->getPropertyValue("NumberingRules");
79  aAny >>= mxNumRulesOverride;
80  }
81  else
82  {
83  const SvxXMLListStyleContext* pListStyle =
84  rTxtImp.FindAutoListStyle( sListStyleOverrideName );
85  if( pListStyle )
86  {
87  mxNumRulesOverride = pListStyle->GetNumRules();
88  if( !mxNumRulesOverride.is() )
89  {
90  pListStyle->CreateAndInsertAuto();
91  mxNumRulesOverride = pListStyle->GetNumRules();
92  }
93  }
94  }
95  }
96  }
97  else if ( aIter.getToken() == XML_ELEMENT(XML, XML_ID) )
98  {
99 //FIXME: there is no UNO API for list items
100  }
101  else
102  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
103  }
104 
105  // If this is a <text:list-item> element, then remember it as a sign
106  // that a bullet has to be generated.
107  if( !bIsHeader ) {
108  rTxtImport.GetTextListHelper().SetListItem( this );
109  }
110 
111 }
112 
114 {
115 }
116 
118 {
119  // finish current list item
121 }
122 
123 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextListItemContext::createFastChildContext(
124  sal_Int32 nElement,
125  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
126 {
127  SvXMLImportContext *pContext = nullptr;
128 
129  switch( nElement )
130  {
131  case XML_ELEMENT(TEXT, XML_H):
132  case XML_ELEMENT(TEXT, XML_P):
133  case XML_ELEMENT(LO_EXT, XML_P):
134  pContext = new XMLParaContext( GetImport(), nElement,
135  xAttrList );
136  if (rTxtImport.IsProgress())
138 
139  break;
140  case XML_ELEMENT(TEXT, XML_LIST):
141  ++mnSubListCount;
142  pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
143  xAttrList,
144  (mnSubListCount > 1) );
145  break;
146  default:
147  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
148  }
149 
150  return pContext;
151 }
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
const SvxXMLListStyleContext * FindAutoListStyle(const OUString &rName) const
Definition: txtimp.cxx:2378
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
bool IsProgress() const
Definition: txtimp.cxx:578
XMLTextImportHelper & rTxtImport
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void CreateAndInsertAuto() const
Definition: xmlnumi.cxx:1025
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:131
virtual ~XMLTextListItemContext() override
XMLTextListItemContext(SvXMLImport &rImport, XMLTextImportHelper &rTxtImp, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const bool bIsHeader)
void Increment(sal_Int32 nInc=1)
ProgressBarHelper * GetProgressBarHelper()
Definition: xmlimp.cxx:1494
XMLTextListsHelper & GetTextListHelper()
Definition: txtimp.cxx:664
const css::uno::Reference< css::container::XNameContainer > & GetNumberingStyles() const
Definition: txtimp.cxx:596
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
void SetListItem(XMLTextListItemContext *pListItem)
set list item on top of the list context stack
Definition: txtlists.cxx:89
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
const css::uno::Reference< css::container::XIndexReplace > & GetNumRules() const
Definition: xmlnumi.hxx:64
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:137
TEXT