STOFFOLEParser.hxx Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

STOFFOLEParser.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libstaroffice
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 /*
35 * freely inspired from istorage :
36 * ------------------------------------------------------------
37 * Generic OLE Zones furnished with a copy of the file header
38 *
39 * Compound Storage (32 bit version)
40 * Storage implementation
41 *
42 * This file contains the compound file implementation
43 * of the storage interface.
44 *
45 * Copyright 1999 Francis Beaudet
46 * Copyright 1999 Sylvain St-Germain
47 * Copyright 1999 Thuy Nguyen
48 * Copyright 2005 Mike McCormack
49 *
50 * This library is free software; you can redistribute it and/or
51 * modify it under the terms of the GNU Lesser General Public
52 * License as published by the Free Software Foundation; either
53 * version 2.1 of the License, or (at your option) any later version.
54 *
55 * This library is distributed in the hope that it will be useful,
56 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
58 * Lesser General Public License for more details.
59 *
60 * ------------------------------------------------------------
61 */
62
63 #ifndef STOFF_OLE_PARSER_H
64 #define STOFF_OLE_PARSER_H
65
66 #include <string>
67 #include <vector>
68
69 #include <librevenge-stream/librevenge-stream.h>
70
71 #include <libstaroffice/STOFFDocument.hxx>
72
73 #include "libstaroffice_internal.hxx"
74 #include "STOFFPosition.hxx"
75
76 #include "STOFFDebug.hxx"
77
78 namespace STOFFOLEParserInternal
79 {
80 struct State;
81 }
82
86 class STOFFOLEParser
87 {
88 public:
89 struct OleDirectory;
90
92 STOFFOLEParser();
93
95 ~STOFFOLEParser();
96
99 bool parse(STOFFInputStreamPtr fileInput);
100
102 std::vector<shared_ptr<OleDirectory> > &getDirectoryList();
104 shared_ptr<OleDirectory> getDirectory(std::string const &dir);
105
107 struct OleContent {
109 OleContent(std::string const &dir, std::string const &base) :
110 m_dir(dir), m_base(base), m_isParsed(false), m_position(), m_imageData(), m_imageType("")
111 {
112 }
114 std::string getBaseName()
115 {
116 return m_base;
117 }
119 std::string getOleName() const
120 {
121 if (m_dir.empty()) return m_base;
122 return m_dir+"/"+m_base;
123 }
125 bool isParsed() const
126 {
127 return m_isParsed;
128 }
130 void setParsed(bool flag=true)
131 {
132 m_isParsed=flag;
133 }
135 STOFFPosition const &getPosition() const
136 {
137 return m_position;
138 }
140 void setPosition(STOFFPosition const &pos)
141 {
142 m_position=pos;
143 }
145 bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
146 {
147 if (m_imageData.empty()) {
148 data.clear();
149 type="";
150 return false;
151 }
152 data=m_imageData;
153 type=m_imageType;
154 return true;
155 }
157 void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
158 {
159 m_imageData=data;
160 m_imageType=type;
161 }
162 protected:
164 std::string m_dir;
166 std::string m_base;
168 bool m_isParsed;
170 STOFFPosition m_position;
172 librevenge::RVNGBinaryData m_imageData;
174 std::string m_imageType;
175 };
176
178 struct OleDirectory {
180 OleDirectory(STOFFInputStreamPtr input, std::string const &dir) : m_input(input), m_dir(dir), m_contentList(), m_kind(STOFFDocument::STOFF_K_UNKNOWN),
181 m_hasCompObj(false), m_clsName(""), m_clipName("") { }
183 void addNewBase(std::string const &base)
184 {
185 if (base=="CompObj")
186 m_hasCompObj=true;
187 else
188 m_contentList.push_back(OleContent(m_dir,base));
189 }
191 std::vector<std::string> getUnparsedOles() const
192 {
193 std::vector<std::string> res;
194 for (size_t i=0; i<m_contentList.size(); ++i) {
195 if (m_contentList[i].isParsed()) continue;
196 res.push_back(m_contentList[i].getOleName());
197 }
198 return res;
199 }
201 STOFFInputStreamPtr m_input;
203 std::string m_dir;
205 std::vector<OleContent> m_contentList;
207 STOFFDocument::Kind m_kind;
209 bool m_hasCompObj;
211 std::string m_clsName;
213 std::string m_clipName;
214 };
215
216 protected:
218 static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName,
219 libstoff::DebugFile &ascii);
220
222 static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName,
223 libstoff::DebugFile &ascii);
225 static bool readObjInfo(STOFFInputStreamPtr input, std::string const &oleName,
226 libstoff::DebugFile &ascii);
228 bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory);
229
231 static bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName);
235 static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content);
236
238 static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName);
242 static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content);
243
247 bool readContents(STOFFInputStreamPtr input, OleContent &content);
248
254 bool readCONTENTS(STOFFInputStreamPtr input, OleContent &content);
255
256 protected:
257 //
258 // data
259 //
260
262 shared_ptr<STOFFOLEParserInternal::State> m_state;
263 };
264
265 #endif
266 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFOLEParser::OleContent::getBaseName
std::string getBaseName()
returns the base name
Definition: STOFFOLEParser.hxx:114
STOFFInputStreamPtr
shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition: libstaroffice_internal.hxx:482
STOFFOLEParser
a class used to parse some basic oles Tries to read the different ole parts and stores their contents...
Definition: STOFFOLEParser.hxx:86
STOFFOLEParser::OleContent::m_imageType
std::string m_imageType
the image type ( if known)
Definition: STOFFOLEParser.hxx:174
libstoff::DebugFile
Definition: STOFFDebug.hxx:198
STOFFOLEParser::OleContent::getImageData
bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
returns the image data
Definition: STOFFOLEParser.hxx:145
STOFFOLEParser::OleContent::m_isParsed
bool m_isParsed
true if the data has been parsed
Definition: STOFFOLEParser.hxx:168
STOFFDocument
This class provides all the functions an application would need to parse StarOffice documents...
Definition: STOFFDocument.hxx:55
STOFFPosition.hxx
STOFFDebug.hxx
STOFFOLEParser::OleDirectory::m_kind
STOFFDocument::Kind m_kind
the ole kind
Definition: STOFFOLEParser.hxx:207
STOFFOLEParser::OleDirectory::m_input
STOFFInputStreamPtr m_input
the main input
Definition: STOFFOLEParser.hxx:201
STOFFOLEParser::OleContent::m_imageData
librevenge::RVNGBinaryData m_imageData
the image content ( if known )
Definition: STOFFOLEParser.hxx:172
STOFFOLEParser::OleContent::m_dir
std::string m_dir
the directory
Definition: STOFFOLEParser.hxx:164
STOFFOLEParser::OleDirectory::getUnparsedOles
std::vector< std::string > getUnparsedOles() const
returns the list of unknown ole
Definition: STOFFOLEParser.hxx:191
STOFFOLEParser::OleDirectory::OleDirectory
OleDirectory(STOFFInputStreamPtr input, std::string const &dir)
constructor
Definition: STOFFOLEParser.hxx:180
STOFFOLEParser::m_state
shared_ptr< STOFFOLEParserInternal::State > m_state
the class state
Definition: STOFFOLEParser.hxx:262
STOFFOLEParser::OleContent::m_position
STOFFPosition m_position
the image position (if known)
Definition: STOFFOLEParser.hxx:170
STOFFOLEParser::OleContent::OleContent
OleContent(std::string const &dir, std::string const &base)
constructor
Definition: STOFFOLEParser.hxx:109
STOFFOLEParser::OleDirectory::m_hasCompObj
bool m_hasCompObj
true if the directory contains a compobj object
Definition: STOFFOLEParser.hxx:209
STOFFOLEParserInternal
Low level: namespace used to define/store the data used by STOFFOLEParser.
Definition: STOFFOLEParser.cxx:93
STOFFOLEParser::OleDirectory::m_clipName
std::string m_clipName
the compobj clipname
Definition: STOFFOLEParser.hxx:213
STOFFOLEParser::OleContent::getOleName
std::string getOleName() const
returns the ole name
Definition: STOFFOLEParser.hxx:119
STOFFOLEParser::OleContent::setImageData
void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
sets the image data
Definition: STOFFOLEParser.hxx:157
STOFFOLEParser::OleContent::isParsed
bool isParsed() const
returns true if the object if parsed
Definition: STOFFOLEParser.hxx:125
libstaroffice_internal.hxx
STOFFOLEParser::OleDirectory::addNewBase
void addNewBase(std::string const &base)
add a new base file
Definition: STOFFOLEParser.hxx:183
STOFFOLEParser::OleDirectory::m_contentList
std::vector< OleContent > m_contentList
the list of base name
Definition: STOFFOLEParser.hxx:205
STOFFOLEParser::OleDirectory::m_dir
std::string m_dir
the dir name
Definition: STOFFOLEParser.hxx:203
STOFFOLEParser::OleContent
structure use to store an object content
Definition: STOFFOLEParser.hxx:107
STOFFDocument::Kind
Kind
an enum to define the kind of document
Definition: STOFFDocument.hxx:66
STOFFDocument.hxx
STOFFOLEParser::OleContent::getPosition
STOFFPosition const & getPosition() const
return the image position
Definition: STOFFOLEParser.hxx:135
STOFFOLEParser::OleContent::m_base
std::string m_base
the base name
Definition: STOFFOLEParser.hxx:166
STOFFOLEParser::OleContent::setPosition
void setPosition(STOFFPosition const &pos)
set the image position
Definition: STOFFOLEParser.hxx:140
STOFFOLEParser::OleContent::setParsed
void setParsed(bool flag=true)
sets the parsed flag
Definition: STOFFOLEParser.hxx:130
STOFFPosition
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: STOFFPosition.hxx:47
STOFFOLEParser::OleDirectory::m_clsName
std::string m_clsName
the compobj CLSname
Definition: STOFFOLEParser.hxx:211
STOFFOLEParser::OleDirectory
Internal: internal method to keep ole directory and their content.
Definition: STOFFOLEParser.hxx:178