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 #include "oox/xls/connectionsfragment.hxx"
25 
26 #include "oox/helper/attributelist.hxx"
27 #include "oox/xls/biffhelper.hxx"
28 #include "oox/xls/connectionsbuffer.hxx"
29 
30 namespace oox {
31 namespace xls {
32 
33 // ============================================================================
34 
35 using namespace ::oox::core;
36 
37 using ::rtl::OUString;
38 
39 // ============================================================================
40 
ConnectionContext(WorkbookFragmentBase & rParent,Connection & rConnection)41 ConnectionContext::ConnectionContext( WorkbookFragmentBase& rParent, Connection& rConnection ) :
42     WorkbookContextBase( rParent ),
43     mrConnection( rConnection )
44 {
45 }
46 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)47 ContextHandlerRef ConnectionContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
48 {
49     switch( getCurrentElement() )
50     {
51         case XLS_TOKEN( connection ):
52             if( nElement == XLS_TOKEN( webPr ) )
53             {
54                 mrConnection.importWebPr( rAttribs );
55                 return this;
56             }
57         break;
58 
59         case XLS_TOKEN( webPr ):
60             if( nElement == XLS_TOKEN( tables ) )
61             {
62                 mrConnection.importTables( rAttribs );
63                 return this;
64             }
65         break;
66 
67         case XLS_TOKEN( tables ):
68             mrConnection.importTable( rAttribs, nElement );
69         break;
70     }
71     return 0;
72 }
73 
onStartElement(const AttributeList & rAttribs)74 void ConnectionContext::onStartElement( const AttributeList& rAttribs )
75 {
76     if( getCurrentElement() == XLS_TOKEN( connection ) )
77         mrConnection.importConnection( rAttribs );
78 }
79 
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream & rStrm)80 ContextHandlerRef ConnectionContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
81 {
82     switch( getCurrentElement() )
83     {
84         case BIFF12_ID_CONNECTION:
85             if( nRecId == BIFF12_ID_WEBPR )
86             {
87                 mrConnection.importWebPr( rStrm );
88                 return this;
89             }
90         break;
91 
92         case BIFF12_ID_WEBPR:
93             if( nRecId == BIFF12_ID_WEBPRTABLES )
94             {
95                 mrConnection.importWebPrTables( rStrm );
96                 return this;
97             }
98         break;
99 
100         case BIFF12_ID_WEBPRTABLES:
101             mrConnection.importWebPrTable( rStrm, nRecId );
102         break;
103     }
104     return 0;
105 }
106 
onStartRecord(SequenceInputStream & rStrm)107 void ConnectionContext::onStartRecord( SequenceInputStream& rStrm )
108 {
109     if( getCurrentElement() == BIFF12_ID_CONNECTION )
110         mrConnection.importConnection( rStrm );
111 }
112 
113 // ============================================================================
114 
ConnectionsFragment(const WorkbookHelper & rHelper,const OUString & rFragmentPath)115 ConnectionsFragment::ConnectionsFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
116     WorkbookFragmentBase( rHelper, rFragmentPath )
117 {
118 }
119 
onCreateContext(sal_Int32 nElement,const AttributeList &)120 ContextHandlerRef ConnectionsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
121 {
122     switch( getCurrentElement() )
123     {
124         case XML_ROOT_CONTEXT:
125             if( nElement == XLS_TOKEN( connections ) )
126                 return this;
127         break;
128 
129         case XLS_TOKEN( connections ):
130             if( nElement == XLS_TOKEN( connection ) )
131                 return new ConnectionContext( *this, getConnections().createConnection() );
132         break;
133     }
134     return 0;
135 }
136 
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream &)137 ContextHandlerRef ConnectionsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& /*rStrm*/ )
138 {
139     switch( getCurrentElement() )
140     {
141         case XML_ROOT_CONTEXT:
142             if( nRecId == BIFF12_ID_CONNECTIONS )
143                 return this;
144         break;
145 
146         case BIFF12_ID_CONNECTIONS:
147             if( nRecId == BIFF12_ID_CONNECTION )
148                 return new ConnectionContext( *this, getConnections().createConnection() );
149         break;
150     }
151     return 0;
152 }
153 
getRecordInfos() const154 const RecordInfo* ConnectionsFragment::getRecordInfos() const
155 {
156     static const RecordInfo spRecInfos[] =
157     {
158         { BIFF12_ID_CONNECTIONS,    BIFF12_ID_CONNECTIONS + 1   },
159         { BIFF12_ID_CONNECTION,     BIFF12_ID_CONNECTION + 1    },
160         { BIFF12_ID_WEBPR,          BIFF12_ID_WEBPR + 1         },
161         { BIFF12_ID_WEBPRTABLES,    BIFF12_ID_WEBPRTABLES + 1   },
162         { -1,                       -1                          }
163     };
164     return spRecInfos;
165 }
166 
finalizeImport()167 void ConnectionsFragment::finalizeImport()
168 {
169     getConnections().finalizeImport();
170 }
171 
172 // ============================================================================
173 
174 } // namespace xls
175 } // namespace oox
176