1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shellio.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/embed/XStorage.hpp>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/fcontnr.hxx>
37 #include <sot/formats.hxx>
38 #include <sot/storage.hxx>
39 #include <svtools/parhtml.hxx>
40 #include <tools/string.hxx>
41 #include <tools/date.hxx>
42 #include <tools/time.hxx>
43 #include <tools/datetime.hxx>
44 #include <tools/ref.hxx>
45 #include <tools/urlobj.hxx>
47 #include <swtypes.hxx>
48 #include <docfac.hxx> // SwDocFac
50 #include <iodetect.hxx>
52 // einige Forward - Deklarationen
53 class SfxFilterContainer
;
62 class SvxMacroTableDtor
;
72 // ab so vielen chars wird ein mit einem ASCII/W4W-Reader eingelesener
73 // Absatz zwangsweise umgebrochen. Muss immer groesser als 200 sein !!!
74 #define MAX_ASCII_PARA 10000
77 class SW_DLLPUBLIC SwAsciiOptions
80 rtl_TextEncoding eCharSet
;
86 const String
& GetFontName() const { return sFont
; }
87 void SetFontName( const String
& rFont
) { sFont
= rFont
; }
89 rtl_TextEncoding
GetCharSet() const { return eCharSet
; }
90 void SetCharSet( rtl_TextEncoding nVal
) { eCharSet
= nVal
; }
92 USHORT
GetLanguage() const { return nLanguage
; }
93 void SetLanguage( USHORT nVal
) { nLanguage
= nVal
; }
95 LineEnd
GetParaFlags() const { return eCRLF_Flag
; }
96 void SetParaFlags( LineEnd eVal
) { eCRLF_Flag
= eVal
; }
101 eCRLF_Flag
= GetSystemLineEnd();
102 eCharSet
= ::gsl_getSystemTextEncoding();
105 // for the automatic conversion (mail/news/...)
106 void ReadUserData( const String
& );
107 void WriteUserData( String
& );
109 SwAsciiOptions() { Reset(); }
112 /**************** SwReader/Reader ************************/
113 // Basisklasse der moeglichen Optionen fuer einen speziellen Reader
115 // Ruft den Reader mit seinen Optionen, Dokument, Cursor etc.
117 // SwRead ist der Pointer auf die Read-Optionen-Basisklasse
118 typedef Reader
*SwRead
;
120 class SwgReaderOption
122 SwAsciiOptions aASCIIOpts
;
137 void ResetAllFmtsOnly() { What
.bFmtsOnly
= 0; }
138 BOOL
IsFmtsOnly() const { return What
.bFmtsOnly
; }
140 BOOL
IsFrmFmts() const { return What
.Fmts
.bFrmFmts
; }
141 void SetFrmFmts( const BOOL bNew
) { What
.Fmts
.bFrmFmts
= bNew
; }
143 BOOL
IsPageDescs() const { return What
.Fmts
.bPageDescs
; }
144 void SetPageDescs( const BOOL bNew
) { What
.Fmts
.bPageDescs
= bNew
; }
146 BOOL
IsTxtFmts() const { return What
.Fmts
.bTxtFmts
; }
147 void SetTxtFmts( const BOOL bNew
) { What
.Fmts
.bTxtFmts
= bNew
; }
149 BOOL
IsNumRules() const { return What
.Fmts
.bNumRules
; }
150 void SetNumRules( const BOOL bNew
) { What
.Fmts
.bNumRules
= bNew
; }
152 BOOL
IsMerge() const { return What
.Fmts
.bMerge
; }
153 void SetMerge( const BOOL bNew
) { What
.Fmts
.bMerge
= bNew
; }
155 const SwAsciiOptions
& GetASCIIOpts() const { return aASCIIOpts
; }
156 void SetASCIIOpts( const SwAsciiOptions
& rOpts
) { aASCIIOpts
= rOpts
; }
157 void ResetASCIIOpts() { aASCIIOpts
.Reset(); }
160 { ResetAllFmtsOnly(); aASCIIOpts
.Reset(); }
163 class SwReader
: public SwDocFac
167 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
168 SfxMedium
* pMedium
; // wer ein Medium haben will (W4W)
176 * Initiales Einlesen. Dokument wird erst beim Read(..) angelegt.
177 * JP 25.04.95: oder falls es mitgegeben wird, in dieses.
178 * Sonderfall fuer Load mit Sw3Reader
180 //SwReader( SotStorage&, const String& rFilename, SwDoc *pDoc = 0 );
181 //SwReader( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&, const String& rFilename, SwDoc *pDoc = 0 );
182 SwReader( SfxMedium
&, const String
& rFilename
, SwDoc
*pDoc
= 0 );
184 * In ein existierendes Dokument einlesen, Dokument und
185 * Position im Dokument werden aus dem SwPaM uebernommen.
187 SwReader( SvStream
&, const String
& rFilename
, const String
& rBaseURL
, SwPaM
& );
188 //SwReader( SotStorage&, const String& rFilename, SwPaM& );
189 SwReader( SfxMedium
&, const String
& rFilename
, SwPaM
& );
190 SwReader( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, const String
& rFilename
, SwPaM
& );
193 * Nur SwReader::Read(...) ist die Export-Schnittstelle!!!
195 BOOL
NeedsPasswd( const Reader
& );
196 BOOL
CheckPasswd( const String
&, const Reader
& );
197 ULONG
Read( const Reader
& );
199 // ask for glossaries
200 BOOL
HasGlossaries( const Reader
& );
201 BOOL
ReadGlossaries( const Reader
&, SwTextBlocks
&, BOOL bSaveRelFiles
);
203 const String
& GetBaseURL() const { return sBaseURL
;}
206 void SetBaseURL( const String
& rURL
) { sBaseURL
= rURL
; }
212 /**************** SPEZIELLE Reader ************************/
214 // spezielle - Reader koennen beides sein !! (Excel, W4W, .. )
215 #define SW_STREAM_READER 1
216 #define SW_STORAGE_READER 2
218 class SW_DLLPUBLIC Reader
220 friend class SwReader
;
227 DateTime aChkDateTime
;
232 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
233 SfxMedium
* pMedium
; // wer ein Medium haben will (W4W)
235 SwgReaderOption aOpt
;
236 BOOL bInsertMode
: 1;
237 BOOL bTmplBrowseMode
: 1;
238 BOOL bReadUTF8
: 1; // Stream als UTF-8 interpretieren
240 BOOL bOrganizerMode
: 1;
241 BOOL bHasAskTemplateName
: 1;
242 BOOL bIgnoreHTMLComments
: 1;
244 virtual String
GetTemplateName() const;
250 virtual int GetReaderType();
251 SwgReaderOption
& GetReaderOpt() { return aOpt
; }
253 virtual void SetFltName( const String
& rFltNm
);
254 static void SetNoOutlineNum( SwDoc
& rDoc
);
256 // den Item-Set eines Frm-Formats an das alte Format anpassen
257 static void ResetFrmFmtAttrs( SfxItemSet
&rFrmSet
);
259 // die Rahmen-/Grafik-/OLE-Vorlagen an das alte Format (ohne
260 // Umrandung etc.) anpassen
261 static void ResetFrmFmts( SwDoc
& rDoc
);
263 // Die Filter-Vorlage laden, setzen und wieder freigeben
264 SwDoc
* GetTemplateDoc();
265 BOOL
SetTemplate( SwDoc
& rDoc
);
266 void ClearTemplate();
267 void SetTemplateName( const String
& rDir
);
268 void MakeHTMLDummyTemplateDoc();
270 BOOL
IsReadUTF8() const { return bReadUTF8
; }
271 void SetReadUTF8( BOOL bSet
) { bReadUTF8
= bSet
; }
273 BOOL
IsBlockMode() const { return bBlockMode
; }
274 void SetBlockMode( BOOL bSet
) { bBlockMode
= bSet
; }
276 BOOL
IsOrganizerMode() const { return bOrganizerMode
; }
277 void SetOrganizerMode( BOOL bSet
) { bOrganizerMode
= bSet
; }
279 void SetIgnoreHTMLComments( BOOL bSet
) { bIgnoreHTMLComments
= bSet
; }
281 virtual BOOL
HasGlossaries() const;
282 virtual BOOL
ReadGlossaries( SwTextBlocks
&, BOOL bSaveRelFiles
) const;
284 // read the sections of the document, which is equal to the medium.
285 // returns the count of it
286 virtual USHORT
GetSectionList( SfxMedium
& rMedium
,
287 SvStrings
& rStrings
) const;
289 SotStorageRef
getSotStorageRef() { return pStg
; };
290 void setSotStorageRef(SotStorageRef pStgRef
) { pStg
= pStgRef
; };
293 virtual ULONG
Read(SwDoc
&, const String
& rBaseURL
, SwPaM
&,const String
&)=0;
295 // alle die die Streams / Storages nicht geoeffnet brauchen,
296 // muessen die Methode ueberladen (W4W!!)
297 virtual int SetStrmStgPtr();
300 class AsciiReader
: public Reader
302 friend class SwReader
;
303 virtual ULONG
Read( SwDoc
&, const String
& rBaseURL
, SwPaM
&,const String
&);
305 AsciiReader(): Reader() {}
308 /*class SwgReader: public Reader
310 virtual ULONG Read( SwDoc &, const String& rBaseURL, SwPaM &,const String &);
313 class SW_DLLPUBLIC StgReader
: public Reader
318 ULONG
OpenMainStream( SotStorageStreamRef
& rRef
, USHORT
& rBuffSize
);
321 virtual int GetReaderType();
322 const String
& GetFltName() { return aFltName
; }
323 virtual void SetFltName( const String
& r
);
327 /*class Sw3Reader : public StgReader
330 virtual ULONG Read( SwDoc &, const String& rBaseURL, SwPaM &,const String &);
332 Sw3Reader() : pIO( 0 ) {}
334 void SetSw3Io( Sw3Io* pIo ) { pIO = pIo; }
336 // read the sections of the document, which is equal to the medium.
337 // returns the count of it
338 virtual USHORT GetSectionList( SfxMedium& rMedium,
339 SvStrings& rStrings ) const;
343 ////////////////////////////////////////////////////////////////////////////
345 // Der uebergebene Stream muss dynamisch angelegt werden und
346 // vor dem Loeschen der Instanz per Stream() angefordert
347 // und geloescht werden!
351 class SW_DLLPUBLIC SwTextBlocks
353 // friend class Sw2TextBlocks;
354 // friend class Sw3IoImp;
359 SwTextBlocks( const String
& );
365 void ClearDoc(); // Doc-Inhalt loeschen
366 const String
& GetName();
367 void SetName( const String
& );
368 ULONG
GetError() const { return nErr
; }
370 String
GetBaseURL() const;
371 void SetBaseURL( const String
& rURL
);
374 ULONG
ConvertToNew(); // Textbausteine konvertieren
376 USHORT
GetCount() const; // Anzahl Textbausteine ermitteln
377 USHORT
GetIndex( const String
& ) const; // Index fuer Kurznamen ermitteln
378 USHORT
GetLongIndex( const String
& ) const; //Index fuer Langnamen ermitteln
379 const String
& GetShortName( USHORT
) const; // Kurzname fuer Index zurueck
380 const String
& GetLongName( USHORT
) const; // Langname fuer Index zurueck
382 BOOL
Delete( USHORT
); // Loeschen
383 USHORT
Rename( USHORT
, const String
*, const String
* ); // Umbenennen
384 ULONG
CopyBlock( SwTextBlocks
& rSource
, String
& rSrcShort
,
385 const String
& rLong
); // Block kopieren
387 BOOL
BeginGetDoc( USHORT
); // Textbaustein einlesen
388 void EndGetDoc(); // Textbaustein wieder loslassen
390 BOOL
BeginPutDoc( const String
&, const String
& ); // Speichern Beginn
391 USHORT
PutDoc(); // Speichern Ende
393 USHORT
PutText( const String
&, const String
&, const String
& ); // Speichern( Kurzn., Text)
395 BOOL
IsOnlyTextBlock( USHORT
) const;
396 BOOL
IsOnlyTextBlock( const String
& rShort
) const;
398 const String
& GetFileName() const; // Dateiname von pImp
399 BOOL
IsReadOnly() const; // ReadOnly-Flag von pImp
401 BOOL
GetMacroTable( USHORT nIdx
, SvxMacroTableDtor
& rMacroTbl
);
402 BOOL
SetMacroTable( USHORT nIdx
, const SvxMacroTableDtor
& rMacroTbl
);
404 BOOL
StartPutMuchBlockEntries();
405 void EndPutMuchBlockEntries();
408 // BEGIN source/filter/basflt/fltini.cxx
410 extern void _InitFilter();
411 extern void _FinitFilter();
413 extern SwRead ReadAscii
, /*ReadSwg, ReadSw3, */ReadHTML
, ReadXML
;
415 //SW_DLLPUBLIC SwRead SwGetReaderSw3();
416 SW_DLLPUBLIC SwRead
SwGetReaderXML();
418 // END source/filter/basflt/fltini.cxx
421 extern BOOL
SetHTMLTemplate( SwDoc
&rDoc
); //Fuer Vorlagen aus HTML.vor laden shellio.cxx
425 /////////////////////////////////////////////////////////////////////////////
432 /* Basis-Klasse aller Writer */
434 class IDocumentSettingAccess
;
435 class IDocumentStylePoolAccess
;
437 class SW_DLLPUBLIC Writer
: public SvRefBase
439 SwAsciiOptions aAscOpts
;
442 void _AddFontItem( SfxItemPool
& rPool
, const SvxFontItem
& rFont
);
443 void _AddFontItems( SfxItemPool
& rPool
, USHORT nWhichId
);
449 SwPaM
* pOrigPam
; // der letze zu bearbeitende Pam
450 const String
* pOrigFileName
;
453 BOOL
CopyNextPam( SwPaM
** );
455 void PutNumFmtFontsInAttrPool();
456 void PutEditEngFontsInAttrPool( BOOL bIncl_CJK_CTL
= TRUE
);
457 void PutCJKandCTLFontsInAttrPool();
459 virtual ULONG
WriteStream() = 0;
460 void SetBaseURL( const String
& rURL
) { sBaseURL
= rURL
; }
462 IDocumentSettingAccess
* getIDocumentSettingAccess();
463 const IDocumentSettingAccess
* getIDocumentSettingAccess() const;
465 IDocumentStylePoolAccess
* getIDocumentStylePoolAccess();
466 const IDocumentStylePoolAccess
* getIDocumentStylePoolAccess() const;
472 BOOL bShowProgress
: 1;
473 BOOL bWriteClipboardDoc
: 1;
474 BOOL bWriteOnlyFirstTable
: 1;
475 BOOL bASCII_ParaAsCR
: 1;
476 BOOL bASCII_ParaAsBlanc
: 1;
477 BOOL bASCII_NoLastLineEnd
: 1;
478 BOOL bUCS2_WithStartChar
: 1;
479 BOOL bExportPargraphNumbering
: 1;
482 BOOL bOrganizerMode
: 1;
487 virtual ULONG
Write( SwPaM
&, SfxMedium
&, const String
* = 0 );
488 ULONG
Write( SwPaM
&, SvStream
&, const String
* = 0 );
489 virtual ULONG
Write( SwPaM
&, const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, const String
* = 0, SfxMedium
* = 0 );
490 virtual ULONG
Write( SwPaM
&, SotStorage
&, const String
* = 0 );
492 virtual void SetPasswd( const String
& );
493 virtual void SetVersion( const String
&, long );
494 virtual BOOL
IsStgWriter() const;
495 // virtual BOOL IsSw3Writer() const;
497 void SetShowProgress( BOOL bFlag
= FALSE
) { bShowProgress
= bFlag
; }
499 const String
* GetOrigFileName() const { return pOrigFileName
; }
501 const SwAsciiOptions
& GetAsciiOptions() const { return aAscOpts
; }
502 void SetAsciiOptions( const SwAsciiOptions
& rOpt
) { aAscOpts
= rOpt
; }
504 const String
& GetBaseURL() const { return sBaseURL
;}
506 // suche die naechste Bookmark-Position aus der Bookmark-Tabelle
507 sal_Int32
FindPos_Bkmk( const SwPosition
& rPos
) const;
508 // build a bookmark table, which is sort by the node position. The
509 // OtherPos of the bookmarks also inserted.
510 void CreateBookmarkTbl();
511 // search alle Bookmarks in the range and return it in the Array
512 USHORT
GetBookmarks( const SwCntntNode
& rNd
,
513 xub_StrLen nStt
, xub_StrLen nEnd
,
516 // lege einen neuen PaM an der Position an
517 static SwPaM
* NewSwPaM( SwDoc
& rDoc
, ULONG nStartIdx
, ULONG nEndIdx
,
518 BOOL bNodesArray
= TRUE
);
520 // kopiere ggfs. eine lokale Datei ins Internet
521 BOOL
CopyLocalFileToINet( String
& rFileNm
);
523 // Stream-spezifische Routinen, im Storage-Writer NICHT VERWENDEN!
525 // Optimierung der Ausgabe auf den Stream.
526 SvStream
& OutLong( SvStream
& rStrm
, long nVal
);
527 SvStream
& OutULong( SvStream
& rStrm
, ULONG nVal
);
529 // Hex-Zahl ausgeben, default ist 2.stellige Zahl
530 SvStream
& OutHex( SvStream
& rStrm
, ULONG nHex
, BYTE nLen
= 2 );
531 // 4-st. Hex-Zahl ausgeben
532 inline SvStream
& OutHex4( SvStream
& rStrm
, USHORT nHex
)
533 { return OutHex( rStrm
, nHex
, 4 ); }
535 inline SvStream
& OutHex( USHORT nHex
, BYTE nLen
= 2 ) { return OutHex( Strm(), nHex
, nLen
); }
536 inline SvStream
& OutHex4( USHORT nHex
) { return OutHex( Strm(), nHex
, 4 ); }
537 inline SvStream
& OutLong( long nVal
) { return OutLong( Strm(), nVal
); }
538 inline SvStream
& OutULong( ULONG nVal
) { return OutULong( Strm(), nVal
); }
540 void SetStrm( SvStream
& rStrm
) { pStrm
= &rStrm
; }
542 SvStream
& Strm() { return *pStrm
; }
547 void SetOrganizerMode( BOOL bSet
) { bOrganizerMode
= bSet
; }
550 #ifndef SW_DECL_WRITER_DEFINED
551 #define SW_DECL_WRITER_DEFINED
556 // Basisklasse fuer alle Storage-Writer
557 class SW_DLLPUBLIC StgWriter
: public Writer
562 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
564 // Fehler beim Aufruf erzeugen
565 virtual ULONG
WriteStream();
566 virtual ULONG
WriteStorage() = 0;
567 virtual ULONG
WriteMedium( SfxMedium
& ) = 0;
572 StgWriter() : Writer() {}
574 virtual BOOL
IsStgWriter() const;
576 virtual ULONG
Write( SwPaM
&, const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, const String
* = 0, SfxMedium
* = 0 );
577 virtual ULONG
Write( SwPaM
&, SotStorage
&, const String
* = 0 );
579 SotStorage
& GetStorage() const { return *pStg
; }
582 /*class Sw3Writer : public StgWriter
587 virtual ULONG WriteStorage();
588 virtual ULONG WriteMedium( SfxMedium& );
591 Sw3Writer() : pIO( 0 ), bSaveAs( FALSE ) {}
593 virtual BOOL IsSw3Writer() const;
598 // Schnittstellenklasse fuer den allgemeinen Zugriff auf die
605 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
617 ULONG
Write( WriterRef
& rxWriter
, const String
* = 0);
619 SwWriter( SvStream
&, SwCrsrShell
&,BOOL bWriteAll
= FALSE
);
620 SwWriter( SvStream
&, SwDoc
& );
621 SwWriter( SvStream
&, SwPaM
&, BOOL bWriteAll
= FALSE
);
623 // SwWriter( SotStorage&, SwCrsrShell &,BOOL bWriteAll = FALSE );
624 SwWriter( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, SwDoc
& );
625 // SwWriter( SotStorage&, SwPaM&, BOOL bWriteAll = FALSE );
627 SwWriter( SfxMedium
&, SwCrsrShell
&,BOOL bWriteAll
= FALSE
);
628 SwWriter( SfxMedium
&, SwDoc
& );
629 // SwWriter( SfxMedium&, SwPaM&, BOOL bWriteAll = FALSE );
631 //const String& GetBaseURL() const { return sBaseURL;}
636 /////////////////////////////////////////////////////////////////////////////
638 typedef Reader
* (*FnGetReader
)();
639 typedef void (*FnGetWriter
)(const String
&, const String
& rBaseURL
, WriterRef
&);
641 struct SwReaderWriterEntry
644 FnGetReader fnGetReader
;
645 FnGetWriter fnGetWriter
;
648 SwReaderWriterEntry( const FnGetReader fnReader
, const FnGetWriter fnWriter
, BOOL bDel
)
649 : pReader( NULL
), fnGetReader( fnReader
), fnGetWriter( fnWriter
), bDelReader( bDel
)
652 /// Get access to the reader
655 /// Get access to the writer
656 void GetWriter( const String
& rNm
, const String
& rBaseURL
, WriterRef
& xWrt
) const;
659 namespace SwReaderWriter
661 /// Return reader based on ReaderWriterEnum
662 Reader
* GetReader( ReaderWriterEnum eReader
);
664 /// Return reader based on the name
665 Reader
* GetReader( const String
& rFltName
);
667 /// Return writer based on the name
668 void GetWriter( const String
& rFltName
, const String
& rBaseURL
, WriterRef
& xWrt
);
671 void GetRTFWriter( const String
&, const String
&, WriterRef
& );
672 void GetASCWriter( const String
&, const String
&, WriterRef
& );
673 //void GetSw3Writer( const String&, const String&, WriterRef& );
674 void GetHTMLWriter( const String
&, const String
&, WriterRef
& );
675 void GetXMLWriter( const String
&, const String
&, WriterRef
& );
676 void GetWW8Writer( const String
&, const String
&, WriterRef
& );