Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / XMLDetectiveContext.cxx
blobea7b370130d241ffe95cf2f0f5aae8480d10ad9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLDetectiveContext.hxx"
22 #include <sax/tools/converter.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include "xmlimprt.hxx"
26 #include "XMLConverter.hxx"
27 #include <rangeutl.hxx>
29 using namespace ::com::sun::star;
30 using namespace xmloff::token;
32 ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
33 aSourceRange(),
34 eObjType( SC_DETOBJ_NONE ),
35 bHasError( false )
39 bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
41 return (nIndex < rDetOp.nIndex);
44 void ScMyImpDetectiveOpArray::Sort()
46 aDetectiveOpList.sort();
49 bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
51 if( aDetectiveOpList.empty() )
52 return false;
53 ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
54 rDetOp = *aItr;
55 aDetectiveOpList.erase( aItr );
56 return true;
59 ScXMLDetectiveContext::ScXMLDetectiveContext(
60 ScXMLImport& rImport,
61 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
62 ScXMLImportContext( rImport ),
63 pDetectiveObjVec( pNewDetectiveObjVec )
67 ScXMLDetectiveContext::~ScXMLDetectiveContext()
71 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDetectiveContext::createFastChildContext(
72 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
74 SvXMLImportContext* pContext = nullptr;
75 sax_fastparser::FastAttributeList *pAttribList =
76 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
78 switch (nElement)
80 case XML_ELEMENT( TABLE, XML_HIGHLIGHTED_RANGE ):
81 pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), pAttribList, pDetectiveObjVec );
82 break;
83 case XML_ELEMENT( TABLE, XML_OPERATION ):
84 pContext = new ScXMLDetectiveOperationContext( GetScImport(), pAttribList );
85 break;
87 if( !pContext )
88 pContext = new SvXMLImportContext( GetImport() );
90 return pContext;
93 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
94 ScXMLImport& rImport,
95 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
96 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
97 ScXMLImportContext( rImport ),
98 pDetectiveObjVec( pNewDetectiveObjVec ),
99 aDetectiveObj(),
100 bValid( false )
102 if ( rAttrList.is() )
104 for (auto &aIter : *rAttrList)
106 switch (aIter.getToken())
108 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
110 sal_Int32 nOffset(0);
111 ScXMLImport::MutexGuard aGuard(GetScImport());
112 bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, aIter.toString(), GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
114 break;
115 case XML_ELEMENT( TABLE, XML_DIRECTION ):
116 aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( aIter.toString() );
117 break;
118 case XML_ELEMENT( TABLE, XML_CONTAINS_ERROR ):
119 aDetectiveObj.bHasError = IsXMLToken(aIter, XML_TRUE);
120 break;
121 case XML_ELEMENT( TABLE, XML_MARKED_INVALID ):
123 if (IsXMLToken(aIter, XML_TRUE))
124 aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
126 break;
132 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
136 void SAL_CALL ScXMLDetectiveHighlightedContext::endFastElement( sal_Int32 /*nElement*/ )
138 switch( aDetectiveObj.eObjType )
140 case SC_DETOBJ_ARROW:
141 case SC_DETOBJ_TOOTHERTAB:
142 break;
143 case SC_DETOBJ_FROMOTHERTAB:
144 case SC_DETOBJ_CIRCLE:
145 bValid = true;
146 break;
147 default:
148 bValid = false;
150 if( bValid )
151 pDetectiveObjVec->push_back( aDetectiveObj );
154 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
155 ScXMLImport& rImport,
156 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
157 ScXMLImportContext( rImport ),
158 aDetectiveOp(),
159 bHasType( false )
161 if ( rAttrList.is() )
163 for (auto &aIter : *rAttrList)
165 switch (aIter.getToken())
167 case XML_ELEMENT( TABLE, XML_NAME ):
168 bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, aIter.toString() );
169 break;
170 case XML_ELEMENT( TABLE, XML_INDEX ):
172 sal_Int32 nValue;
173 if (::sax::Converter::convertNumber( nValue, aIter.toString(), 0 ))
174 aDetectiveOp.nIndex = nValue;
176 break;
180 aDetectiveOp.aPosition = rImport.GetTables().GetCurrentCellPos();
183 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
187 void SAL_CALL ScXMLDetectiveOperationContext::endFastElement( sal_Int32 /*nElement*/ )
189 if( bHasType && (aDetectiveOp.nIndex >= 0) )
190 GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */