Line data Source code
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 _IODETECT_HXX_
21 : #define _IODETECT_HXX_
22 :
23 : #include <sfx2/docfilt.hxx>
24 : #include <sfx2/docfile.hxx>
25 : #include <sfx2/fcontnr.hxx>
26 : #include <osl/endian.h>
27 : #include <tools/string.hxx>
28 : #include <swddllapi.h>
29 :
30 : #define FILTER_RTF "RTF" ///< RTF filter
31 : #define sRtfWH "WH_RTF"
32 : #define FILTER_TEXT "TEXT" ///< text filter with default codeset
33 : #define FILTER_BAS "BAS" ///< StarBasic (identical to ANSI)
34 : #define FILTER_WW8 "CWW8" ///< WinWord 97 filter
35 : #define FILTER_TEXT_DLG "TEXT_DLG" ///< text filter with encoding dialog
36 : #define FILTER_XML "CXML" ///< XML filter
37 : #define FILTER_XMLV "CXMLV" ///< XML filter
38 : #define FILTER_XMLVW "CXMLVWEB" ///< XML filter
39 : #define sHTML "HTML"
40 : #define sWW1 "WW1"
41 : #define sWW5 "WW6"
42 : #define sWW6 "CWW6"
43 :
44 : #define sSWRITER "swriter"
45 : #define sSWRITERWEB "swriter/web"
46 :
47 : struct SwIoDetect
48 : {
49 : const sal_Char* pName;
50 : sal_uInt16 nLen;
51 :
52 374 : inline SwIoDetect( const sal_Char *pN, sal_uInt16 nL )
53 374 : : pName( pN ), nLen( nL )
54 374 : {}
55 :
56 57474 : inline int IsFilter( const String& rNm ) const
57 : {
58 57474 : return pName && rNm.EqualsAscii( pName, 0, nLen );
59 : }
60 :
61 : const sal_Char* IsReader( const sal_Char* pHeader, sal_uLong nLen_,
62 : const String &rFileName, const String& rUserData ) const;
63 : };
64 :
65 : enum ReaderWriterEnum {
66 : READER_WRITER_RTF,
67 : READER_WRITER_BAS,
68 : READER_WRITER_WW6,
69 : READER_WRITER_WW8,
70 : READER_WRITER_RTF_WH,
71 : READER_WRITER_HTML,
72 : READER_WRITER_WW1,
73 : READER_WRITER_WW5,
74 : READER_WRITER_XML,
75 : READER_WRITER_TEXT_DLG,
76 : READER_WRITER_TEXT,
77 : MAXFILTER
78 : };
79 :
80 : extern SWD_DLLPUBLIC SwIoDetect aFilterDetect[];
81 :
82 : /** The following class is a wrapper for basic i/o functions of Writer 3.0.
83 : Everything is static. All filter names mentioned are Writer-internal
84 : names, i.e. the names in front of the equality sign in INSTALL.INI, like SWG
85 : or ASCII.*/
86 :
87 : class SwIoSystem
88 : {
89 : public:
90 : /// find for an internal format name the corresponding filter entry
91 : SWD_DLLPUBLIC static const SfxFilter*
92 : GetFilterOfFormat( const String& rFormat,
93 : const SfxFilterContainer* pCnt = 0 );
94 :
95 : /** Detect for the given file which filter should be used. The filter name
96 : is returned. If no filter could be found, the name of the ASCII filter
97 : is returned! */
98 : SWD_DLLPUBLIC static const SfxFilter*
99 : GetFileFilter( const String& rFileName,
100 : const String& rPrefFltName,
101 : SfxMedium* pMedium = 0 );
102 :
103 : /** Detect whether the given file is in the given format.
104 : For now, only our own filters are supported! */
105 : static sal_Bool IsFileFilter(SfxMedium& rMedium, const String& rFmtName);
106 :
107 : static sal_Bool IsValidStgFilter( SotStorage& , const SfxFilter& );
108 : static sal_Bool IsValidStgFilter( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const SfxFilter& rFilter);
109 :
110 : SWD_DLLPUBLIC static bool
111 : IsDetectableText( const sal_Char* pBuf, sal_uLong &rLen,
112 : CharSet *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0, bool bEncodedFilter = false );
113 :
114 : static const SfxFilter* GetTextFilter( const sal_Char* pBuf, sal_uLong nLen );
115 :
116 : SWD_DLLPUBLIC static const String
117 : GetSubStorageName( const SfxFilter& rFltr );
118 : };
119 :
120 : #endif
121 :
122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|