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 #include "xmllabri.hxx"
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include "xmlimprt.hxx"
33
34 using namespace ::com::sun::star;
35 using ::rtl::OUString;
36 using namespace xmloff::token;
37
38
39 //___________________________________________________________________
40
ScXMLLabelRangesContext(ScXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)41 ScXMLLabelRangesContext::ScXMLLabelRangesContext(
42 ScXMLImport& rImport,
43 sal_uInt16 nPrefix,
44 const OUString& rLName,
45 const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ ):
46 SvXMLImportContext( rImport, nPrefix, rLName )
47 {
48 rImport.LockSolarMutex();
49 }
50
~ScXMLLabelRangesContext()51 ScXMLLabelRangesContext::~ScXMLLabelRangesContext()
52 {
53 GetScImport().UnlockSolarMutex();
54 }
55
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)56 SvXMLImportContext* ScXMLLabelRangesContext::CreateChildContext(
57 sal_uInt16 nPrefix,
58 const OUString& rLName,
59 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
60 {
61 SvXMLImportContext* pContext(NULL);
62 const SvXMLTokenMap& rTokenMap(GetScImport().GetLabelRangesElemTokenMap());
63
64 switch( rTokenMap.Get( nPrefix, rLName ) )
65 {
66 case XML_TOK_LABEL_RANGE_ELEM:
67 pContext = new ScXMLLabelRangeContext( GetScImport(), nPrefix, rLName, xAttrList );
68 break;
69 }
70 if( !pContext )
71 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
72
73 return pContext;
74 }
75
EndElement()76 void ScXMLLabelRangesContext::EndElement()
77 {
78 }
79
80
81 //___________________________________________________________________
82
ScXMLLabelRangeContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)83 ScXMLLabelRangeContext::ScXMLLabelRangeContext(
84 ScXMLImport& rImport,
85 sal_uInt16 nPrfx,
86 const OUString& rLName,
87 const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
88 SvXMLImportContext( rImport, nPrfx, rLName ),
89 bColumnOrientation( sal_False )
90 {
91 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
92 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetLabelRangeAttrTokenMap());
93
94 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
95 {
96 const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
97 const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
98 OUString aLocalName;
99 sal_uInt16 nPrefix (GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ));
100
101 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
102 {
103 case XML_TOK_LABEL_RANGE_ATTR_LABEL_RANGE:
104 sLabelRangeStr = sValue;
105 break;
106 case XML_TOK_LABEL_RANGE_ATTR_DATA_RANGE:
107 sDataRangeStr = sValue;
108 break;
109 case XML_TOK_LABEL_RANGE_ATTR_ORIENTATION:
110 bColumnOrientation = IsXMLToken(sValue, XML_COLUMN );
111 break;
112 }
113 }
114 }
115
~ScXMLLabelRangeContext()116 ScXMLLabelRangeContext::~ScXMLLabelRangeContext()
117 {
118 }
119
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)120 SvXMLImportContext* ScXMLLabelRangeContext::CreateChildContext(
121 sal_uInt16 nPrefix,
122 const OUString& rLName,
123 const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ )
124 {
125 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
126 }
127
EndElement()128 void ScXMLLabelRangeContext::EndElement()
129 {
130 // #b5071088# Label ranges must be stored as strings until all sheets are loaded
131 // (like named expressions).
132
133 ScMyLabelRange* pLabelRange = new ScMyLabelRange;
134
135 pLabelRange->sLabelRangeStr = sLabelRangeStr;
136 pLabelRange->sDataRangeStr = sDataRangeStr;
137 pLabelRange->bColumnOrientation = bColumnOrientation;
138
139 GetScImport().AddLabelRange(pLabelRange);
140 }
141
142