xref: /aoo41x/main/sw/inc/iodetect.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _IODETECT_HXX_
29 #define _IODETECT_HXX_
30 
31 #include <sfx2/docfilt.hxx>
32 #include <sfx2/docfile.hxx>
33 #include <sfx2/fcontnr.hxx>
34 #include <osl/endian.h>
35 #include <errhdl.hxx>		// for ASSERT
36 #include <tools/string.hxx>
37 #include <swdllapi.h>
38 
39 #define FILTER_RTF      "RTF"       // RTF-Filter
40 #define sRtfWH          "WH_RTF"
41 #define FILTER_TEXT     "TEXT"      // Text-Filter mit Default-CodeSet
42 #define FILTER_BAS      "BAS"       // StarBasic (identisch mit ANSI)
43 #define FILTER_WW8      "CWW8"      // WinWord 97-Filter
44 #define FILTER_TEXT_DLG "TEXT_DLG"  // text filter with encoding dialog
45 #define FILTER_XML      "CXML"      // XML filter
46 #define FILTER_XMLV     "CXMLV"     // XML filter
47 #define FILTER_XMLVW    "CXMLVWEB"  // XML filter
48 #define sHTML           "HTML"
49 #define sWW1            "WW1"
50 #define sWW5            "WW6"
51 #define sWW6            "CWW6"
52 
53 #define sSWRITER        "swriter"
54 #define sSWRITERWEB     "swriter/web"
55 
56 struct SwIoDetect
57 {
58     const sal_Char* pName;
59     sal_uInt16 nLen;
60 
61     inline SwIoDetect( const sal_Char *pN, sal_uInt16 nL )
62         : pName( pN ), nLen( nL )
63     {}
64 
65     inline int IsFilter( const String& rNm ) const
66     {
67         return pName && rNm.EqualsAscii( pName, 0, nLen );
68     }
69 
70     const sal_Char* IsReader( const sal_Char* pHeader, sal_uLong nLen_,
71             const String &rFileName, const String& rUserData ) const;
72 };
73 
74 enum ReaderWriterEnum {
75     READER_WRITER_RTF,
76     READER_WRITER_BAS,
77     READER_WRITER_WW6,
78     READER_WRITER_WW8,
79     READER_WRITER_RTF_WH,
80     READER_WRITER_HTML,
81     READER_WRITER_WW1,
82     READER_WRITER_WW5,
83     READER_WRITER_XML,
84     READER_WRITER_TEXT_DLG,
85     READER_WRITER_TEXT,
86     MAXFILTER
87 };
88 
89 extern SwIoDetect aFilterDetect[];
90 
91 // Die folgende Klasse ist ein Wrappe fuer die Basic-I/O-Funktionen
92 // des Writer 3.0. Alles ist statisch. Alle u.a. Filternamen sind die
93 // Writer-internen Namen, d.h. die namen, die in INSTALL.INI vor dem
94 // Gleichheitszeichen stehen, z.b. SWG oder ASCII.
95 
96 class SwIoSystem
97 {
98 public:
99     // suche ueber den internen FormatNamen den Filtereintrag
100     SW_DLLPUBLIC static const SfxFilter* GetFilterOfFormat( const String& rFormat,
101             const SfxFilterContainer* pCnt = 0 );
102 
103     // Feststellen des zu verwendenden Filters fuer die uebergebene
104     // Datei. Der Filtername wird zurueckgeliefert. Konnte kein Filter
105     // zurueckgeliefert werden, wird der Name des ASCII-Filters geliefert!
106     static const SfxFilter* GetFileFilter( const String& rFileName,
107             const String& rPrefFltName,
108             SfxMedium* pMedium = 0 );
109 
110     // Feststellen ob das File in dem vorgegebenen Format vorliegt.
111     // Z.z werden nur unsere eigene Filter unterstuetzt!!
112     static sal_Bool IsFileFilter( SfxMedium& rMedium, const String& rFmtName,
113             const SfxFilter** ppFlt = 0 );
114 
115     static sal_Bool IsValidStgFilter( SotStorage& , const SfxFilter& );
116     static sal_Bool IsValidStgFilter( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const SfxFilter& rFilter);
117 
118     static bool IsDetectableText( const sal_Char* pBuf, sal_uLong &rLen,
119             CharSet *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0, bool bEncodedFilter = false );
120     //    static bool IsDetectableW4W(const String& rFileName, const String& rUserData);
121 
122     static const SfxFilter* GetTextFilter( const sal_Char* pBuf, sal_uLong nLen );
123 
124     static const String GetSubStorageName( const SfxFilter& rFltr );
125 };
126 
127 #endif
128