diff options
Diffstat (limited to 'src/lib/SW602Document.cpp')
-rw-r--r-- | src/lib/SW602Document.cpp | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/lib/SW602Document.cpp b/src/lib/SW602Document.cpp new file mode 100644 index 0000000..2be0e20 --- /dev/null +++ b/src/lib/SW602Document.cpp @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * This file is part of the libsw602 project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <libsw602/SW602Document.h> + +#include <boost/shared_ptr.hpp> + +#include <librevenge-stream/librevenge-stream.h> + +#include "WinText602Header.h" +#include "WinText602Parser.h" + +using boost::shared_ptr; + +using librevenge::RVNGInputStream; + +using std::string; + +namespace libsw602 +{ + +namespace +{ + +shared_ptr<RVNGInputStream> getContent(librevenge::RVNGInputStream *const ip) +{ + const shared_ptr<RVNGInputStream> input(ip, SW602_shared_ptr_noop_deleter<librevenge::RVNGInputStream>()); + + shared_ptr<RVNGInputStream> strm; + if (input->isStructured()) + strm.reset(input->getSubStreamByName("CONTENTS")); + + return strm; +} + +} + +SW602Document::Confidence SW602Document::isSupported(librevenge::RVNGInputStream *const input, Kind &kind, Type *const type, bool *const needsEncoding) try +{ + if (!input) + return CONFIDENCE_NONE; + + shared_ptr<RVNGInputStream> content = getContent(input); + if (bool(content)) + { + content->seek(0, librevenge::RVNG_SEEK_SET); + WinText602Header header(*content); + // TODO: handle encryption + if (header.isValid()) + { + kind = KIND_TEXT; + if (type) + *type = TYPE_WINTEXT602; + if (needsEncoding) + *needsEncoding = false; + return CONFIDENCE_EXCELLENT; + } + } + + return CONFIDENCE_NONE; +} +catch (...) +{ + return CONFIDENCE_NONE; +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const char *const password) +{ + return parse(input, document, TYPE_UNKNOWN, ENCODING_UNSPECIFIED, password); +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const Type type, const char *const password) +{ + return parse(input, document, type, ENCODING_UNSPECIFIED, password); +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const Encoding encoding, const char *const password) +{ + return parse(input, document, TYPE_UNKNOWN, encoding, password); +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, Type type, Encoding /*encoding*/, const char * /*password*/) try +{ + if (!document) + return RESULT_OK; + if (!input) + return RESULT_PARSE_ERROR; + + if (type == TYPE_UNKNOWN) + { + Kind kind = KIND_UNKNOWN; + const Confidence confidence = SW602Document::isSupported(input, kind, &type); + if ((kind != KIND_TEXT) || ((confidence != CONFIDENCE_EXCELLENT) && (confidence != CONFIDENCE_SUPPORTED_ENCRYPTION))) + return RESULT_UNSUPPORTED_FORMAT; + } + + switch (type) + { + case TYPE_WINTEXT602: + { + shared_ptr<RVNGInputStream> content = getContent(input); + if (bool(content)) + { + content->seek(0, librevenge::RVNG_SEEK_SET); + WinText602Parser parser(content); + parser.parse(document); + return RESULT_OK; + } + break; + } + default: + return RESULT_UNSUPPORTED_FORMAT; + } + + return RESULT_UNKNOWN_ERROR; +} +catch (...) +{ + return RESULT_UNKNOWN_ERROR; +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *document, const char *password) +{ + return parse(input, document, TYPE_UNKNOWN, ENCODING_UNSPECIFIED, password); +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *document, Type type, const char *password) +{ + return parse(input, document, type, ENCODING_UNSPECIFIED, password); +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *document, Encoding encoding, const char *password) +{ + return parse(input, document, TYPE_UNKNOWN, encoding, password); +} + +SW602Document::Result SW602Document::parse(librevenge::RVNGInputStream * /*input*/, librevenge::RVNGSpreadsheetInterface * /*document*/, Type /*type*/, Encoding /*encoding*/, const char * /*password*/) try +{ + // TODO: implement me + return RESULT_UNKNOWN_ERROR; +} +catch (...) +{ + return RESULT_UNKNOWN_ERROR; +} + +} // namespace libsw602 + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |