1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/xls/connectionsfragment.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
27cdf0e10cSrcweir #include "oox/xls/biffhelper.hxx"
28cdf0e10cSrcweir #include "oox/xls/connectionsbuffer.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace oox {
31cdf0e10cSrcweir namespace xls {
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // ============================================================================
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::oox::core;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using ::rtl::OUString;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // ============================================================================
40cdf0e10cSrcweir 
ConnectionContext(WorkbookFragmentBase & rParent,Connection & rConnection)41cdf0e10cSrcweir ConnectionContext::ConnectionContext( WorkbookFragmentBase& rParent, Connection& rConnection ) :
42cdf0e10cSrcweir     WorkbookContextBase( rParent ),
43cdf0e10cSrcweir     mrConnection( rConnection )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)47cdf0e10cSrcweir ContextHandlerRef ConnectionContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     switch( getCurrentElement() )
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         case XLS_TOKEN( connection ):
52cdf0e10cSrcweir             if( nElement == XLS_TOKEN( webPr ) )
53cdf0e10cSrcweir             {
54cdf0e10cSrcweir                 mrConnection.importWebPr( rAttribs );
55cdf0e10cSrcweir                 return this;
56cdf0e10cSrcweir             }
57cdf0e10cSrcweir         break;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         case XLS_TOKEN( webPr ):
60cdf0e10cSrcweir             if( nElement == XLS_TOKEN( tables ) )
61cdf0e10cSrcweir             {
62cdf0e10cSrcweir                 mrConnection.importTables( rAttribs );
63cdf0e10cSrcweir                 return this;
64cdf0e10cSrcweir             }
65cdf0e10cSrcweir         break;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         case XLS_TOKEN( tables ):
68cdf0e10cSrcweir             mrConnection.importTable( rAttribs, nElement );
69cdf0e10cSrcweir         break;
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir     return 0;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
onStartElement(const AttributeList & rAttribs)74cdf0e10cSrcweir void ConnectionContext::onStartElement( const AttributeList& rAttribs )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     if( getCurrentElement() == XLS_TOKEN( connection ) )
77cdf0e10cSrcweir         mrConnection.importConnection( rAttribs );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream & rStrm)80cdf0e10cSrcweir ContextHandlerRef ConnectionContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     switch( getCurrentElement() )
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         case BIFF12_ID_CONNECTION:
85cdf0e10cSrcweir             if( nRecId == BIFF12_ID_WEBPR )
86cdf0e10cSrcweir             {
87cdf0e10cSrcweir                 mrConnection.importWebPr( rStrm );
88cdf0e10cSrcweir                 return this;
89cdf0e10cSrcweir             }
90cdf0e10cSrcweir         break;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         case BIFF12_ID_WEBPR:
93cdf0e10cSrcweir             if( nRecId == BIFF12_ID_WEBPRTABLES )
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 mrConnection.importWebPrTables( rStrm );
96cdf0e10cSrcweir                 return this;
97cdf0e10cSrcweir             }
98cdf0e10cSrcweir         break;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         case BIFF12_ID_WEBPRTABLES:
101cdf0e10cSrcweir             mrConnection.importWebPrTable( rStrm, nRecId );
102cdf0e10cSrcweir         break;
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir     return 0;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
onStartRecord(SequenceInputStream & rStrm)107cdf0e10cSrcweir void ConnectionContext::onStartRecord( SequenceInputStream& rStrm )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     if( getCurrentElement() == BIFF12_ID_CONNECTION )
110cdf0e10cSrcweir         mrConnection.importConnection( rStrm );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // ============================================================================
114cdf0e10cSrcweir 
ConnectionsFragment(const WorkbookHelper & rHelper,const OUString & rFragmentPath)115cdf0e10cSrcweir ConnectionsFragment::ConnectionsFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
116cdf0e10cSrcweir     WorkbookFragmentBase( rHelper, rFragmentPath )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
onCreateContext(sal_Int32 nElement,const AttributeList &)120cdf0e10cSrcweir ContextHandlerRef ConnectionsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     switch( getCurrentElement() )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         case XML_ROOT_CONTEXT:
125cdf0e10cSrcweir             if( nElement == XLS_TOKEN( connections ) )
126cdf0e10cSrcweir                 return this;
127cdf0e10cSrcweir         break;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         case XLS_TOKEN( connections ):
130cdf0e10cSrcweir             if( nElement == XLS_TOKEN( connection ) )
131cdf0e10cSrcweir                 return new ConnectionContext( *this, getConnections().createConnection() );
132cdf0e10cSrcweir         break;
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir     return 0;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream &)137cdf0e10cSrcweir ContextHandlerRef ConnectionsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& /*rStrm*/ )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     switch( getCurrentElement() )
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         case XML_ROOT_CONTEXT:
142cdf0e10cSrcweir             if( nRecId == BIFF12_ID_CONNECTIONS )
143cdf0e10cSrcweir                 return this;
144cdf0e10cSrcweir         break;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         case BIFF12_ID_CONNECTIONS:
147cdf0e10cSrcweir             if( nRecId == BIFF12_ID_CONNECTION )
148cdf0e10cSrcweir                 return new ConnectionContext( *this, getConnections().createConnection() );
149cdf0e10cSrcweir         break;
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     return 0;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
getRecordInfos() const154cdf0e10cSrcweir const RecordInfo* ConnectionsFragment::getRecordInfos() const
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     static const RecordInfo spRecInfos[] =
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         { BIFF12_ID_CONNECTIONS,    BIFF12_ID_CONNECTIONS + 1   },
159cdf0e10cSrcweir         { BIFF12_ID_CONNECTION,     BIFF12_ID_CONNECTION + 1    },
160cdf0e10cSrcweir         { BIFF12_ID_WEBPR,          BIFF12_ID_WEBPR + 1         },
161cdf0e10cSrcweir         { BIFF12_ID_WEBPRTABLES,    BIFF12_ID_WEBPRTABLES + 1   },
162cdf0e10cSrcweir         { -1,                       -1                          }
163cdf0e10cSrcweir     };
164cdf0e10cSrcweir     return spRecInfos;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
finalizeImport()167cdf0e10cSrcweir void ConnectionsFragment::finalizeImport()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     getConnections().finalizeImport();
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir // ============================================================================
173cdf0e10cSrcweir 
174cdf0e10cSrcweir } // namespace xls
175cdf0e10cSrcweir } // namespace oox
176