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