Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / oox / connectionsfragment.cxx
blob504c7ec5cbdcbada606e5bd269b6ccba8a4085fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "connectionsfragment.hxx"
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/token/namespaces.hxx>
24 #include <oox/token/tokens.hxx>
25 #include "biffhelper.hxx"
26 #include "connectionsbuffer.hxx"
28 namespace oox {
29 namespace xls {
31 using namespace ::oox::core;
33 ConnectionContext::ConnectionContext( WorkbookFragmentBase& rParent, Connection& rConnection ) :
34 WorkbookContextBase( rParent ),
35 mrConnection( rConnection )
39 ContextHandlerRef ConnectionContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
41 switch( getCurrentElement() )
43 case XLS_TOKEN( connection ):
44 if( nElement == XLS_TOKEN( webPr ) )
46 mrConnection.importWebPr( rAttribs );
47 return this;
49 break;
51 case XLS_TOKEN( webPr ):
52 if( nElement == XLS_TOKEN( tables ) )
54 mrConnection.importTables( rAttribs );
55 return this;
57 break;
59 case XLS_TOKEN( tables ):
60 mrConnection.importTable( rAttribs, nElement );
61 break;
63 return nullptr;
66 void ConnectionContext::onStartElement( const AttributeList& rAttribs )
68 if( getCurrentElement() == XLS_TOKEN( connection ) )
69 mrConnection.importConnection( rAttribs );
72 ContextHandlerRef ConnectionContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
74 switch( getCurrentElement() )
76 case BIFF12_ID_CONNECTION:
77 if( nRecId == BIFF12_ID_WEBPR )
79 mrConnection.importWebPr( rStrm );
80 return this;
82 break;
84 case BIFF12_ID_WEBPR:
85 if( nRecId == BIFF12_ID_WEBPRTABLES )
87 mrConnection.importWebPrTables( rStrm );
88 return this;
90 break;
92 case BIFF12_ID_WEBPRTABLES:
93 mrConnection.importWebPrTable( rStrm, nRecId );
94 break;
96 return nullptr;
99 void ConnectionContext::onStartRecord( SequenceInputStream& rStrm )
101 if( getCurrentElement() == BIFF12_ID_CONNECTION )
102 mrConnection.importConnection( rStrm );
105 ConnectionsFragment::ConnectionsFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
106 WorkbookFragmentBase( rHelper, rFragmentPath )
110 ContextHandlerRef ConnectionsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
112 switch( getCurrentElement() )
114 case XML_ROOT_CONTEXT:
115 if( nElement == XLS_TOKEN( connections ) )
116 return this;
117 break;
119 case XLS_TOKEN( connections ):
120 if( nElement == XLS_TOKEN( connection ) )
121 return new ConnectionContext( *this, getConnections().createConnection() );
122 break;
124 return nullptr;
127 ContextHandlerRef ConnectionsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& /*rStrm*/ )
129 switch( getCurrentElement() )
131 case XML_ROOT_CONTEXT:
132 if( nRecId == BIFF12_ID_CONNECTIONS )
133 return this;
134 break;
136 case BIFF12_ID_CONNECTIONS:
137 if( nRecId == BIFF12_ID_CONNECTION )
138 return new ConnectionContext( *this, getConnections().createConnection() );
139 break;
141 return nullptr;
144 const RecordInfo* ConnectionsFragment::getRecordInfos() const
146 static const RecordInfo spRecInfos[] =
148 { BIFF12_ID_CONNECTIONS, BIFF12_ID_CONNECTIONS + 1 },
149 { BIFF12_ID_CONNECTION, BIFF12_ID_CONNECTION + 1 },
150 { BIFF12_ID_WEBPR, BIFF12_ID_WEBPR + 1 },
151 { BIFF12_ID_WEBPRTABLES, BIFF12_ID_WEBPRTABLES + 1 },
152 { -1, -1 }
154 return spRecInfos;
157 void ConnectionsFragment::finalizeImport()
159 getConnections().finalizeImport();
162 } // namespace xls
163 } // namespace oox
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */