Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : :
31 : :
32 : : //___________________________________________________________________
33 : : #include "XMLDetectiveContext.hxx"
34 : :
35 : : #include <sax/tools/converter.hxx>
36 : : #include <xmloff/nmspmap.hxx>
37 : : #include <xmloff/xmltoken.hxx>
38 : : #include "convuno.hxx"
39 : : #include "xmlimprt.hxx"
40 : : #include "XMLConverter.hxx"
41 : : #include "rangeutl.hxx"
42 : :
43 : : #include <algorithm>
44 : :
45 : : using ::rtl::OUString;
46 : : using namespace ::com::sun::star;
47 : : using namespace xmloff::token;
48 : :
49 : :
50 : : //___________________________________________________________________
51 : :
52 : 0 : ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
53 : : aSourceRange(),
54 : : eObjType( SC_DETOBJ_NONE ),
55 : 0 : bHasError( false )
56 : : {
57 : 0 : }
58 : :
59 : : //___________________________________________________________________
60 : :
61 : 0 : bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
62 : : {
63 : 0 : return (nIndex < rDetOp.nIndex);
64 : : }
65 : :
66 : 93 : void ScMyImpDetectiveOpArray::Sort()
67 : : {
68 : 93 : aDetectiveOpList.sort();
69 : 93 : }
70 : :
71 : 93 : bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
72 : : {
73 [ + - ]: 93 : if( aDetectiveOpList.empty() )
74 : 93 : return false;
75 : 0 : ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
76 : 0 : rDetOp = *aItr;
77 [ # # ]: 0 : aDetectiveOpList.erase( aItr );
78 : 93 : return true;
79 : : }
80 : :
81 : :
82 : : //___________________________________________________________________
83 : :
84 : 0 : ScXMLDetectiveContext::ScXMLDetectiveContext(
85 : : ScXMLImport& rImport,
86 : : sal_uInt16 nPrfx,
87 : : const OUString& rLName,
88 : : ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
89 : : SvXMLImportContext( rImport, nPrfx, rLName ),
90 : 0 : pDetectiveObjVec( pNewDetectiveObjVec )
91 : : {
92 : 0 : }
93 : :
94 : 0 : ScXMLDetectiveContext::~ScXMLDetectiveContext()
95 : : {
96 [ # # ]: 0 : }
97 : :
98 : 0 : SvXMLImportContext *ScXMLDetectiveContext::CreateChildContext(
99 : : sal_uInt16 nPrefix,
100 : : const OUString& rLName,
101 : : const uno::Reference< xml::sax::XAttributeList>& xAttrList )
102 : : {
103 : 0 : SvXMLImportContext* pContext = NULL;
104 : 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDetectiveElemTokenMap();
105 : :
106 [ # # # ]: 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
107 : : {
108 : : case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED:
109 [ # # ]: 0 : pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix, rLName, xAttrList, pDetectiveObjVec );
110 : 0 : break;
111 : : case XML_TOK_DETECTIVE_ELEM_OPERATION:
112 [ # # ]: 0 : pContext = new ScXMLDetectiveOperationContext( GetScImport(), nPrefix, rLName, xAttrList );
113 : 0 : break;
114 : : }
115 [ # # ]: 0 : if( !pContext )
116 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
117 : :
118 : 0 : return pContext;
119 : : }
120 : :
121 : 0 : void ScXMLDetectiveContext::EndElement()
122 : : {
123 : 0 : }
124 : :
125 : :
126 : : //___________________________________________________________________
127 : :
128 : 0 : ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
129 : : ScXMLImport& rImport,
130 : : sal_uInt16 nPrfx,
131 : : const OUString& rLName,
132 : : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
133 : : ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
134 : : SvXMLImportContext( rImport, nPrfx, rLName ),
135 : : pDetectiveObjVec( pNewDetectiveObjVec ),
136 : : aDetectiveObj(),
137 : 0 : bValid( false )
138 : : {
139 [ # # ]: 0 : if( !xAttrList.is() ) return;
140 : :
141 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList->getLength();
142 [ # # ]: 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveHighlightedAttrTokenMap();
143 : :
144 [ # # ]: 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
145 : : {
146 [ # # ][ # # ]: 0 : const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
147 [ # # ][ # # ]: 0 : const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
148 : 0 : OUString aLocalName;
149 [ # # ]: 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
150 : :
151 [ # # ][ # # : 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
# # # ]
152 : : {
153 : : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE:
154 : : {
155 : 0 : sal_Int32 nOffset(0);
156 [ # # ]: 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
157 [ # # ][ # # ]: 0 : bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
158 : : }
159 : 0 : break;
160 : : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION:
161 [ # # ]: 0 : aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( sValue );
162 : 0 : break;
163 : : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR:
164 [ # # ]: 0 : aDetectiveObj.bHasError = IsXMLToken(sValue, XML_TRUE);
165 : 0 : break;
166 : : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID:
167 : : {
168 [ # # ][ # # ]: 0 : if (IsXMLToken(sValue, XML_TRUE))
169 : 0 : aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
170 : : }
171 : 0 : break;
172 : : }
173 : 0 : }
174 : : }
175 : :
176 : 0 : ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
177 : : {
178 [ # # ]: 0 : }
179 : :
180 : 0 : SvXMLImportContext *ScXMLDetectiveHighlightedContext::CreateChildContext(
181 : : sal_uInt16 nPrefix,
182 : : const OUString& rLName,
183 : : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
184 : : {
185 [ # # ]: 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
186 : : }
187 : :
188 : 0 : void ScXMLDetectiveHighlightedContext::EndElement()
189 : : {
190 [ # # # ]: 0 : switch( aDetectiveObj.eObjType )
191 : : {
192 : : case SC_DETOBJ_ARROW:
193 : : case SC_DETOBJ_TOOTHERTAB:
194 : 0 : break;
195 : : case SC_DETOBJ_FROMOTHERTAB:
196 : : case SC_DETOBJ_CIRCLE:
197 : 0 : bValid = true;
198 : 0 : break;
199 : : default:
200 : 0 : bValid = false;
201 : : }
202 [ # # ]: 0 : if( bValid )
203 : 0 : pDetectiveObjVec->push_back( aDetectiveObj );
204 : 0 : }
205 : :
206 : :
207 : : //___________________________________________________________________
208 : :
209 : 0 : ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
210 : : ScXMLImport& rImport,
211 : : sal_uInt16 nPrfx,
212 : : const OUString& rLName,
213 : : const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
214 : : SvXMLImportContext( rImport, nPrfx, rLName ),
215 : : aDetectiveOp(),
216 : 0 : bHasType( false )
217 : : {
218 [ # # ]: 0 : if( !xAttrList.is() ) return;
219 : :
220 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList->getLength();
221 [ # # ]: 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveOperationAttrTokenMap();
222 : :
223 [ # # ]: 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
224 : : {
225 [ # # ][ # # ]: 0 : const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
226 [ # # ][ # # ]: 0 : const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
227 : 0 : OUString aLocalName;
228 [ # # ]: 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
229 : :
230 [ # # ]: 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
[ # # # ]
231 : : {
232 : : case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME:
233 [ # # ]: 0 : bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, sValue );
234 : 0 : break;
235 : : case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX:
236 : : {
237 : : sal_Int32 nValue;
238 [ # # ][ # # ]: 0 : if (::sax::Converter::convertNumber( nValue, sValue, 0 ))
239 : 0 : aDetectiveOp.nIndex = nValue;
240 : : }
241 : 0 : break;
242 : : }
243 : 0 : }
244 : 0 : aDetectiveOp.aPosition = rImport.GetTables().GetCurrentCellPos();
245 : : }
246 : :
247 : 0 : ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
248 : : {
249 [ # # ]: 0 : }
250 : :
251 : 0 : SvXMLImportContext *ScXMLDetectiveOperationContext::CreateChildContext(
252 : : sal_uInt16 nPrefix,
253 : : const OUString& rLName,
254 : : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
255 : : {
256 [ # # ]: 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
257 : : }
258 : :
259 : 0 : void ScXMLDetectiveOperationContext::EndElement()
260 : : {
261 [ # # ][ # # ]: 0 : if( bHasType && (aDetectiveOp.nIndex >= 0) )
262 : 0 : GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
263 : 0 : }
264 : :
265 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|