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