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