/src/libreoffice/sw/inc/iodetect.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_SW_INC_IODETECT_HXX |
21 | | #define INCLUDED_SW_INC_IODETECT_HXX |
22 | | |
23 | | #include <memory> |
24 | | #include <string_view> |
25 | | #include <o3tl/string_view.hxx> |
26 | | #include <rtl/ustring.hxx> |
27 | | #include <tools/lineend.hxx> |
28 | | #include <utility> |
29 | | #include <tools/solar.h> |
30 | | #include "swdllapi.h" |
31 | | |
32 | | inline constexpr OUString FILTER_RTF = u"RTF"_ustr; ///< RTF filter |
33 | | inline constexpr OUString sRtfWH = u"WH_RTF"_ustr; |
34 | | inline constexpr OUString FILTER_TEXT = u"TEXT"_ustr; ///< text filter with default codeset |
35 | | inline constexpr OUString FILTER_BAS = u"BAS"_ustr; ///< StarBasic (identical to ANSI) |
36 | | inline constexpr OUString FILTER_WW8 = u"CWW8"_ustr; ///< WinWord 97 filter |
37 | | inline constexpr OUString FILTER_TEXT_DLG = u"TEXT_DLG"_ustr; ///< text filter with encoding dialog |
38 | | inline constexpr OUString FILTER_XML = u"CXML"_ustr; ///< XML filter |
39 | 0 | #define FILTER_XMLV "CXMLV" ///< XML filter |
40 | 0 | #define FILTER_XMLVW "CXMLVWEB" ///< XML filter |
41 | | inline constexpr OUString FILTER_DOCX = u"OXML"_ustr; |
42 | | inline constexpr OUString FILTER_MD = u"Markdown"_ustr; // markdown filter |
43 | | inline constexpr OUString sHTML = u"HTML"_ustr; |
44 | | inline constexpr OUString sWW5 = u"WW6"_ustr; |
45 | | inline constexpr OUString sWW6 = u"CWW6"_ustr; |
46 | | |
47 | | inline constexpr OUString sSWRITER = u"swriter"_ustr; |
48 | | inline constexpr OUString sSWRITERWEB = u"swriter/web"_ustr; |
49 | | |
50 | | class SfxFilter; |
51 | | class SfxFilterContainer; |
52 | | class SotStorage; |
53 | | class SvStream; |
54 | | namespace com::sun::star::embed { class XStorage; } |
55 | | namespace com::sun::star::uno { template <typename> class Reference; } |
56 | | |
57 | | struct SwIoDetect |
58 | | { |
59 | | const OUString sName; |
60 | | |
61 | | SwIoDetect(OUString aN) |
62 | 216 | : sName(std::move(aN)) |
63 | 216 | { |
64 | 216 | } |
65 | | |
66 | | bool IsFilter( std::u16string_view rNm ) const |
67 | 321k | { |
68 | 321k | return o3tl::starts_with(rNm, sName); |
69 | 321k | } |
70 | | }; |
71 | | |
72 | | enum ReaderWriterEnum { |
73 | | READER_WRITER_RTF, |
74 | | READER_WRITER_BAS, |
75 | | READER_WRITER_WW6, |
76 | | READER_WRITER_WW8, |
77 | | READER_WRITER_RTF_WH, |
78 | | READER_WRITER_HTML, |
79 | | READER_WRITER_WW5, |
80 | | READER_WRITER_XML, |
81 | | READER_WRITER_TEXT_DLG, |
82 | | READER_WRITER_TEXT, |
83 | | READER_WRITER_DOCX, |
84 | | READER_WRITER_MD, |
85 | | MAXFILTER |
86 | | }; |
87 | | |
88 | | extern SwIoDetect aFilterDetect[]; |
89 | | |
90 | | /** The following class is a wrapper for basic i/o functions of Writer 3.0. |
91 | | Everything is static. All filter names mentioned are Writer-internal |
92 | | names, i.e. the names in front of the equality sign in INSTALL.INI, like SWG |
93 | | or ASCII.*/ |
94 | | |
95 | | class SwIoSystem |
96 | | { |
97 | | public: |
98 | | /// find for an internal format name the corresponding filter entry |
99 | | SW_DLLPUBLIC static std::shared_ptr<const SfxFilter> |
100 | | GetFilterOfFormat( std::u16string_view rFormat, |
101 | | const SfxFilterContainer* pCnt = nullptr ); |
102 | | |
103 | | /** Detect for the given file which filter should be used. The filter name |
104 | | is returned. If no filter could be found, the name of the ASCII filter |
105 | | is returned! */ |
106 | | static std::shared_ptr<const SfxFilter> GetFileFilter(const OUString& rFileName); |
107 | | |
108 | | static bool IsValidStgFilter( SotStorage& , const SfxFilter& ); |
109 | | static bool IsValidStgFilter( const css::uno::Reference < css::embed::XStorage >& rStg, const SfxFilter& rFilter); |
110 | | |
111 | | // tdf#106899 - wrapper around IsDetectableText to retrieve the text encoding for a given stream |
112 | | SW_DLLPUBLIC static rtl_TextEncoding GetTextEncoding(SvStream&); |
113 | | static bool IsDetectableText( const char* pBuf, sal_uLong &rLen, |
114 | | rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool *pBom); |
115 | | |
116 | | static OUString GetSubStorageName( const SfxFilter& rFltr ); |
117 | | }; |
118 | | |
119 | | extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportFODT(SvStream &rStream); |
120 | | extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestPDFExportFODT(SvStream &rStream); |
121 | | |
122 | | #endif |
123 | | |
124 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |