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 {
52  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
53  {
54  if( !bIsHeader && aIter.getToken() == XML_ELEMENT(TEXT, XML_START_VALUE) )
55  {
56  sal_Int32 nTmp = aIter.toInt32();
57  if( nTmp >= 0 && nTmp <= SHRT_MAX )
58  nStartValue = static_cast<sal_Int16>(nTmp);
59  }
60  else if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_OVERRIDE) )
61  {
62  OUString sListStyleOverrideName = aIter.toString();
63  if ( !sListStyleOverrideName.isEmpty() )
64  {
65  OUString sDisplayStyleName(
66  GetImport().GetStyleDisplayName( XmlStyleFamily::TEXT_LIST,
67  sListStyleOverrideName ) );
68  const Reference < container::XNameContainer >& rNumStyles =
69  rTxtImp.GetNumberingStyles();
70  if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
71  {
72  Reference < style::XStyle > xStyle;
73  Any aAny = rNumStyles->getByName( sDisplayStyleName );
74  aAny >>= xStyle;
75 
76  uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
77  aAny = xPropSet->getPropertyValue("NumberingRules");
78  aAny >>= mxNumRulesOverride;
79  }
80  else
81  {
82  const SvxXMLListStyleContext* pListStyle =
83  rTxtImp.FindAutoListStyle( sListStyleOverrideName );
84  if( pListStyle )
85  {
86  mxNumRulesOverride = pListStyle->GetNumRules();
87  if( !mxNumRulesOverride.is() )
88  {
89  pListStyle->CreateAndInsertAuto();
90  mxNumRulesOverride = pListStyle->GetNumRules();
91  }
92  }
93  }
94  }
95  }
96  else if ( aIter.getToken() == XML_ELEMENT(XML, XML_ID) )
97  {
98 //FIXME: there is no UNO API for list items
99  }
100  else
101  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
102  }
103 
104  // If this is a <text:list-item> element, then remember it as a sign
105  // that a bullet has to be generated.
106  if( !bIsHeader ) {
107  rTxtImport.GetTextListHelper().SetListItem( this );
108  }
109 
110 }
111 
113 {
114 }
115 
117 {
118  // finish current list item
120 }
121 
122 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextListItemContext::createFastChildContext(
123  sal_Int32 nElement,
124  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
125 {
126  SvXMLImportContext *pContext = nullptr;
127 
128  switch( nElement )
129  {
130  case XML_ELEMENT(TEXT, XML_H):
131  case XML_ELEMENT(TEXT, XML_P):
132  case XML_ELEMENT(LO_EXT, XML_P):
133  pContext = new XMLParaContext( GetImport(), nElement,
134  xAttrList );
135  if (rTxtImport.IsProgress())
137 
138  break;
139  case XML_ELEMENT(TEXT, XML_LIST):
140  ++mnSubListCount;
141  pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
142  xAttrList,
143  (mnSubListCount > 1) );
144  break;
145  default:
146  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
147  }
148 
149  return pContext;
150 }
151 
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
const SvxXMLListStyleContext * FindAutoListStyle(const OUString &rName) const
Definition: txtimp.cxx:1973
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
bool IsProgress() const
Definition: txtimp.cxx:247
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:1005
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
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:1436
XMLTextListsHelper & GetTextListHelper()
Definition: txtimp.cxx:333
const css::uno::Reference< css::container::XNameContainer > & GetNumberingStyles() const
Definition: txtimp.cxx:265
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:44
void SetListItem(XMLTextListItemContext *pListItem)
set list item on top of the list context stack
Definition: txtlists.cxx:87
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
const css::uno::Reference< css::container::XIndexReplace > & GetNumRules() const
Definition: xmlnumi.hxx:63
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:119
TEXT