LibreOffice Module sc (master)  1
XMLDetectiveContext.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 "XMLDetectiveContext.hxx"
21 
22 #include <sax/tools/converter.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include "xmlimprt.hxx"
26 #include "XMLConverter.hxx"
27 #include <rangeutl.hxx>
28 
29 using namespace ::com::sun::star;
30 using namespace xmloff::token;
31 
33  eObjType( SC_DETOBJ_NONE ),
34  bHasError( false )
35 {
36 }
37 
39 {
40  return (nIndex < rDetOp.nIndex);
41 }
42 
44 {
45  aDetectiveOpList.sort();
46 }
47 
49 {
50  if( aDetectiveOpList.empty() )
51  return false;
52  ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
53  rDetOp = *aItr;
54  aDetectiveOpList.erase( aItr );
55  return true;
56 }
57 
59  ScXMLImport& rImport,
60  ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
61  ScXMLImportContext( rImport ),
62  pDetectiveObjVec( pNewDetectiveObjVec )
63 {
64 }
65 
67 {
68 }
69 
70 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDetectiveContext::createFastChildContext(
71  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
72 {
73  SvXMLImportContext* pContext = nullptr;
76 
77  switch (nElement)
78  {
80  pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), pAttribList, pDetectiveObjVec );
81  break;
83  pContext = new ScXMLDetectiveOperationContext( GetScImport(), pAttribList );
84  break;
85  }
86 
87  return pContext;
88 }
89 
91  ScXMLImport& rImport,
93  ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
94  ScXMLImportContext( rImport ),
95  pDetectiveObjVec( pNewDetectiveObjVec ),
96  bValid( false )
97 {
98  if ( !rAttrList.is() )
99  return;
100 
101  for (auto &aIter : *rAttrList)
102  {
103  switch (aIter.getToken())
104  {
106  {
107  sal_Int32 nOffset(0);
109  ScDocument* pDoc = GetScImport().GetDocument();
110  assert(pDoc);
112  }
113  break;
116  break;
119  break;
121  {
122  if (IsXMLToken(aIter, XML_TRUE))
124  }
125  break;
126  }
127  }
128 }
129 
131 {
132 }
133 
134 void SAL_CALL ScXMLDetectiveHighlightedContext::endFastElement( sal_Int32 /*nElement*/ )
135 {
136  switch( aDetectiveObj.eObjType )
137  {
138  case SC_DETOBJ_ARROW:
140  break;
142  case SC_DETOBJ_CIRCLE:
143  bValid = true;
144  break;
145  default:
146  bValid = false;
147  }
148  if( bValid )
149  pDetectiveObjVec->push_back( aDetectiveObj );
150 }
151 
153  ScXMLImport& rImport,
155  ScXMLImportContext( rImport ),
156  bHasType( false )
157 {
158  if ( rAttrList.is() )
159  {
160  for (auto &aIter : *rAttrList)
161  {
162  switch (aIter.getToken())
163  {
164  case XML_ELEMENT( TABLE, XML_NAME ):
166  break;
167  case XML_ELEMENT( TABLE, XML_INDEX ):
168  {
169  sal_Int32 nValue;
170  if (::sax::Converter::convertNumber( nValue, aIter.toString(), 0 ))
171  aDetectiveOp.nIndex = nValue;
172  }
173  break;
174  }
175  }
176  }
178 }
179 
181 {
182 }
183 
184 void SAL_CALL ScXMLDetectiveOperationContext::endFastElement( sal_Int32 /*nElement*/ )
185 {
186  if( bHasType && (aDetectiveOp.nIndex >= 0) )
188 }
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_MARKED_INVALID
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
XML_CONTAINS_ERROR
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
ScXMLDetectiveContext(ScXMLImport &rImport, ScMyImpDetectiveObjVec *pNewDetectiveObjVec)
ScMyTables & GetTables()
Definition: xmlimprt.hxx:208
bool GetFirstOp(ScMyImpDetectiveOp &rDetOp)
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual ~ScXMLDetectiveContext() override
ScMyImpDetectiveOpList aDetectiveOpList
XML_INDEX
ScMyImpDetectiveObjVec * pDetectiveObjVec
void AddDetectiveOp(const ScMyImpDetectiveOp &rDetOp)
ScMyImpDetectiveObjVec * pDetectiveObjVec
static bool GetRangeFromString(ScRange &rRange, const OUString &rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
virtual ~ScXMLDetectiveHighlightedContext() override
This class exists only to provide GetScImport() to its derived classes.
ScDetectiveObjType eObjType
bool operator<(const ScMyImpDetectiveOp &rDetOp) const
virtual ~ScXMLDetectiveOperationContext() override
static ScDetectiveObjType GetDetObjTypeFromString(std::u16string_view rString)
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:288
static bool GetDetOpTypeFromString(ScDetOpType &rDetOpType, std::u16string_view rString)
ScXMLImport & GetScImport()
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
XML_CELL_RANGE_ADDRESS
XML_TRUE
const ScAddress & GetCurrentCellPos() const
Definition: xmlsubti.hxx:80
TABLE
XML_HIGHLIGHTED_RANGE
#define XML_ELEMENT(prefix, name)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
XML_DIRECTION
ScMyImpDetectiveOpArray * GetDetectiveOpArray()
Definition: xmlimprt.cxx:1663
::std::vector< ScMyImpDetectiveObj > ScMyImpDetectiveObjVec
XML_OPERATION
ScXMLDetectiveOperationContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
sal_Int16 nValue
XML_NAME
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
ScXMLDetectiveHighlightedContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScMyImpDetectiveObjVec *pNewDetectiveObjVec)