xref: /aoo4110/main/sw/inc/iodetect.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _IODETECT_HXX_
25 #define _IODETECT_HXX_
26 
27 #include <sfx2/docfilt.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/fcontnr.hxx>
30 #include <osl/endian.h>
31 #include <errhdl.hxx>		// for ASSERT
32 #include <tools/string.hxx>
33 #include <swdllapi.h>
34 
35 #define FILTER_RTF      "RTF"       // RTF-Filter
36 #define sRtfWH          "WH_RTF"
37 #define FILTER_TEXT     "TEXT"      // Text-Filter mit Default-CodeSet
38 #define FILTER_BAS      "BAS"       // StarBasic (identisch mit ANSI)
39 #define FILTER_WW8      "CWW8"      // WinWord 97-Filter
40 #define FILTER_TEXT_DLG "TEXT_DLG"  // text filter with encoding dialog
41 #define FILTER_XML      "CXML"      // XML filter
42 #define FILTER_XMLV     "CXMLV"     // XML filter
43 #define FILTER_XMLVW    "CXMLVWEB"  // XML filter
44 #define sHTML           "HTML"
45 #define sWW1            "WW1"
46 #define sWW5            "WW6"
47 #define sWW6            "CWW6"
48 
49 #define sSWRITER        "swriter"
50 #define sSWRITERWEB     "swriter/web"
51 
52 struct SwIoDetect
53 {
54     const sal_Char* pName;
55     sal_uInt16 nLen;
56 
SwIoDetectSwIoDetect57     inline SwIoDetect( const sal_Char *pN, sal_uInt16 nL )
58         : pName( pN ), nLen( nL )
59     {}
60 
IsFilterSwIoDetect61     inline int IsFilter( const String& rNm ) const
62     {
63         return pName && rNm.EqualsAscii( pName, 0, nLen );
64     }
65 
66     const sal_Char* IsReader( const sal_Char* pHeader, sal_uLong nLen_,
67             const String &rFileName, const String& rUserData ) const;
68 };
69 
70 enum ReaderWriterEnum {
71     READER_WRITER_RTF,
72     READER_WRITER_BAS,
73     READER_WRITER_WW6,
74     READER_WRITER_WW8,
75     READER_WRITER_RTF_WH,
76     READER_WRITER_HTML,
77     READER_WRITER_WW1,
78     READER_WRITER_WW5,
79     READER_WRITER_XML,
80     READER_WRITER_TEXT_DLG,
81     READER_WRITER_TEXT,
82     MAXFILTER
83 };
84 
85 extern SwIoDetect aFilterDetect[];
86 
87 // Die folgende Klasse ist ein Wrappe fuer die Basic-I/O-Funktionen
88 // des Writer 3.0. Alles ist statisch. Alle u.a. Filternamen sind die
89 // Writer-internen Namen, d.h. die namen, die in INSTALL.INI vor dem
90 // Gleichheitszeichen stehen, z.b. SWG oder ASCII.
91 
92 class SwIoSystem
93 {
94 public:
95     // suche ueber den internen FormatNamen den Filtereintrag
96     SW_DLLPUBLIC static const SfxFilter* GetFilterOfFormat( const String& rFormat,
97             const SfxFilterContainer* pCnt = 0 );
98 
99     // Feststellen des zu verwendenden Filters fuer die uebergebene
100     // Datei. Der Filtername wird zurueckgeliefert. Konnte kein Filter
101     // zurueckgeliefert werden, wird der Name des ASCII-Filters geliefert!
102     static const SfxFilter* GetFileFilter( const String& rFileName,
103             const String& rPrefFltName,
104             SfxMedium* pMedium = 0 );
105 
106     // Feststellen ob das File in dem vorgegebenen Format vorliegt.
107     // Z.z werden nur unsere eigene Filter unterstuetzt!!
108     static sal_Bool IsFileFilter( SfxMedium& rMedium, const String& rFmtName,
109             const SfxFilter** ppFlt = 0 );
110 
111     static sal_Bool IsValidStgFilter( SotStorage& , const SfxFilter& );
112     static sal_Bool IsValidStgFilter( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const SfxFilter& rFilter);
113 
114     static bool IsDetectableText( const sal_Char* pBuf, sal_uLong &rLen,
115             CharSet *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0, bool bEncodedFilter = false );
116     //    static bool IsDetectableW4W(const String& rFileName, const String& rUserData);
117 
118     static const SfxFilter* GetTextFilter( const sal_Char* pBuf, sal_uLong nLen );
119 
120     static const String GetSubStorageName( const SfxFilter& rFltr );
121 };
122 
123 #endif
124