Line data Source code
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 :
21 :
22 :
23 : //___________________________________________________________________
24 : #include "XMLDetectiveContext.hxx"
25 :
26 : #include <sax/tools/converter.hxx>
27 : #include <xmloff/nmspmap.hxx>
28 : #include <xmloff/xmltoken.hxx>
29 : #include "convuno.hxx"
30 : #include "xmlimprt.hxx"
31 : #include "XMLConverter.hxx"
32 : #include "rangeutl.hxx"
33 :
34 : #include <algorithm>
35 :
36 : using namespace ::com::sun::star;
37 : using namespace xmloff::token;
38 :
39 :
40 : //___________________________________________________________________
41 :
42 0 : ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
43 : aSourceRange(),
44 : eObjType( SC_DETOBJ_NONE ),
45 0 : bHasError( false )
46 : {
47 0 : }
48 :
49 : //___________________________________________________________________
50 :
51 0 : bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
52 : {
53 0 : return (nIndex < rDetOp.nIndex);
54 : }
55 :
56 75 : void ScMyImpDetectiveOpArray::Sort()
57 : {
58 75 : aDetectiveOpList.sort();
59 75 : }
60 :
61 75 : bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
62 : {
63 75 : if( aDetectiveOpList.empty() )
64 75 : return false;
65 0 : ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
66 0 : rDetOp = *aItr;
67 0 : aDetectiveOpList.erase( aItr );
68 0 : return true;
69 : }
70 :
71 :
72 : //___________________________________________________________________
73 :
74 0 : ScXMLDetectiveContext::ScXMLDetectiveContext(
75 : ScXMLImport& rImport,
76 : sal_uInt16 nPrfx,
77 : const OUString& rLName,
78 : ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
79 : SvXMLImportContext( rImport, nPrfx, rLName ),
80 0 : pDetectiveObjVec( pNewDetectiveObjVec )
81 : {
82 0 : }
83 :
84 0 : ScXMLDetectiveContext::~ScXMLDetectiveContext()
85 : {
86 0 : }
87 :
88 0 : SvXMLImportContext *ScXMLDetectiveContext::CreateChildContext(
89 : sal_uInt16 nPrefix,
90 : const OUString& rLName,
91 : const uno::Reference< xml::sax::XAttributeList>& xAttrList )
92 : {
93 0 : SvXMLImportContext* pContext = NULL;
94 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDetectiveElemTokenMap();
95 :
96 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
97 : {
98 : case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED:
99 0 : pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix, rLName, xAttrList, pDetectiveObjVec );
100 0 : break;
101 : case XML_TOK_DETECTIVE_ELEM_OPERATION:
102 0 : pContext = new ScXMLDetectiveOperationContext( GetScImport(), nPrefix, rLName, xAttrList );
103 0 : break;
104 : }
105 0 : if( !pContext )
106 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
107 :
108 0 : return pContext;
109 : }
110 :
111 0 : void ScXMLDetectiveContext::EndElement()
112 : {
113 0 : }
114 :
115 :
116 : //___________________________________________________________________
117 :
118 0 : ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
119 : ScXMLImport& rImport,
120 : sal_uInt16 nPrfx,
121 : const OUString& rLName,
122 : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
123 : ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
124 : SvXMLImportContext( rImport, nPrfx, rLName ),
125 : pDetectiveObjVec( pNewDetectiveObjVec ),
126 : aDetectiveObj(),
127 0 : bValid( false )
128 : {
129 0 : if( !xAttrList.is() ) return;
130 :
131 0 : sal_Int16 nAttrCount = xAttrList->getLength();
132 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveHighlightedAttrTokenMap();
133 :
134 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
135 : {
136 0 : const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
137 0 : const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
138 0 : OUString aLocalName;
139 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
140 :
141 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
142 : {
143 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE:
144 : {
145 0 : sal_Int32 nOffset(0);
146 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
147 0 : bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
148 : }
149 0 : break;
150 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION:
151 0 : aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( sValue );
152 0 : break;
153 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR:
154 0 : aDetectiveObj.bHasError = IsXMLToken(sValue, XML_TRUE);
155 0 : break;
156 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID:
157 : {
158 0 : if (IsXMLToken(sValue, XML_TRUE))
159 0 : aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
160 : }
161 0 : break;
162 : }
163 0 : }
164 : }
165 :
166 0 : ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
167 : {
168 0 : }
169 :
170 0 : SvXMLImportContext *ScXMLDetectiveHighlightedContext::CreateChildContext(
171 : sal_uInt16 nPrefix,
172 : const OUString& rLName,
173 : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
174 : {
175 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
176 : }
177 :
178 0 : void ScXMLDetectiveHighlightedContext::EndElement()
179 : {
180 0 : switch( aDetectiveObj.eObjType )
181 : {
182 : case SC_DETOBJ_ARROW:
183 : case SC_DETOBJ_TOOTHERTAB:
184 0 : break;
185 : case SC_DETOBJ_FROMOTHERTAB:
186 : case SC_DETOBJ_CIRCLE:
187 0 : bValid = true;
188 0 : break;
189 : default:
190 0 : bValid = false;
191 : }
192 0 : if( bValid )
193 0 : pDetectiveObjVec->push_back( aDetectiveObj );
194 0 : }
195 :
196 :
197 : //___________________________________________________________________
198 :
199 0 : ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
200 : ScXMLImport& rImport,
201 : sal_uInt16 nPrfx,
202 : const OUString& rLName,
203 : const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
204 : SvXMLImportContext( rImport, nPrfx, rLName ),
205 : aDetectiveOp(),
206 0 : bHasType( false )
207 : {
208 0 : if( !xAttrList.is() ) return;
209 :
210 0 : sal_Int16 nAttrCount = xAttrList->getLength();
211 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveOperationAttrTokenMap();
212 :
213 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
214 : {
215 0 : const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
216 0 : const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
217 0 : OUString aLocalName;
218 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
219 :
220 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
221 : {
222 : case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME:
223 0 : bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, sValue );
224 0 : break;
225 : case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX:
226 : {
227 : sal_Int32 nValue;
228 0 : if (::sax::Converter::convertNumber( nValue, sValue, 0 ))
229 0 : aDetectiveOp.nIndex = nValue;
230 : }
231 0 : break;
232 : }
233 0 : }
234 0 : aDetectiveOp.aPosition = rImport.GetTables().GetCurrentCellPos();
235 : }
236 :
237 0 : ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
238 : {
239 0 : }
240 :
241 0 : SvXMLImportContext *ScXMLDetectiveOperationContext::CreateChildContext(
242 : sal_uInt16 nPrefix,
243 : const OUString& rLName,
244 : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
245 : {
246 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
247 : }
248 :
249 0 : void ScXMLDetectiveOperationContext::EndElement()
250 : {
251 0 : if( bHasType && (aDetectiveOp.nIndex >= 0) )
252 0 : GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
253 0 : }
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|