| /************************************************************** |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| *************************************************************/ |
| |
| |
| |
| // MARKER(update_precomp.py): autogen include statement, do not remove |
| #include "precompiled_sc.hxx" |
| |
| |
| |
| // INCLUDE --------------------------------------------------------------- |
| #include <rtl/ustrbuf.hxx> |
| |
| #include "xmlnexpi.hxx" |
| #include "xmlimprt.hxx" |
| #include "xmlcelli.hxx" |
| #include "docuno.hxx" |
| #include "global.hxx" |
| #include "document.hxx" |
| #include "XMLConverter.hxx" |
| |
| #include <xmloff/xmltkmap.hxx> |
| #include <xmloff/nmspmap.hxx> |
| |
| using namespace com::sun::star; |
| |
| //------------------------------------------------------------------ |
| |
| ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext( ScXMLImport& rImport, |
| sal_uInt16 nPrfx, |
| const ::rtl::OUString& rLName, |
| const ::com::sun::star::uno::Reference< |
| ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) : |
| SvXMLImportContext( rImport, nPrfx, rLName ), |
| nScopeOfNameRange( MAXTABCOUNT ) //aRangeNameScope( MAXTABCOUNT ) |
| { |
| /* sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; |
| for( sal_Int16 i=0; i < nAttrCount; ++i ) |
| { |
| const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i )); |
| rtl::OUString aLocalName; |
| sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( |
| sAttrName, &aLocalName ); |
| const rtl::OUString& sValue(xAttrList->getValueByIndex( i )); |
| |
| const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap(); |
| |
| switch( rAttrTokenMap.Get( nPrefix, aLocalName ) ) |
| { |
| } |
| }*/ |
| rImport.LockSolarMutex(); |
| } |
| |
| ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext() |
| { |
| GetScImport().UnlockSolarMutex(); |
| } |
| |
| SvXMLImportContext *ScXMLNamedExpressionsContext::CreateChildContext( sal_uInt16 nPrefix, |
| const ::rtl::OUString& rLName, |
| const ::com::sun::star::uno::Reference< |
| ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) |
| { |
| SvXMLImportContext *pContext(0); |
| |
| const SvXMLTokenMap& rTokenMap(GetScImport().GetNamedExpressionsElemTokenMap()); |
| switch( rTokenMap.Get( nPrefix, rLName ) ) |
| { |
| case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE: |
| pContext = new ScXMLNamedRangeContext( GetScImport(), nPrefix, |
| rLName, xAttrList,nScopeOfNameRange//, |
| //this |
| ); |
| break; |
| case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION: |
| pContext = new ScXMLNamedExpressionContext( GetScImport(), nPrefix, |
| rLName, xAttrList, nScopeOfNameRange//, |
| //this |
| ); |
| break; |
| } |
| |
| if( !pContext ) |
| pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName ); |
| |
| return pContext; |
| } |
| |
| void ScXMLNamedExpressionsContext::EndElement() |
| { |
| // happends in ScXMLImport::EndDocument() |
| // because it has to be set after the Database Ranges |
| } |
| |
| ScXMLNamedRangeContext::ScXMLNamedRangeContext( ScXMLImport& rImport, |
| sal_uInt16 nPrfx, |
| const ::rtl::OUString& rLName, |
| const ::com::sun::star::uno::Reference< |
| ::com::sun::star::xml::sax::XAttributeList>& xAttrList, SCTAB nScopeOfNameRange) : |
| SvXMLImportContext( rImport, nPrfx, rLName ) |
| { |
| ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression); |
| pNamedExpression->nNameScope = nScopeOfNameRange; |
| // A simple table:cell-range-address is not a formula expression, stored |
| // without [] brackets but with dot, .A1 |
| pNamedExpression->eGrammar = formula::FormulaGrammar::mergeToGrammar( |
| GetScImport().GetDocument()->GetStorageGrammar(), |
| formula::FormulaGrammar::CONV_OOO); |
| sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0); |
| const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap(); |
| for( sal_Int16 i=0; i < nAttrCount; ++i ) |
| { |
| const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i )); |
| rtl::OUString aLocalName; |
| sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName( |
| sAttrName, &aLocalName )); |
| const rtl::OUString& sValue(xAttrList->getValueByIndex( i )); |
| |
| switch( rAttrTokenMap.Get( nPrefix, aLocalName ) ) |
| { |
| case XML_TOK_NAMED_RANGE_ATTR_NAME : |
| { |
| pNamedExpression->sName = sValue; |
| } |
| break; |
| case XML_TOK_NAMED_RANGE_ATTR_CELL_RANGE_ADDRESS : |
| { |
| pNamedExpression->sContent = sValue; |
| } |
| break; |
| case XML_TOK_NAMED_RANGE_ATTR_BASE_CELL_ADDRESS : |
| { |
| pNamedExpression->sBaseCellAddress = sValue; |
| } |
| break; |
| case XML_TOK_NAMED_RANGE_ATTR_RANGE_USABLE_AS : |
| { |
| pNamedExpression->sRangeType = sValue; |
| } |
| break; |
| } |
| } |
| pNamedExpression->bIsExpression = sal_False; |
| GetScImport().AddNamedExpression(pNamedExpression); |
| } |
| |
| ScXMLNamedRangeContext::~ScXMLNamedRangeContext() |
| { |
| } |
| |
| SvXMLImportContext *ScXMLNamedRangeContext::CreateChildContext( sal_uInt16 nPrefix, |
| const ::rtl::OUString& rLName, |
| const ::com::sun::star::uno::Reference< |
| ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) |
| { |
| /* const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap(); |
| switch( rTokenMap.Get( nPrefix, rLName ) ) |
| { |
| }*/ |
| return new SvXMLImportContext( GetImport(), nPrefix, rLName ); |
| } |
| |
| void ScXMLNamedRangeContext::EndElement() |
| { |
| } |
| |
| ScXMLNamedExpressionContext::ScXMLNamedExpressionContext( ScXMLImport& rImport, |
| sal_uInt16 nPrfx, |
| const ::rtl::OUString& rLName, |
| const ::com::sun::star::uno::Reference< |
| ::com::sun::star::xml::sax::XAttributeList>& xAttrList, SCTAB nScopeOfNameRange) : |
| SvXMLImportContext( rImport, nPrfx, rLName ) |
| { |
| ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression); |
| pNamedExpression->nNameScope = nScopeOfNameRange; |
| sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0); |
| const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap()); |
| for( sal_Int16 i=0; i < nAttrCount; ++i ) |
| { |
| const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i )); |
| rtl::OUString aLocalName; |
| sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName( |
| sAttrName, &aLocalName )); |
| const rtl::OUString& sValue(xAttrList->getValueByIndex( i )); |
| |
| switch( rAttrTokenMap.Get( nPrefix, aLocalName ) ) |
| { |
| case XML_TOK_NAMED_EXPRESSION_ATTR_NAME : |
| { |
| pNamedExpression->sName = sValue; |
| } |
| break; |
| case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION : |
| { |
| GetScImport().ExtractFormulaNamespaceGrammar( |
| pNamedExpression->sContent, pNamedExpression->sContentNmsp, |
| pNamedExpression->eGrammar, sValue ); |
| } |
| break; |
| case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS : |
| { |
| pNamedExpression->sBaseCellAddress = sValue; |
| } |
| break; |
| } |
| } |
| pNamedExpression->bIsExpression = sal_True; |
| GetScImport().AddNamedExpression(pNamedExpression); |
| } |
| |
| ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext() |
| { |
| } |
| |
| SvXMLImportContext *ScXMLNamedExpressionContext::CreateChildContext( sal_uInt16 nPrefix, |
| const ::rtl::OUString& rLName, |
| const ::com::sun::star::uno::Reference< |
| ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) |
| { |
| /* const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap(); |
| switch( rTokenMap.Get( nPrefix, rLName ) ) |
| { |
| }*/ |
| return new SvXMLImportContext( GetImport(), nPrefix, rLName );; |
| } |
| |
| void ScXMLNamedExpressionContext::EndElement() |
| { |
| } |
| |