LibreOffice Module sc (master)  1
xmlsorti.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 "xmldrani.hxx"
21 #include "xmlsorti.hxx"
22 #include "xmlimprt.hxx"
23 #include <convuno.hxx>
24 #include <unonames.hxx>
25 #include <rangeutl.hxx>
26 
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 
30 #include <com/sun/star/util/SortField.hpp>
31 
32 using namespace com::sun::star;
33 using namespace xmloff::token;
34 
37  ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
38  ScXMLImportContext( rImport ),
39  pDatabaseRangeContext(pTempDatabaseRangeContext),
40  nUserListIndex(0),
41  bCopyOutputData(false),
42  bBindFormatsToContent(true),
43  bIsCaseSensitive(false),
44  bEnabledUserList(false)
45 {
46  if ( !rAttrList.is() )
47  return;
48 
49  for (auto &aIter : *rAttrList)
50  {
51  switch (aIter.getToken())
52  {
54  {
56  }
57  break;
59  {
60  ScRange aScRange;
61  sal_Int32 nOffset(0);
63  assert(pDoc);
64  if (ScRangeStringConverter::GetRangeFromString( aScRange, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
65  {
67  bCopyOutputData = true;
68  }
69  }
70  break;
72  {
74  }
75  break;
77  {
78  maLanguageTagODF.maRfcLanguageTag = aIter.toString();
79  }
80  break;
82  {
83  maLanguageTagODF.maLanguage = aIter.toString();
84  }
85  break;
86  case XML_ELEMENT( TABLE, XML_SCRIPT ):
87  {
88  maLanguageTagODF.maScript = aIter.toString();
89  }
90  break;
91  case XML_ELEMENT( TABLE, XML_COUNTRY ):
92  {
93  maLanguageTagODF.maCountry = aIter.toString();
94  }
95  break;
97  {
98  sAlgorithm = aIter.toString();
99  }
100  break;
101  }
102  }
103 }
104 
106 {
107 }
108 
109 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSortContext::createFastChildContext(
110  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
111 {
112  SvXMLImportContext *pContext(nullptr);
113  sax_fastparser::FastAttributeList *pAttribList =
115 
116  switch (nElement)
117  {
118  case XML_ELEMENT( TABLE, XML_SORT_BY ):
119  {
120  pContext = new ScXMLSortByContext( GetScImport(), nElement, pAttribList, this );
121  }
122  break;
123  }
124 
125  return pContext;
126 }
127 
128 void SAL_CALL ScXMLSortContext::endFastElement( sal_Int32 /*nElement*/ )
129 {
130  sal_Int32 nAlgoLength(sAlgorithm.getLength());
131  sal_uInt8 i (0);
132  if (!maLanguageTagODF.isEmpty())
133  ++i;
134  if (nAlgoLength)
135  ++i;
136  uno::Sequence <beans::PropertyValue> aSortDescriptor(7 + i);
137  aSortDescriptor[0].Name = SC_UNONAME_BINDFMT;
138  aSortDescriptor[0].Value <<= bBindFormatsToContent;
139  aSortDescriptor[1].Name = SC_UNONAME_COPYOUT;
140  aSortDescriptor[1].Value <<= bCopyOutputData;
141  aSortDescriptor[2].Name = SC_UNONAME_ISCASE;
142  aSortDescriptor[2].Value <<= bIsCaseSensitive;
143  aSortDescriptor[3].Name = SC_UNONAME_ISULIST;
144  aSortDescriptor[3].Value <<= bEnabledUserList;
145  aSortDescriptor[4].Name = SC_UNONAME_OUTPOS;
146  aSortDescriptor[4].Value <<= aOutputPosition;
147  aSortDescriptor[5].Name = SC_UNONAME_UINDEX;
148  aSortDescriptor[5].Value <<= nUserListIndex;
149  aSortDescriptor[6].Name = SC_UNONAME_SORTFLD;
150  aSortDescriptor[6].Value <<= aSortFields;
151  if (!maLanguageTagODF.isEmpty())
152  {
153  aSortDescriptor[7].Name = SC_UNONAME_COLLLOC;
154  aSortDescriptor[7].Value <<= maLanguageTagODF.getLanguageTag().getLocale( false);
155  }
156  if (nAlgoLength)
157  {
158  aSortDescriptor[6 + i].Name = SC_UNONAME_COLLALG;
159  aSortDescriptor[6 + i].Value <<= sAlgorithm;
160  }
161  pDatabaseRangeContext->SetSortSequence(aSortDescriptor);
162 }
163 
164 void ScXMLSortContext::AddSortField(const OUString& sFieldNumber, const OUString& sDataType, std::u16string_view sOrder)
165 {
166  util::SortField aSortField;
167  aSortField.Field = sFieldNumber.toInt32();
168  if (IsXMLToken(sOrder, XML_ASCENDING))
169  aSortField.SortAscending = true;
170  else
171  aSortField.SortAscending = false;
172  if (sDataType.getLength() > 8)
173  {
174  OUString sTemp = sDataType.copy(0, 8);
175  if (sTemp == "UserList")
176  {
177  bEnabledUserList = true;
178  sTemp = sDataType.copy(8);
179  nUserListIndex = static_cast<sal_Int16>(sTemp.toInt32());
180  }
181  else
182  {
183  if (IsXMLToken(sDataType, XML_AUTOMATIC))
184  aSortField.FieldType = util::SortFieldType_AUTOMATIC;
185  }
186  }
187  else
188  {
189  if (IsXMLToken(sDataType, XML_TEXT))
190  aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
191  else if (IsXMLToken(sDataType, XML_NUMBER))
192  aSortField.FieldType = util::SortFieldType_NUMERIC;
193  }
194  aSortFields.realloc(aSortFields.getLength() + 1);
195  aSortFields[aSortFields.getLength() - 1] = aSortField;
196 }
197 
199  sal_Int32 /*nElement*/,
201  ScXMLSortContext* pTempSortContext) :
202  ScXMLImportContext( rImport ),
203  pSortContext(pTempSortContext),
204  sDataType(GetXMLToken(XML_AUTOMATIC)),
205  sOrder(GetXMLToken(XML_ASCENDING))
206 {
207  if ( !rAttrList.is() )
208  return;
209 
210  for (auto &aIter : *rAttrList)
211  {
212  switch (aIter.getToken())
213  {
215  {
216  sFieldNumber = aIter.toString();
217  }
218  break;
220  {
221  sDataType = aIter.toString();
222  }
223  break;
224  case XML_ELEMENT( TABLE, XML_ORDER ):
225  {
226  sOrder = aIter.toString();
227  }
228  break;
229  }
230  }
231 }
232 
234 {
235 }
236 
237 void SAL_CALL ScXMLSortByContext::endFastElement( sal_Int32 /*nElement*/ )
238 {
240 }
241 
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlsorti.cxx:128
XML_NUMBER
sal_Int16 nUserListIndex
Definition: xmlsorti.hxx:40
ScAddress aStart
Definition: address.hxx:499
#define SC_UNONAME_COPYOUT
Definition: unonames.hxx:296
css::uno::Sequence< css::util::SortField > aSortFields
Definition: xmlsorti.hxx:36
XML_FIELD_NUMBER
OUString maCountry
bool bBindFormatsToContent
Definition: xmlsorti.hxx:42
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
XML_SCRIPT
XML_TEXT
bool bCopyOutputData
Definition: xmlsorti.hxx:41
css::table::CellAddress aOutputPosition
Definition: xmlsorti.hxx:37
XML_SORT_BY
OUString maLanguage
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlsorti.cxx:109
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
LanguageTag getLanguageTag() const
ScXMLSortContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLDatabaseRangeContext *pTempDatabaseRangeContext)
Definition: xmlsorti.cxx:35
XML_DATA_TYPE
XML_AUTOMATIC
OUString sAlgorithm
Definition: xmlsorti.hxx:39
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
static void FillApiAddress(css::table::CellAddress &rApiAddress, const ScAddress &rScAddress)
Definition: convuno.hxx:70
bool bEnabledUserList
Definition: xmlsorti.hxx:44
#define SC_UNONAME_OUTPOS
Definition: unonames.hxx:299
XML_ORDER
#define SC_UNONAME_BINDFMT
Definition: unonames.hxx:295
XML_LANGUAGE
#define SC_UNONAME_UINDEX
Definition: unonames.hxx:294
static bool GetRangeFromString(ScRange &rRange, const OUString &rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
ScXMLDatabaseRangeContext * pDatabaseRangeContext
Definition: xmlsorti.hxx:34
ScXMLSortByContext(ScXMLImport &rImport, sal_Int32 nElement, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLSortContext *pTempSortContext)
Definition: xmlsorti.cxx:198
OUString sDataType
Definition: xmlsorti.hxx:67
This class exists only to provide GetScImport() to its derived classes.
XML_ALGORITHM
int i
bool isEmpty() const
XML_RFC_LANGUAGE_TAG
OUString maRfcLanguageTag
LanguageTagODF maLanguageTagODF
Definition: xmlsorti.hxx:38
ScXMLImport & GetScImport()
XML_TARGET_RANGE_ADDRESS
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlsorti.cxx:237
virtual ~ScXMLSortByContext() override
Definition: xmlsorti.cxx:233
#define SC_UNONAME_ISCASE
Definition: unonames.hxx:297
XML_TRUE
TABLE
#define SC_UNONAME_ISULIST
Definition: unonames.hxx:298
ScXMLSortContext * pSortContext
Definition: xmlsorti.hxx:64
OUString maScript
OUString sFieldNumber
Definition: xmlsorti.hxx:66
unsigned char sal_uInt8
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
XML_CASE_SENSITIVE
#define XML_ELEMENT(prefix, name)
bool bIsCaseSensitive
Definition: xmlsorti.hxx:43
virtual ~ScXMLSortContext() override
Definition: xmlsorti.cxx:105
XML_BIND_STYLES_TO_CONTENT
#define SC_UNONAME_SORTFLD
Definition: unonames.hxx:304
void SetSortSequence(const css::uno::Sequence< css::beans::PropertyValue > &aTempSortSequence)
Definition: xmldrani.hxx:114
XML_ASCENDING
XML_COUNTRY
#define SC_UNONAME_COLLALG
Definition: unonames.hxx:309
#define SC_UNONAME_COLLLOC
Definition: unonames.hxx:308
void AddSortField(const OUString &sFieldNumber, const OUString &sDataType, std::u16string_view sOrder)
Definition: xmlsorti.cxx:164