1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLDetectiveContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //___________________________________________________________________
37 #include "XMLDetectiveContext.hxx"
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include "convuno.hxx"
42 #include "xmlimprt.hxx"
43 #include "XMLConverter.hxx"
44 #include "rangeutl.hxx"
48 using ::rtl::OUString
;
49 using namespace ::com::sun::star
;
50 using namespace xmloff::token
;
53 //___________________________________________________________________
55 ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
57 eObjType( SC_DETOBJ_NONE
),
58 bHasError( sal_False
)
62 //___________________________________________________________________
64 sal_Bool
ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp
& rDetOp
) const
66 return (nIndex
< rDetOp
.nIndex
);
69 void ScMyImpDetectiveOpArray::Sort()
71 aDetectiveOpList
.sort();
74 sal_Bool
ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp
& rDetOp
)
76 if( aDetectiveOpList
.empty() )
78 ScMyImpDetectiveOpList::iterator aItr
= aDetectiveOpList
.begin();
80 aDetectiveOpList
.erase( aItr
);
85 //___________________________________________________________________
87 ScXMLDetectiveContext::ScXMLDetectiveContext(
90 const OUString
& rLName
,
91 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
) :
92 SvXMLImportContext( rImport
, nPrfx
, rLName
),
93 pDetectiveObjVec( pNewDetectiveObjVec
)
97 ScXMLDetectiveContext::~ScXMLDetectiveContext()
101 SvXMLImportContext
*ScXMLDetectiveContext::CreateChildContext(
103 const OUString
& rLName
,
104 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
106 SvXMLImportContext
* pContext
= NULL
;
107 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetDetectiveElemTokenMap();
109 switch( rTokenMap
.Get( nPrefix
, rLName
) )
111 case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED
:
112 pContext
= new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix
, rLName
, xAttrList
, pDetectiveObjVec
);
114 case XML_TOK_DETECTIVE_ELEM_OPERATION
:
115 pContext
= new ScXMLDetectiveOperationContext( GetScImport(), nPrefix
, rLName
, xAttrList
);
119 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
124 void ScXMLDetectiveContext::EndElement()
129 //___________________________________________________________________
131 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
132 ScXMLImport
& rImport
,
134 const OUString
& rLName
,
135 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
136 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
):
137 SvXMLImportContext( rImport
, nPrfx
, rLName
),
138 pDetectiveObjVec( pNewDetectiveObjVec
),
142 if( !xAttrList
.is() ) return;
144 sal_Int16 nAttrCount
= xAttrList
->getLength();
145 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetDetectiveHighlightedAttrTokenMap();
147 for( sal_Int16 nIndex
= 0; nIndex
< nAttrCount
; ++nIndex
)
149 const rtl::OUString
& sAttrName (xAttrList
->getNameByIndex( nIndex
));
150 const rtl::OUString
& sValue (xAttrList
->getValueByIndex( nIndex
));
152 USHORT nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
154 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
156 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE
:
158 sal_Int32
nOffset(0);
159 GetScImport().LockSolarMutex();
160 bValid
= ScRangeStringConverter::GetRangeFromString( aDetectiveObj
.aSourceRange
, sValue
, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
161 GetScImport().UnlockSolarMutex();
164 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION
:
165 aDetectiveObj
.eObjType
= ScXMLConverter::GetDetObjTypeFromString( sValue
);
167 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR
:
168 aDetectiveObj
.bHasError
= IsXMLToken(sValue
, XML_TRUE
);
170 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID
:
172 if (IsXMLToken(sValue
, XML_TRUE
))
173 aDetectiveObj
.eObjType
= SC_DETOBJ_CIRCLE
;
180 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
184 SvXMLImportContext
*ScXMLDetectiveHighlightedContext::CreateChildContext(
186 const OUString
& rLName
,
187 const uno::Reference
< xml::sax::XAttributeList
>& /* xAttrList */ )
189 return new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
192 void ScXMLDetectiveHighlightedContext::EndElement()
194 switch( aDetectiveObj
.eObjType
)
196 case SC_DETOBJ_ARROW
:
197 case SC_DETOBJ_TOOTHERTAB
:
199 case SC_DETOBJ_FROMOTHERTAB
:
200 case SC_DETOBJ_CIRCLE
:
207 pDetectiveObjVec
->push_back( aDetectiveObj
);
211 //___________________________________________________________________
213 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
214 ScXMLImport
& rImport
,
216 const OUString
& rLName
,
217 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
) :
218 SvXMLImportContext( rImport
, nPrfx
, rLName
),
220 bHasType( sal_False
)
222 if( !xAttrList
.is() ) return;
224 sal_Int16 nAttrCount
= xAttrList
->getLength();
225 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetDetectiveOperationAttrTokenMap();
227 for( sal_Int16 nIndex
= 0; nIndex
< nAttrCount
; ++nIndex
)
229 const rtl::OUString
& sAttrName (xAttrList
->getNameByIndex( nIndex
));
230 const rtl::OUString
& sValue (xAttrList
->getValueByIndex( nIndex
));
232 USHORT nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
234 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
236 case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME
:
237 bHasType
= ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp
.eOpType
, sValue
);
239 case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX
:
242 if( SvXMLUnitConverter::convertNumber( nValue
, sValue
, 0 ) )
243 aDetectiveOp
.nIndex
= nValue
;
248 ScUnoConversion::FillScAddress( aDetectiveOp
.aPosition
, rImport
.GetTables().GetRealCellPos() );
251 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
255 SvXMLImportContext
*ScXMLDetectiveOperationContext::CreateChildContext(
257 const OUString
& rLName
,
258 const uno::Reference
< xml::sax::XAttributeList
>& /* xAttrList */ )
260 return new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
263 void ScXMLDetectiveOperationContext::EndElement()
265 if( bHasType
&& (aDetectiveOp
.nIndex
>= 0) )
266 GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp
);