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 #ifndef OOX_XLS_EXTERNALLINKFRAGMENT_HXX
25 #define OOX_XLS_EXTERNALLINKFRAGMENT_HXX
26 
27 #include "oox/xls/excelhandlers.hxx"
28 #include "oox/xls/externallinkbuffer.hxx"
29 
30 namespace oox {
31 namespace xls {
32 
33 class ExternalLink;
34 
35 // ============================================================================
36 // ============================================================================
37 
38 /** This class implements importing the sheetData element in external sheets.
39 
40     The sheetData element embedded in the externalBook element contains cached
41     cells from externally linked sheets.
42  */
43 class ExternalSheetDataContext : public WorkbookContextBase
44 {
45 public:
46     explicit            ExternalSheetDataContext(
47                             WorkbookFragmentBase& rFragment,
48                             const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >& rxSheetCache );
49 
50 protected:
51     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
52     virtual void        onCharacters( const ::rtl::OUString& rChars );
53 
54     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
55 
56 private:
57     /** Imports cell settings from a c element. */
58     void                importCell( const AttributeList& rAttribs );
59 
60     /** Imports the EXTCELL_BLANK from the passed stream. */
61     void                importExtCellBlank( SequenceInputStream& rStrm );
62     /** Imports the EXTCELL_BOOL from the passed stream. */
63     void                importExtCellBool( SequenceInputStream& rStrm );
64     /** Imports the EXTCELL_DOUBLE from the passed stream. */
65     void                importExtCellDouble( SequenceInputStream& rStrm );
66     /** Imports the EXTCELL_ERROR from the passed stream. */
67     void                importExtCellError( SequenceInputStream& rStrm );
68     /** Imports the EXTCELL_STRING from the passed stream. */
69     void                importExtCellString( SequenceInputStream& rStrm );
70 
71     /** Sets the passed cell value to the current position in the sheet cache. */
72     void                setCellValue( const ::com::sun::star::uno::Any& rValue );
73 
74 private:
75     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >
76                         mxSheetCache;               /// The sheet cache used to store external cell values.
77     ::com::sun::star::table::CellAddress maCurrPos; /// Position of current cell.
78     sal_Int32           mnCurrType;                 /// Data type of current cell.
79 };
80 
81 // ============================================================================
82 
83 class ExternalLinkFragment : public WorkbookFragmentBase
84 {
85 public:
86     explicit            ExternalLinkFragment(
87                             const WorkbookHelper& rHelper,
88                             const ::rtl::OUString& rFragmentPath,
89                             ExternalLink& rExtLink );
90 
91 protected:
92     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
93     virtual void        onCharacters( const ::rtl::OUString& rChars );
94     virtual void        onEndElement();
95 
96     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
97 
98     virtual const ::oox::core::RecordInfo* getRecordInfos() const;
99 
100 private:
101     ::oox::core::ContextHandlerRef createSheetDataContext( sal_Int32 nSheetId );
102 
103 private:
104     ExternalLink&       mrExtLink;
105     ExternalNameRef     mxExtName;
106     ::rtl::OUString     maResultValue;
107     sal_Int32           mnResultType;
108 };
109 
110 // ============================================================================
111 // ============================================================================
112 
113 class BiffExternalSheetDataContext : public BiffWorkbookContextBase
114 {
115 public:
116     explicit            BiffExternalSheetDataContext( const WorkbookHelper& rHelper, bool bImportDefNames );
117     virtual             ~BiffExternalSheetDataContext();
118 
119     /** Tries to import a record related to external links and defined names. */
120     virtual void        importRecord( BiffInputStream& rStrm );
121 
122 private:
123     void                importExternSheet( BiffInputStream& rStrm );
124     void                importExternalBook( BiffInputStream& rStrm );
125     void                importExternalName( BiffInputStream& rStrm );
126     void                importXct( BiffInputStream& rStrm );
127     void                importCrn( BiffInputStream& rStrm );
128     void                importDefinedName( BiffInputStream& rStrm );
129 
130     /** Sets the passed cell value to the passed position in the sheet cache. */
131     void                setCellValue( const BinAddress& rBinAddr, const ::com::sun::star::uno::Any& rValue );
132 
133 private:
134     ExternalLinkRef     mxExtLink;              /// Current external link.
135     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >
136                         mxSheetCache;           /// The sheet cache used to store external cell values.
137     bool                mbImportDefNames;
138 };
139 
140 // ============================================================================
141 
142 class BiffExternalLinkFragment : public BiffWorkbookFragmentBase
143 {
144 public:
145     explicit            BiffExternalLinkFragment( const BiffWorkbookFragmentBase& rParent );
146 
147     /** Imports all records related to external links. */
148     virtual bool        importFragment();
149 };
150 
151 // ============================================================================
152 // ============================================================================
153 
154 } // namespace xls
155 } // namespace oox
156 
157 #endif
158