1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 //___________________________________________________________________
30 #include "XMLCellRangeSourceContext.hxx"
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include "xmlimprt.hxx"
34
35 using ::rtl::OUString;
36 using namespace ::com::sun::star;
37
38
39 //___________________________________________________________________
40
ScMyImpCellRangeSource()41 ScMyImpCellRangeSource::ScMyImpCellRangeSource() :
42 nColumns( 0 ),
43 nRows( 0 ),
44 nRefresh( 0 )
45 {
46 }
47
48
49 //___________________________________________________________________
50
ScXMLCellRangeSourceContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScMyImpCellRangeSource * pCellRangeSource)51 ScXMLCellRangeSourceContext::ScXMLCellRangeSourceContext(
52 ScXMLImport& rImport,
53 sal_uInt16 nPrfx,
54 const OUString& rLName,
55 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
56 ScMyImpCellRangeSource* pCellRangeSource ) :
57 SvXMLImportContext( rImport, nPrfx, rLName )
58 {
59 if( !xAttrList.is() ) return;
60
61 sal_Int16 nAttrCount = xAttrList->getLength();
62 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableCellRangeSourceAttrTokenMap();
63
64 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
65 {
66 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( nIndex ));
67 const OUString& sValue(xAttrList->getValueByIndex( nIndex ));
68 OUString aLocalName;
69 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
70
71 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
72 {
73 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_NAME:
74 pCellRangeSource->sSourceStr = sValue;
75 break;
76 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_FILTER_NAME:
77 pCellRangeSource->sFilterName = sValue;
78 break;
79 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_FILTER_OPTIONS:
80 pCellRangeSource->sFilterOptions = sValue;
81 break;
82 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_HREF:
83 pCellRangeSource->sURL = GetScImport().GetAbsoluteReference(sValue);
84 break;
85 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_LAST_COLUMN:
86 {
87 sal_Int32 nValue;
88 if( SvXMLUnitConverter::convertNumber( nValue, sValue, 1 ) )
89 pCellRangeSource->nColumns = nValue;
90 else
91 pCellRangeSource->nColumns = 1;
92 }
93 break;
94 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_LAST_ROW:
95 {
96 sal_Int32 nValue;
97 if( SvXMLUnitConverter::convertNumber( nValue, sValue, 1 ) )
98 pCellRangeSource->nRows = nValue;
99 else
100 pCellRangeSource->nRows = 1;
101 }
102 break;
103 case XML_TOK_TABLE_CELL_RANGE_SOURCE_ATTR_REFRESH_DELAY:
104 {
105 double fTime;
106 if( SvXMLUnitConverter::convertTime( fTime, sValue ) )
107 pCellRangeSource->nRefresh = Max( (sal_Int32)(fTime * 86400.0), (sal_Int32)0 );
108 }
109 break;
110 }
111 }
112 }
113
~ScXMLCellRangeSourceContext()114 ScXMLCellRangeSourceContext::~ScXMLCellRangeSourceContext()
115 {
116 }
117
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)118 SvXMLImportContext *ScXMLCellRangeSourceContext::CreateChildContext(
119 sal_uInt16 nPrefix,
120 const OUString& rLName,
121 const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
122 {
123 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
124 }
125
EndElement()126 void ScXMLCellRangeSourceContext::EndElement()
127 {
128 }
129
130