diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2009-07-29 14:46:52 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2009-07-29 14:46:52 +0000 |
commit | 32cd63b065ce197e0e141177e3cde3858e8f91c0 (patch) | |
tree | d56ff441aa296af7e529d65143d9547bdbee64bc /sc/source/filter/xml/xmlstyli.cxx | |
parent | ab8dd2505c7486eed6f9ab9d4a4fba6e586ce81b (diff) |
CWS-TOOLING: integrate CWS dr71
2009-07-07 16:26:00 +0200 dr r273805 : #i10000# unused variables
2009-07-07 10:27:14 +0200 dr r273780 : CWS-TOOLING: rebase CWS dr71 to trunk@273468 (milestone: DEV300:m51)
2009-07-01 11:28:24 +0200 dr r273559 : #101471# special handling for XL library functions in ODF formulas (EUROCONVERT)
2009-06-29 17:48:46 +0200 dr r273478 : #i101471# typo
2009-06-29 17:35:16 +0200 dr r273477 : #i101471# import msoxl: formulas from conditional formatting and data validation
2009-06-18 13:45:17 +0200 dr r273115 : #101471# changed interface css.sheet.XFormulaParser
2009-06-18 13:44:43 +0200 dr r273114 : #101471# changed interface css.sheet.XFormulaParser
2009-06-17 17:29:23 +0200 dr r273089 : #i101471# extend the XFormulaParser interface with a ReferencePosition parameter, make rel-refs from msoxl: namespace working
2009-06-17 17:28:39 +0200 dr r273088 : #i101471# extend the XFormulaParser interface with a ReferencePosition parameter
2009-06-17 17:28:19 +0200 dr r273087 : #i101471# extend the XFormulaParser interface with a ReferencePosition parameter
2009-06-17 17:27:19 +0200 dr r273086 : #i101471# extend the XFormulaParser interface with a ReferencePosition parameter, remove that property from FormulaParser service
2009-06-17 12:52:20 +0200 dr r273059 : #i101471# import cell formulas from msoxl: namespace
2009-06-16 11:40:50 +0200 dr r273013 : #i101471# import formula namespace from xml elements
2009-06-12 18:34:13 +0200 dr r272935 : #i101471# external formula parser for oox in odf
2009-06-12 18:33:13 +0200 dr r272934 : #i101471# external formula parsers
2009-06-12 18:29:46 +0200 dr r272933 : #i101471# external formula parsers
2009-06-05 15:53:47 +0200 dr r272705 : #i101471# provide OOX formula parser as UNO service
Diffstat (limited to 'sc/source/filter/xml/xmlstyli.cxx')
-rw-r--r-- | sc/source/filter/xml/xmlstyli.cxx | 242 |
1 files changed, 79 insertions, 163 deletions
diff --git a/sc/source/filter/xml/xmlstyli.cxx b/sc/source/filter/xml/xmlstyli.cxx index 3b411df8db08..79ba79f0e689 100644 --- a/sc/source/filter/xml/xmlstyli.cxx +++ b/sc/source/filter/xml/xmlstyli.cxx @@ -73,6 +73,7 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; using namespace xmloff::token; //using namespace ::com::sun::star::text; +using namespace ::formula; ScXMLCellImportPropertyMapper::ScXMLCellImportPropertyMapper( const UniReference< XMLPropertySetMapper >& rMapper, @@ -285,10 +286,7 @@ public: ScXMLMapContext::ScXMLMapContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< xml::sax::XAttributeList > & xAttrList ) - : SvXMLImportContext( rImport, nPrfx, rLName ), - sApplyStyle(), - sCondition(), - sBaseCell() + : SvXMLImportContext( rImport, nPrfx, rLName ) { sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0); for( sal_Int16 i=0; i < nAttrCount; ++i ) @@ -315,200 +313,118 @@ ScXMLMapContext::~ScXMLMapContext() { } -void XMLTableStyleContext::SetOperator(com::sun::star::uno::Sequence<beans::PropertyValue>& aProps, - const com::sun::star::sheet::ConditionOperator aOp) const -{ - sal_Int32 nLength(aProps.getLength()); - aProps.realloc(nLength + 1); - aProps[nLength].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_OPERATOR)); - aProps[nLength].Value <<= aOp; -} +namespace { -void XMLTableStyleContext::SetBaseCellAddress(com::sun::star::uno::Sequence<beans::PropertyValue>& aProps, - const rtl::OUString& sBaseCell) const +template< typename Type > +inline void lclAppendProperty( uno::Sequence< beans::PropertyValue >& rProps, const OUString& rPropName, const Type& rValue ) { - sal_Int32 nLength(aProps.getLength()); - aProps.realloc(nLength + 1); - - // #b4974740# source position must be set as string, because it may - // refer to a sheet that hasn't been loaded yet. - - aProps[nLength].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SOURCESTR)); - aProps[nLength].Value <<= sBaseCell; + sal_Int32 nLength = rProps.getLength(); + rProps.realloc( nLength + 1 ); + rProps[ nLength ].Name = rPropName; + rProps[ nLength ].Value <<= rValue; } -void XMLTableStyleContext::SetStyle(com::sun::star::uno::Sequence<beans::PropertyValue>& aProps, - const rtl::OUString& sApplyStyle) const +} // namespace + +void XMLTableStyleContext::SetOperator( uno::Sequence< beans::PropertyValue >& rProps, sheet::ConditionOperator eOp ) const { - sal_Int32 nLength(aProps.getLength()); - aProps.realloc(nLength + 1); - aProps[nLength].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_STYLENAME)); - aProps[nLength].Value <<= sApplyStyle; + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OPERATOR ) ), eOp ); } -void XMLTableStyleContext::SetFormula1(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps, - const rtl::OUString& sFormula, bool bPreParse) const +void XMLTableStyleContext::SetBaseCellAddress( uno::Sequence< beans::PropertyValue >& rProps, const OUString& rBaseCell ) const { - sal_Int32 nLength(aProps.getLength()); - aProps.realloc(nLength + 1); - aProps[nLength].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FORMULA1)); - if (bPreParse) - { - rtl::OUString sRealFormula(sFormula); - ScXMLConverter::ParseFormula(sRealFormula); - aProps[nLength].Value <<= sRealFormula; - } - else - aProps[nLength].Value <<= sFormula; + /* #b4974740# Source position must be set as string, because it may refer + to a sheet that hasn't been loaded yet. */ + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SOURCESTR ) ), rBaseCell ); } -void XMLTableStyleContext::SetFormula2(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps, - const rtl::OUString& sFormula) const +void XMLTableStyleContext::SetStyle( uno::Sequence<beans::PropertyValue>& rProps, const OUString& rApplyStyle ) const { - sal_Int32 nLength(aProps.getLength()); - aProps.realloc(nLength + 1); - aProps[nLength].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FORMULA2)); - rtl::OUString sRealFormula(sFormula); - ScXMLConverter::ParseFormula(sRealFormula); - aProps[nLength].Value <<= sRealFormula; + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_STYLENAME ) ), rApplyStyle ); } -void XMLTableStyleContext::SetFormulas(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps, - const rtl::OUString& sFormulas) const +void XMLTableStyleContext::SetFormula( uno::Sequence< beans::PropertyValue >& rProps, + sal_Int32 nFormulaIdx, const OUString& rFormula, const OUString& rFormulaNmsp, + FormulaGrammar::Grammar eGrammar, bool bHasNmsp ) const { - sal_Int32 i(0); - sal_Bool bString(sal_False); - sal_Int32 nBrakes(0); - while ((sFormulas[i] != ',' || nBrakes > 0 || bString) && i < sFormulas.getLength()) + OUString aFormula, aFormulaNmsp; + FormulaGrammar::Grammar eNewGrammar = FormulaGrammar::GRAM_UNSPECIFIED; + if( bHasNmsp ) { - if (sFormulas[i] == '(') - ++nBrakes; - if (sFormulas[i] == ')') - --nBrakes; - if (sFormulas[i] == '"') - bString = !bString; - ++i; + // the entire attribute contains a namespace: internal namespace not allowed + aFormula = rFormula; + aFormulaNmsp = rFormulaNmsp; + eNewGrammar = eGrammar; } - if (sFormulas[i] == ',') + else { - rtl::OUString sFormula1(sFormulas.copy(0, i)); - rtl::OUString sFormula2(sFormulas.copy(i + 1)); - SetFormula1(aProps, sFormula1); - SetFormula2(aProps, sFormula2); + // the attribute does not contain a namespace: try to find a namespace of an external grammar + GetScImport().ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eNewGrammar, rFormula, true ); + if( eNewGrammar != FormulaGrammar::GRAM_EXTERNAL ) + eNewGrammar = eGrammar; } -} -void XMLTableStyleContext::SetGrammar(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps, - const formula::FormulaGrammar::Grammar eGrammar) const -{ - sal_Int32 nLength(aProps.getLength()); - aProps.realloc(nLength + 1); - aProps[nLength].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_GRAMMAR)); - aProps[nLength].Value <<= static_cast<sal_Int32>(eGrammar); + // add formula, formula namespace, and grammar with appropriate property names + sal_Int32 nGrammar = static_cast< sal_Int32 >( eNewGrammar ); + switch( nFormulaIdx ) + { + case 1: + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULA1 ) ), aFormula ); + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULANMSP1 ) ), aFormulaNmsp ); + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_GRAMMAR1 ) ), nGrammar ); + break; + case 2: + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULA2 ) ), aFormula ); + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULANMSP2 ) ), aFormulaNmsp ); + lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_GRAMMAR2 ) ), nGrammar ); + break; + default: + OSL_ENSURE( false, "XMLTableStyleContext::SetFormula - invalid formula index" ); + } } void XMLTableStyleContext::GetConditionalFormat(uno::Any& aAny, const rtl::OUString& sTempCondition, const rtl::OUString& sApplyStyle, const rtl::OUString& sBaseCell) const { - rtl::OUString sCondition(sTempCondition); - if (sCondition.getLength() && sApplyStyle.getLength()) + if (sTempCondition.getLength() && sApplyStyle.getLength()) { uno::Reference<sheet::XSheetConditionalEntries> xConditionalEntries(aAny, uno::UNO_QUERY); if (xConditionalEntries.is()) { - const formula::FormulaGrammar::Grammar eStorageGrammar = GetScImport().GetDocument()->GetStorageGrammar(); - formula::FormulaGrammar::Grammar eGrammar = eStorageGrammar; - // ToDo: erase all blanks in the condition, but not in formulas or strings - rtl::OUString scell_content(RTL_CONSTASCII_USTRINGPARAM("cell_content")); - rtl::OUString scell_content_is_between(RTL_CONSTASCII_USTRINGPARAM("cell_content_is_between")); - rtl::OUString scell_content_is_not_between(RTL_CONSTASCII_USTRINGPARAM("cell_content_is_not_between")); - rtl::OUString sis_true_formula(RTL_CONSTASCII_USTRINGPARAM("is_true_formula")); uno::Sequence<beans::PropertyValue> aProps; if (sBaseCell.getLength()) SetBaseCellAddress(aProps, sBaseCell); SetStyle(aProps, sApplyStyle); - sal_Int32 i = 0; - while (sCondition[i] != '(' && i < sCondition.getLength()) - ++i; - if (sCondition[i] == '(') + + // extract leading namespace from condition string + OUString aCondition, aConditionNmsp; + FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED; + GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sTempCondition ); + bool bHasNmsp = aCondition.getLength() < sTempCondition.getLength(); + + // parse a condition from the attribute string + ScXMLConditionParseResult aParseResult; + ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 ); + + /* Check the result. A valid value in aParseResult.meToken implies + that the other members of aParseResult are filled with valid + data for that token. */ + switch( aParseResult.meToken ) { - sCondition = sCondition.copy(i + 1); - if (i == scell_content.getLength()) - { - sCondition = sCondition.copy(1); - switch (sCondition[0]) - { - case '<' : - { - if (sCondition[1] == '=') - { - SetOperator(aProps, sheet::ConditionOperator_LESS_EQUAL); - sCondition = sCondition.copy(2); - } - else - { - SetOperator(aProps, sheet::ConditionOperator_LESS); - sCondition = sCondition.copy(1); - } - } - break; - case '>' : - { - if (sCondition[1] == '=') - { - SetOperator(aProps, sheet::ConditionOperator_GREATER_EQUAL); - sCondition = sCondition.copy(2); - } - else - { - SetOperator(aProps, sheet::ConditionOperator_GREATER); - sCondition = sCondition.copy(1); - } - } - break; - case '=' : - { - SetOperator(aProps, sheet::ConditionOperator_EQUAL); - sCondition = sCondition.copy(1); - } - break; - case '!' : - { - SetOperator(aProps, sheet::ConditionOperator_NOT_EQUAL); - sCondition = sCondition.copy(1); - } - break; - } - SetFormula1(aProps, sCondition); - } - else if (i == scell_content_is_between.getLength()) - { - SetOperator(aProps, sheet::ConditionOperator_BETWEEN); - sCondition = sCondition.copy(0, sCondition.getLength() - 1); - SetFormulas(aProps, sCondition); - } - else if (i == scell_content_is_not_between.getLength()) - { - SetOperator(aProps, sheet::ConditionOperator_NOT_BETWEEN); - sCondition = sCondition.copy(0, sCondition.getLength() - 1); - SetFormulas(aProps, sCondition); - } - else if (i == sis_true_formula.getLength()) - { - SetOperator(aProps, sheet::ConditionOperator_FORMULA); - sCondition = sCondition.copy(0, sCondition.getLength() - 1); - rtl::OUString sFormula; - sal_uInt16 nFormulaPrefix = GetImport().GetNamespaceMap(). - _GetKeyByAttrName( sCondition, &sFormula, sal_False ); - if (ScXMLImport::IsAcceptedFormulaNamespace( nFormulaPrefix, - sCondition, eGrammar, eStorageGrammar)) - sCondition = sFormula; - SetFormula1(aProps, sCondition, false); - } + case XML_COND_CELLCONTENT: // condition is 'cell-content()<operator><expression>' + case XML_COND_ISTRUEFORMULA: // condition is 'is-true-formula(<expression>)' + case XML_COND_ISBETWEEN: // condition is 'cell-content-is-between(<expression1>,<expression2>)' + case XML_COND_ISNOTBETWEEN: // condition is 'cell-content-is-not-between(<expression1>,<expression2>)' + SetOperator( aProps, aParseResult.meOperator ); + SetFormula( aProps, 1, aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp ); + SetFormula( aProps, 2, aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp ); + break; + + default:; // unacceptable or unknown condition } - SetGrammar( aProps, eGrammar); - xConditionalEntries->addNew(aProps); + + xConditionalEntries->addNew( aProps ); aAny <<= xConditionalEntries; } } |