summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/objstor.cxx
blob: e5adb4ef42f4fb9babb91bf7c4e1f17039173f02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
/*************************************************************************
 *
 *  $RCSfile: objstor.cxx,v $
 *
 *  $Revision: 1.52 $
 *
 *  last change: $Author: dv $ $Date: 2001-07-10 10:38:18 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SFXENUMITEM_HXX //autogen
#include <svtools/eitem.hxx>
#endif
#ifndef _SFXSTRITEM_HXX //autogen
#include <svtools/stritem.hxx>
#endif
#ifndef _SVSTOR_HXX //autogen
#include <so3/svstor.hxx>
#endif
#ifndef _EXTATTR_HXX //autogen
#include <svtools/extattr.hxx>
#endif
#ifndef _ZCODEC_HXX //autogen
#include <tools/zcodec.hxx>
#endif
#ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
#include <com/sun/star/frame/XStorable.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp>
#endif

#ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
#include <com/sun/star/document/XFilter.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
#include <com/sun/star/document/XImporter.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XEXPORTER_HPP_
#include <com/sun/star/document/XExporter.hpp>
#endif

#ifndef  _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
#include <com/sun/star/lang/XInitialization.hpp>
#endif

#ifndef  _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#endif
#ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#endif
#ifndef  _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#endif

#pragma hdrstop

#ifndef _SFXECODE_HXX
#include <svtools/sfxecode.hxx>
#endif

#ifndef _CPPUHELPER_WEAK_HXX_
#include <cppuhelper/weak.hxx>
#endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif

#ifndef _SO_CLSIDS_HXX
#include <so3/clsids.hxx>
#endif
#ifndef _CACHESTR_HXX
#include <tools/cachestr.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_ADDXMLTOSTORAGEOPTIONS_HXX
#include <svtools/addxmltostorageoptions.hxx>
#endif

#include <svtools/saveopt.hxx>
#include <svtools/useroptions.hxx>
#include <svtools/pathoptions.hxx>
#include <tools/urlobj.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/tempfile.hxx>

#include "objsh.hxx"
#include "childwin.hxx"
#include "sfxdir.hxx"
#include "request.hxx"
#include "sfxresid.hxx"
#include "docfile.hxx"
#include "fltfnc.hxx"
#include "docfilt.hxx"
#include "docinf.hxx"
#include "docfac.hxx"
#include "cfgmgr.hxx"
#include "objshimp.hxx"
#include "sfxtypes.hxx"
#include "appdata.hxx"
#include "doc.hrc"
#include "sfxsids.hrc"
#include "interno.hxx"
#include "module.hxx"
#include "dispatch.hxx"
#include "openflag.hxx"
#include "helper.hxx"
#include "dlgcont.hxx"
#include "filedlghelper.hxx"
#include "scriptcont.hxx"



#define S2BS(s) ByteString( s, RTL_TEXTENCODING_MS_1252 )


extern sal_uInt32 CheckPasswd_Impl( Window*, SfxItemPool&, SfxMedium* );


using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::uno;
using namespace ::rtl;
using namespace ::cppu;

//=========================================================================

sal_Bool ShallSetBaseURL_Impl( SfxMedium &rMed )
{
    SvtSaveOptions aOpt;
    sal_Bool bIsRemote = rMed.IsRemote();
    return  aOpt.IsSaveRelINet() && bIsRemote || aOpt.IsSaveRelFSys() && !bIsRemote;
}

//=========================================================================

sal_Bool SfxObjectShell::Save()
{
    if( SOFFICE_FILEFORMAT_60 <= GetStorage()->GetVersion() )
        return TRUE;
    else
        return SaveInfoAndConfig_Impl( GetMedium()->GetStorage() );
}

//--------------------------------------------------------------------------

sal_Bool SfxObjectShell::SaveAs( SvStorage* pNewStg )
{
    if( SOFFICE_FILEFORMAT_60 <= pNewStg->GetVersion() )
        return TRUE;
    else
        return SaveInfoAndConfig_Impl( pNewStg );
}

//-------------------------------------------------------------------------

sal_Bool GetPasswd_Impl( const SfxItemSet* pSet, String& rPasswd )
{
    const SfxPoolItem* pItem = NULL;
    if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_PASSWORD, sal_True, &pItem ) )
    {
        DBG_ASSERT( pItem->IsA( TYPE(SfxStringItem) ), "wrong item type" );
        rPasswd = ( (const SfxStringItem*)pItem )->GetValue();
        return sal_True;
    }
    return sal_False;
}

//-------------------------------------------------------------------------
sal_Bool SfxObjectShell::DoInitNew_Impl( const String& rName )

/*  [Beschreibung]
*/

{
    if ( rName.Len() )
    {
        ModifyBlocker_Impl aBlock( this );
        pMedium = new SfxMedium( rName, SFX_STREAM_READONLY_MAKECOPY, sal_False );
        if ( InitNew( pMedium->GetStorage() ) )
        {
            bIsTmp = !( pMedium->GetStorage() );
            if ( SFX_CREATE_MODE_EMBEDDED == eCreateMode )
                SetTitle( String( SfxResId( STR_NONAME ) ));
            return sal_True;
        }
        return sal_False;
    }
    else
        return DoInitNew(0);
}


sal_Bool SfxObjectShell::DoInitNew( SvStorage * pStor )

/*  [Beschreibung]

    Diese von SvPersist geerbte virtuelle Methode wird gerufen, um
    die SfxObjectShell-Instanz aus einem Storage (pStor != 0) bzw.
    (pStor == 0) ganz neu zu initialisieren.

    Wie alle Do...-Methoden liegt hier eine Steuerung vor, die eigentliche
    Implementierung erfolgt, indem die ebenfalls virtuellen Methode
    InitNew(SvStorate*) von der SfxObjectShell-Subclass implementiert wird.

    F"ur pStor == 0 wird ein die SfxObjectShell-Instanz mit einem leeren
    SfxMedium verbunden, sonst mit einem SfxMedium, welches auf den
    als Parameter "ubergeben SvStorage verweist.

    Erst nach InitNew() oder Load() ist das Objekt korrekt initialisiert.

    [R"uckgabewert]
    sal_True            Das Objekt wurde initialisiert.
    sal_False           Das Objekt konnte nicht initialisiert werden
*/

{
    ModifyBlocker_Impl aBlock( this );
    if ( pStor )
        pMedium = new SfxMedium( pStor );
    else
    {
        bIsTmp = sal_True;
        pMedium = new SfxMedium;
    }

    if ( InitNew( pStor ) )
    {
        if ( SFX_CREATE_MODE_EMBEDDED == eCreateMode )
            SetTitle( String( SfxResId( STR_NONAME ) ));
        return sal_True;
    }
    return sal_False;
}

//-------------------------------------------------------------------------

void SfxObjectShell::DoHandsOff()

/*  [Beschreibung]

    Diese von SvPersist geerbte virtuelle Methode wird gerufen, um
    das Objekt aufzufordern, den ihm zugeteilten SvStorage freizugeben,
    insbesondere Substorages und Streams zu schlie"sen.

    Als Do...-Methode liegt hier nur die Steuerung. Der Implementierer
    von Subclasses kann die ebenfalls virtuelle Methode HandsOff()
    implementieren, um seine Substorages und Streams zu schlie"sen.

    Nach dem Aufruf dieser Methode, ist dem Objekt kein SfxMedium mehr
    zugeordnet, bis SaveCompleted() durchlaufen ist.
*/

{
    const SfxFilter *pFilter = pMedium->GetFilter();
    if( !pFilter || pFilter->IsOwnFormat() || ( pFilter->GetFilterFlags() & SFX_FILTER_PACKED ) )
        HandsOff();

    // Force document library containers to release storage
    SotStorageRef xDummyStorage;
    SfxDialogLibraryContainer* pDialogCont = pImp->pDialogLibContainer;
    if( pDialogCont )
        pDialogCont->setStorage( xDummyStorage );

    SfxScriptLibraryContainer* pBasicCont = pImp->pBasicLibContainer;
    if( pBasicCont )
        pBasicCont->setStorage( xDummyStorage );

    pMedium->Close();
//  DELETEZ( pMedium );
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoLoad(
    const String& rFileName, StreamMode nStreamMode, StorageMode nStorageMode)
{
    // Es wird nur die IPersistStorage-Schnittstelle angeboten
    ModifyBlocker_Impl aBlock( this );
    SvStorageRef xStor = new SvStorage( rFileName, nStreamMode | STREAM_WRITE, nStorageMode );
    if( !xStor.Is() )
        xStor = new SvStorage( rFileName, nStreamMode, nStorageMode );

    if ( SVSTREAM_OK == xStor->GetError() )
    {
        SfxMedium* pMedium = new SfxMedium( xStor );
        pMedium->SetName( rFileName );
        pMedium->Init_Impl();

        // Muss !!!
        SetFileName( rFileName );

        if( DoLoad( pMedium ) )
        {
            if ( SFX_CREATE_MODE_EMBEDDED == eCreateMode )
                SetTitle( rFileName );
            return sal_True;
        }
    }
    return sal_False;
}


//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoLoad( SvStorage * pStor )

/*  [Beschreibung]

    Diese von SvPersist geerbte virtuelle Methode steuert das Laden
    des Objektes aus einem Storage. Dabei wird der SvStorage zun"achst
    in einem SfxMedium verpackt und SfxObjectShell::DoLoad(SfxMedium*)
    mit diesem gerufen.

    [R"uckgabewert]
    sal_True                Das Objekt wurde initialisiert.
    sal_False               Das Objekt konnte nicht initialisiert werden
*/

{
    pMedium = new SfxMedium( pStor );
    if ( DoLoad(pMedium) )
    {
        if ( SFX_CREATE_MODE_EMBEDDED == eCreateMode )
        {
            ModifyBlocker_Impl aBlock( this );
            // bei Embedded Objekten setzt sonst keiner den Namen
//            DBG_ASSERT( pStor->GetName().Len(),
//                        "StorageName hat Laenge Null" );
            SetTitle( pStor->GetName() );
        }
        return sal_True;
    }

    return sal_False;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoLoad( SfxMedium *pMed )

/*  [Beschreibung]

    Diese Methode steuert das Laden des Objektes aus dem von dem
    "ubergebenen SfxMedium beschriebenen Medium. Hinterher ist das Objekt
    mit diesem SfxMedium verbunden.

    Handelt es sich bei dem SfxMedium um einen Storage im eigenen Format,
    wird die virtuelle Methode SvPersit::Load(SvStorage*) gerufen, welche
    die Implementierer von Subclasses "uberladen m"ussen, um das Objekt
    aus einem eigenen Storage zu laden (=> Swapping m"oeglich).

    Handelt es sich bei dem SfxMedium um einen Storage in einem fremden
    Format, oder um ein Flat-File, dann wird die virtuelle Methode
    <SfxObjectShell::ConvertFrom(SfxMedium*)> gerufen, welche die
    Implementierer von Subclasses "uberladen m"ussen, um das Objekt
    aus dem SfxMedium zu konvertieren. W"ahrend der Bearbeitung ist
    das Objekt dann mit einem tempor"aren SvStorage verbunden.

    Erst nach InitNew() oder Load() ist das Objekt korrekt
    initialisiert.

    [R"uckgabewert]
    sal_True                Das Objekt wurde geladen.
    sal_False           Das Objekt konnte nicht geladen werden
*/

{
    SfxApplication *pSfxApp = SFX_APP();
    ModifyBlocker_Impl aBlock( this );

    if ( SFX_CREATE_MODE_EMBEDDED != eCreateMode )
        GetpApp()->ShowStatusText( SfxResId(STR_DOC_LOADING) );

    pMedium = pMed;
    sal_Bool bOk = sal_False;
    const SfxFilter* pFilter = pMed->GetFilter();
    SfxItemSet* pSet = pMedium->GetItemSet();
    if( !pImp->nEventId )
    {
        SFX_ITEMSET_ARG(
            pSet, pTemplateItem, SfxBoolItem,
            SID_TEMPLATE, sal_False);
#if SUPD < 635
        SFX_ITEMSET_ARG(
            pSet, pBrowsingItem, SfxBoolItem, SID_BROWSING, sal_False );
        SetActivateEvent_Impl(
            ( pTemplateItem && pTemplateItem->GetValue() )
            ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC,
            pBrowsingItem && pBrowsingItem->GetValue() );
#else
        SetActivateEvent_Impl(
            ( pTemplateItem && pTemplateItem->GetValue() )
            ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
#endif
    }


    SFX_ITEMSET_ARG( pSet, pBaseItem, SfxStringItem,
                     SID_BASEURL, sal_False);
    String aBaseURL;
    if( pBaseItem ) aBaseURL = pBaseItem->GetValue();
    else
    {
        SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
        if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
        {
            aBaseURL = INetURLObject::GetBaseURL();
            SetBaseURL( aBaseURL );
        }
        else if ( pSalvageItem )
        {
            String aName( pMed->GetPhysicalName() );
            ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aBaseURL );
        }
        else
            aBaseURL = pMed->GetName();
    }

    SfxApplication* pApp = SFX_APP();
    pImp->nLoadedFlags = 0;
    sal_Bool bHasStorage = !pFilter || ( pFilter->IsOwnFormat() && pFilter->UsesStorage() );
    if ( !bHasStorage && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PACKED ) )
    {
        bHasStorage = pMed->TryStorage();
        if ( bHasStorage )
        {
            String aName( pMed->GetPhysicalName() );
            ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aBaseURL );
        }
    }

    if ( bHasStorage )
    {
        SvStorageRef xStor( pMed->GetStorage() );
        if( xStor.Is() && !xStor->GetError() && pMed->GetFilter()->GetVersion() < SOFFICE_FILEFORMAT_60 )
        {
            // Undoobjekte aufraeumen, muss vor dem eigentlichen Laden erfolgen
            SvEmbeddedObjectRef xThis = this;
            SvPersistRef xPer;
            if ( xThis.Is() )
                xPer = new SvEmbeddedObject;
            else
                xPer = new SvPersist;

            xPer->DoOwnerLoad(xStor);
            xPer->CleanUp();
            xPer->DoSave();
            xPer->DoSaveCompleted( 0 );
        }

        // Load
        const String aOldURL( INetURLObject::GetBaseURL() );
        if( aBaseURL.Len() ) INetURLObject::SetBaseURL( aBaseURL );
        pImp->nLoadedFlags = 0;
        bOk = xStor.Is() && LoadOwnFormat( *pMed );
        INetURLObject::SetBaseURL( aOldURL );

        if ( bOk )
        {
            GetDocInfo().Load(xStor);
            bHasName = sal_True;
        }
        else
            SetError( ERRCODE_ABORT );
    }
    else if ( InitNew(0) )
    {
        // Name vor ConvertFrom setzen, damit GetSbxObject() schon funktioniert
        bHasName = sal_True;
        SetName( SfxResId( STR_NONAME ) );

        // Importieren
        const String aOldURL( INetURLObject::GetBaseURL() );
        if( aBaseURL.Len() ) INetURLObject::SetBaseURL( aBaseURL );
        if( !pMedium->GetFilter()->UsesStorage() )
            pMedium->GetInStream();
        else
            pMedium->GetStorage();

        pImp->nLoadedFlags = 0;
        if ( pMedium->GetFilter() &&  ( pMedium->GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
        {
            bOk = ImportFrom(*pMedium);
        }
        else
        {
            bOk = ConvertFrom(*pMedium);
        }

        INetURLObject::SetBaseURL( aOldURL );

        if( bOk && pMedium->GetOpenMode() & STREAM_WRITE )
        //Medium offen halten um andere Zugriffe zu verhindern
        {
            if(pMedium->GetFilter() && pMedium->GetFilter()->UsesStorage())
                pMedium->GetStorage();
            else
                pMedium->GetInStream();
            if(pMedium->GetError())
                bOk = sal_False;
        }
    }

    if ( bOk )
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >  xModel ( GetModel(), ::com::sun::star::uno::UNO_QUERY );
        if ( xModel.is() )
        {
            ::rtl::OUString aURL = GetMedium()->GetOrigURL();
            SfxItemSet *pSet = GetMedium()->GetItemSet();
            ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
            TransformItems( SID_OPENDOC, *pSet, aArgs );
            xModel->attachResource( aURL, aArgs );
        }

        GetTitle( SFX_TITLE_DETECT );

        // Falls nicht asynchron geladen wird selbst FinishedLoading aufrufen
        if ( !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) &&
            ( !pMedium->GetFilter() ||
             pMedium->GetFilter()->UsesStorage() ||
             pMedium->GetInStream() && pMedium->GetInStream()->GetLockBytes() &&
             pMedium->GetInStream()->GetLockBytes()->IsSynchronMode() ) )
            FinishedLoading( SFX_LOADED_MAINDOCUMENT );

        if( IsOwnStorageFormat_Impl(*pMed) && pMed->GetFilter() )
        {
//???? dv           DirEntry aDirEntry( pMed->GetPhysicalName() );
//???? dv           SetFileName( aDirEntry.GetFull() );
        }
        Broadcast( SfxSimpleHint(SFX_HINT_NAMECHANGED) );
    }

    if( bOk )
    {
        String aFacName = String::CreateFromAscii( GetFactory().GetShortName() );
        if( ! aFacName.EqualsAscii( "swriter" ) &&
            ! aFacName.EqualsAscii( "FrameSet" ) &&
            ! aFacName.EqualsAscii( "swriter/web" ) )
        {
#ifdef DBG_UTIL
            if( pImp->nLoadedFlags != SFX_LOADED_ALL )
            {
                ByteString aError( U2S( aFacName ) );
                aError += " hat uralte Mussaenderung nicht gemacht. TLX fragen";
                DBG_ERROR( aError.GetBuffer() );
            }
#endif
            FinishedLoading( SFX_LOADED_ALL );
        }
    }

    if ( SFX_CREATE_MODE_EMBEDDED != eCreateMode )
        GetpApp()->HideStatusText();
    return bOk;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::IsOwnStorageFormat_Impl(const SfxMedium &rMedium) const
{
    return !rMedium.GetFilter() || // Embedded
           ( rMedium.GetFilter()->IsOwnFormat() &&
             rMedium.GetFilter()->UsesStorage() );
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoSave()
// DoSave wird nur noch ueber OLE aufgerufen. Sichern eigener Dokumente im SFX
// laeuft uber DoSave_Impl, um das Anlegen von Backups zu ermoeglichen.
// Save in eigenes Format jetzt auch wieder Hierueber
{
    sal_Bool bOk = sal_False ;
    {
        ModifyBlocker_Impl aBlock( this );
        SfxForceLinkTimer_Impl aFLT( this );
        pImp->bIsSaving = sal_True;
        String aPasswd;
        if ( IsOwnStorageFormat_Impl( *GetMedium() ) &&
             GetPasswd_Impl( GetMedium()->GetItemSet(), aPasswd ) )
            GetMedium()->GetStorage()->SetKey( S2BS( aPasswd ) );   //!!! (pb) needs new implementation
        GetStorage()->SetVersion( GetMedium()->GetFilter()->GetVersion() );
        bOk = Save();
    }

//#88046
//    if ( bOk )
//        SetModified( sal_False );
    return bOk;
}

void Lock_Impl( SfxObjectShell* pDoc, BOOL bLock )
{
    SfxViewFrame *pFrame= SfxViewFrame::GetFirst( pDoc );
    while ( pFrame )
    {
        pFrame->GetDispatcher()->Lock( bLock );
        pFrame->Enable( !bLock );
        pFrame = SfxViewFrame::GetNext( *pFrame, pDoc );
    }

}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::SaveTo_Impl
(
     SfxMedium &rMedium, // Medium, in das gespeichert werden soll
     const SfxItemSet* pSet,
     BOOL bPrepareForDirectAccess
)

/*  [Beschreibung]

    Schreibt den aktuellen Inhalt in das Medium rMedium.
    Ist das Zielmedium kein Storage, so wird ueber ein temporaeres
    Medium gespeichert, sonst direkt, da das Medium transacted
    geschaltet ist, wenn wir es selbst geoeffnet haben und falls wir
    Server sind entweder der Container einen transacted Storage zur
    Verfuegung stellt oder selbst einen temporaeren Storage erzeugt hat.
*/

{
    SfxForceLinkTimer_Impl aFLT( this );
    EnableSetModified( FALSE );

    const SfxFilter *pFilter = rMedium.GetFilter();
    if ( !pFilter )
    {
        // if no filter was set, use the default filter
        // this should be changed in the feature, it should be an error!
        pFilter = GetFactory().GetFilter(0);
        rMedium.SetFilter(pFilter);
    }

    if( pFilter->UsesStorage() )
        // create an output storage in the correct format
        rMedium.GetOutputStorage( SOFFICE_FILEFORMAT_60 <= pFilter->GetVersion() );
    else
        rMedium.GetOutStream();

    if( rMedium.GetErrorCode() )
        return sal_False;

    sal_Bool bOldStat = pImp->bForbidReload;
    pImp->bForbidReload = sal_True;

    // lock user interface while saving the document
    Lock_Impl( this, TRUE );

    sal_Bool bOk = sal_False;
    if( IsOwnStorageFormat_Impl(rMedium) )
    {
        SvStorageRef aMedRef = rMedium.GetStorage();
        if ( !aMedRef.Is() )
        {
            // no saving without storage, unlock UI and return
            Lock_Impl( this, FALSE );
            return sal_False;
        }

        // transfer password from the parameters to the storage
        String aPasswd;
        if ( GetPasswd_Impl( rMedium.GetItemSet(), aPasswd ) )
            aMedRef->SetKey( S2BS( aPasswd ) ); //!!! (pb) needs new implementation

        const SfxFilter* pFilter = rMedium.GetFilter();
        if(  ((SvStorage *)aMedRef) == ((SvStorage *)GetStorage() ) )
        {
            // target storage and object storage are identical, should never happen here
            DBG_ERROR( "Saving storage without copy!");
            aMedRef->SetVersion( pFilter->GetVersion() );
            bOk = Save();
        }
        else
            // save to target
            bOk = SaveAsOwnFormat( rMedium );

        // look for a "version" parameter
        const SfxStringItem *pVersionItem = pSet ? (const SfxStringItem*)
            SfxRequest::GetItem( pSet, SID_VERSION, sal_False, TYPE(SfxStringItem) ) : NULL;

        if ( pVersionItem )
        {
            // store a version also
            const SfxStringItem *pAuthorItem = pSet ? (const SfxStringItem*)
                SfxRequest::GetItem( pSet, SID_DOCINFO_AUTHOR, sal_False, TYPE(SfxStringItem) ) : NULL;

            // version comment
            SfxVersionInfo aInfo;
            aInfo.aComment = pVersionItem->GetValue();

            // version author
            String aAuthor;
            if ( pAuthorItem )
                aAuthor = pAuthorItem->GetValue();
            else
                // if not transferred as a parameter, get it from user settings
                aAuthor = SvtUserOptions().GetFullName();

            // time stamp for version
            aInfo.aCreateStamp.SetName( aAuthor );

            // desired format for version information
            sal_Bool bUseXML = SOFFICE_FILEFORMAT_60 <= pFilter->GetVersion();

            // get storage for version streams
            SvStorageRef xVersion = bUseXML ?
                    aMedRef->OpenUCBStorage( DEFINE_CONST_UNICODE( "Versions" ) ) :
                    aMedRef->OpenStorage( DEFINE_CONST_UNICODE( "Versions" ) );

            // all preliminary saved versions must be copied from the object storage to the the target storage
            SvStorageRef xOldVersions = GetStorage()->OpenStorage( DEFINE_CONST_UNICODE( "Versions" ), SFX_STREAM_READONLY | STREAM_NOCREATE);
            if ( xOldVersions.Is() && xOldVersions->GetError() == SVSTREAM_OK )
            {
                const SfxVersionTableDtor *pList = rMedium.GetVersionList();
                sal_uInt32 n=0;
                SfxVersionInfo* pInfo = pList->GetObject(n++);
                while( pInfo )
                {
                    const String& rName = pInfo->aName;
                    if ( xOldVersions->IsContained( rName ) )
                        xOldVersions->CopyTo( rName, xVersion, rName );
                    pInfo = pList->GetObject(n++);
                }
            }

            // add new version information into the versionlist and save the versionlist
            // the version list must have been transferred from the "old" medium before
            rMedium.AddVersion_Impl( aInfo );
            rMedium.SaveVersionList_Impl( bUseXML );

            ::utl::TempFile aTmpFile;
            aTmpFile.EnableKillingFile( TRUE );
            SvStorageRef xTmp = new SvStorage( ( SOFFICE_FILEFORMAT_60 <= pFilter->GetVersion() ), aTmpFile.GetURL() );

            // save the new version to the storage, perhaps also with password if the root storage is password protected
            if ( aPasswd.Len() )
                xTmp->SetKey( S2BS( aPasswd ) ); //!!! (pb) needs new implementation

            // save again, now as a version, use the target medium as a transport medium
            // this should be changed in the future, using a different medium seems to be better
            rMedium.SetStorage_Impl( xTmp );
            bOk = SaveAsOwnFormat( rMedium );
            xTmp->Commit();

            // reconnect medium to "old" storage
            rMedium.SetStorage_Impl( aMedRef );

            // close storage, it must be reopened as stream
            xTmp.Clear();

            // compress stream and store it into the root storage
            SvStorageStreamRef xStrm = xVersion->OpenStream( aInfo.aName );
            if ( SOFFICE_FILEFORMAT_60 <= pFilter->GetVersion() )
            {
                *xStrm << *aTmpFile.GetStream( STREAM_READ );
            }
            else
            {
                ZCodec aCodec;
                aCodec.BeginCompression( ZCODEC_BEST_COMPRESSION );
                aCodec.Compress( *aTmpFile.GetStream( STREAM_READ ), *xStrm );
                aCodec.EndCompression();
            }

            // commit the version storage
            xVersion->Commit();
        }
        else if ( pImp->bIsSaving )
        {
            // it's a "Save", not a "SaveAs"
            // so all preliminary saved versions must be copied from the object storage to the the target storage
            sal_Bool bUseXML = SOFFICE_FILEFORMAT_60 <= pFilter->GetVersion();

            // save the version list
            // the version list must have been transferred from the "old" medium before
            rMedium.SaveVersionList_Impl( bUseXML );
            const SfxVersionTableDtor *pList = rMedium.GetVersionList();
            if ( pList && pList->Count() )
            {
                // copy the version streams
                SvStorageRef xVersion = bUseXML ?
                    aMedRef->OpenUCBStorage( DEFINE_CONST_UNICODE( "Versions" ) ) :
                    aMedRef->OpenStorage( DEFINE_CONST_UNICODE( "Versions" ) );
                SvStorageRef xOldVersions = GetStorage()->OpenStorage( DEFINE_CONST_UNICODE( "Versions" ), SFX_STREAM_READONLY | STREAM_NOCREATE );
                if ( xOldVersions.Is() && xOldVersions->GetError() == SVSTREAM_OK )
                {
                    sal_uInt32 n=0;
                    SfxVersionInfo* pInfo = pList->GetObject(n++);
                    while( pInfo )
                    {
                        const String& rName = pInfo->aName;
                        if ( xOldVersions->IsContained( rName ) )
                            xOldVersions->CopyTo( rName, xVersion, rName );
                        pInfo = pList->GetObject(n++);
                    }
                }

                // commit the version storage
                xVersion->Commit();
            }
        }
    }
    else
    {
        // it's a "SaveAs" in an alien format
        if ( rMedium.GetFilter() && ( rMedium.GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
            bOk = ExportTo( rMedium, *pSet );
        else
            bOk = ConvertTo( rMedium );

        // after saving the document, the temporary object storage must be updated
        // if the old object storage was not a temporary one, it will be updated also, because it will be used
        // as a source for copying the objects into the new temporary storage that will be created below
        // updating means: all child objects must be stored into it
        // ( same as on loading, where these objects are copied to the temporary storage )
        // but don't commit these changes, because in the case when the old object storage is not a temporary one,
        // all changes will be written into the original file !
        if( bOk )
            bOk = SaveChilds() && SaveCompletedChilds( NULL );
    }

    // SetModified must be enabled when SaveCompleted is called, otherwise the modified flag of child objects will not be cleared
    EnableSetModified( TRUE );

    if( bOk )
    {
        // remember new object storage, if it is a temporary one, because we will need it for a "SaveCompleted" later
        SvStorageRef xNewTempRef;
        if ( bOk && bPrepareForDirectAccess )
        {
            sal_Bool bCopyTo = sal_False;
            SfxItemSet *pSet = rMedium.GetItemSet();
            if( pSet )
            {
                SFX_ITEMSET_ARG( pSet, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
                bCopyTo =   GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
                            pSaveToItem && pSaveToItem->GetValue();
            }

            // if the target medium is an alien format and the "old" medium was an own format, the object storage
            // must be exchanged, because now we need a new temporary storage as object storage
            BOOL bNeedsStorage = !bCopyTo && IsOwnStorageFormat_Impl(*pMedium) && !IsOwnStorageFormat_Impl(rMedium);
            if ( bNeedsStorage )
            {
                if( !pMedium->GetName().Len() )
                    // if the old object storage was a temporary one too, we can continue with it
                    xNewTempRef = GetStorage();
                else
                {
                    // copy storage of old medium to new temporary storage and take this over
                    if( ConnectTmpStorage_Impl( pMedium->GetStorage() ) )
                        xNewTempRef = GetStorage();
                    else
                        bOk = sal_False;
                }
            }

            // When the new medium ( rMedium ) has the same name as the current one,
            // we need to call DoHandsOff() so Commit() can overwrite the old version
            if ( bOk && pMedium && ( rMedium.GetName() == pMedium->GetName() ) )
                DoHandsOff();
        }

        if ( bOk )
        {
            if ( pMedium && ( rMedium.GetName() == pMedium->GetName() ) )
            {
                // before we overwrite the original file, we will make a backup if there is a demand for that
                const sal_Bool bDoBackup = SvtSaveOptions().IsBackup();
                if ( bDoBackup )
                    pMedium->DoBackup_Impl();
            }

            // transfer data to its destinated location
            EnableSetModified( FALSE );
            RegisterTransfer( rMedium );
            bOk = rMedium.Commit();
            EnableSetModified( TRUE );

            // watch: if the document was successfully saved into an own format, no "SaveCompleted" was called,
            // this must be done by the caller ( because they want to do different calls )
            if ( xNewTempRef.Is() )
                // if the new object storage is a temporary one, because the target format is an alien format
                SaveCompleted( xNewTempRef );
            else if ( !bOk && IsHandsOff() )
                // critical case: avoid "HandsOff" states
                // usually the caller doesn't know that this method has set the document into the "HandsOff" state
                DoSaveCompleted( &rMedium );
        }
    }

    // unlock user interface
    Lock_Impl( this, FALSE );
    pImp->bForbidReload = bOldStat;

    if ( bOk )
    {
        DBG_ASSERT( pFilter, "No filter after successful save?!" );
        if( pFilter )
            if( pFilter->IsAlienFormat() )
                // set flag, that the user will be warned for possible data loss on closing this document
                pImp->bDidDangerousSave=sal_True;
            else
                pImp->bDidDangerousSave=sal_False;

        SetEAs_Impl(rMedium);
    }

    return bOk;
}

//------------------------------------------------------------------------

sal_Bool SfxObjectShell::ConnectTmpStorage_Impl( SvStorage* pStg)

/*   [Beschreibung]

     Arbeitet die Applikation auf einem temporaeren Storage,
     so darf der temporaere Storage nicht aus dem SaveCompleted
     genommen werden. Daher wird in diesem Fall schon hier an
     den neuen Storage connected. SaveCompleted tut dann nichts.

     */

{
    // wenn es kein temp. Storage ist, einen anlegen
    SvStorageRef aTmpMed = new SvStorage( (pStg->GetVersion() >= SOFFICE_FILEFORMAT_60), String() );

    // nach HandsOff muss der alte Storage wieder eingesetzt werden
    if ( !pStg->CopyTo(aTmpMed) )
    {
        SetError(aTmpMed->GetErrorCode());
        aTmpMed.Clear();
        return sal_False;
    }

    SetError(GetMedium()->GetErrorCode());
    SaveCompleted(aTmpMed); // neuer temp. Storage; gibt alten frei
    return sal_True;
}


//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoSaveAs( SvStorage * pNewStor )
{
// DoSaveAs wird nur noch ueber OLE aufgerufen
    sal_Bool bOk;
    {
        SfxForceLinkTimer_Impl aFLT( this );
        ModifyBlocker_Impl aBlock( this );
        //Abwehr gegen feindlich gesinnte Applikationen.
        if ( !pNewStor->GetFormat() )
            SetupStorage( pNewStor );

        pImp->bIsSaving = sal_False;
        SfxMedium* pNewMed = new SfxMedium( pNewStor );
        const String aOldURL( INetURLObject::GetBaseURL() );

        bOk = SaveAsOwnFormat( *pNewMed );
        INetURLObject::SetBaseURL( aOldURL );
        delete pNewMed;
    }
    return bOk;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoSaveAs( SfxMedium &rMedium )
{
    // hier kommen nur Root-Storages rein, die via Temp-File gespeichert werden
    const String aOldURL( INetURLObject::GetBaseURL() );
    if( GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
        if ( ShallSetBaseURL_Impl( rMedium ) )
            INetURLObject::SetBaseURL( rMedium.GetName() );
        else
            INetURLObject::SetBaseURL( String() );

    rMedium.CreateTempFileNoCopy();

    sal_Bool bRet = SaveTo_Impl( rMedium, NULL, FALSE );
    INetURLObject::SetBaseURL( aOldURL );
    if( bRet )
        DoHandsOff();
    else
        SetError(rMedium.GetErrorCode());
    return bRet;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoSaveCompleted( SfxMedium * pNewMed )
{
    sal_Bool bOk = sal_True;
    sal_Bool bMedChanged = pNewMed && pNewMed!=pMedium;
/*  sal_Bool bCreatedTempStor = pNewMed && pMedium &&
        IsOwnStorageFormat_Impl(*pMedium) &&
        !IsOwnStorageFormat_Impl(*pNewMed) &&
        pMedium->GetName().Len();
*/
    DBG_ASSERT( !pNewMed || pNewMed->GetError() == ERRCODE_NONE, "DoSaveCompleted: Medium has error!" );
    if ( bMedChanged )
    {
        delete pMedium;
        pMedium = pNewMed;
        Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
        //MI? DELETEZ(pImp->pDocInfo);
    }

    const SfxFilter *pFilter = pMedium ? pMedium->GetFilter() : 0;
    if ( pNewMed )
    {
        if( bMedChanged )
        {
            if( pNewMed->GetName().Len() )
                bHasName = sal_True;
            String aBase = GetBaseURL();
            if( Current() == this && aBase.Len() )
                INetURLObject::SetBaseURL( aBase );
            Broadcast( SfxSimpleHint(SFX_HINT_NAMECHANGED) );
        }
        if ( !pFilter || pFilter->IsOwnFormat())
        {
            SvStorage* pStorage = pMedium->GetStorage();
            bOk = SaveCompleted( pStorage );

            // Set storage in document library containers
            SfxDialogLibraryContainer* pDialogCont = pImp->pDialogLibContainer;
            if( pDialogCont )
                pDialogCont->setStorage( pStorage );

            SfxScriptLibraryContainer* pBasicCont = pImp->pBasicLibContainer;
            if( pBasicCont )
                pBasicCont->setStorage( pStorage );
        }
        else if( pFilter->UsesStorage() )
            pMedium->GetStorage();
        else if( pMedium->GetOpenMode() & STREAM_WRITE )
            pMedium->GetInStream();
    }
    else
    {
        if( pMedium )
        {
            const SfxFilter* pFilter = pMedium->GetFilter();
            if( pFilter && !pFilter->IsOwnFormat() &&
                (pMedium->GetOpenMode() & STREAM_WRITE ))
                pMedium->ReOpen();
            else
                SaveCompleted( 0 );
        }
        // entweder Save oder ConvertTo
        else
            bOk = SaveCompleted( NULL );
    }

    if ( bOk && pNewMed )
    {
        if( bMedChanged )
        {
            // Titel neu setzen
            if ( pNewMed->GetName().Len() &&
                 SFX_CREATE_MODE_EMBEDDED != eCreateMode )
                InvalidateName();
            SetModified(sal_False); // nur bei gesetztem Medium zur"ucksetzen
        }
    }

    return bOk;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoSaveCompleted( SvStorage * pNewStor )
{
    return DoSaveCompleted(pNewStor? new SfxMedium( pNewStor ): 0);
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::ConvertFrom
(
    SfxMedium&  rMedium     /*  <SfxMedium>, welches die Quell-Datei beschreibt
                                (z.B. Dateiname, <SfxFilter>, Open-Modi etc.) */
)

/*  [Beschreibung]

    Diese Methode wird zum Laden von Dokumenten "uber alle Filter gerufen,
    die nicht SFX_FILTER_OWN sind oder f"ur die kein Clipboard-Format
    registriert wurde (also kein Storage-Format benutzen). Mit anderen Worten:
    mit dieser Methode wird importiert.

    Das hier zu "offende File sollte "uber 'rMedium' ge"offnet werden,
    um die richtigen Open-Modi zu gew"ahrleisten. Insbesondere wenn das
    Format beibehalten wird (nur m"oglich bei SFX_FILTER_SIMULATE oder
    SFX_FILTER_ONW) mu\s die Datei STREAM_SHARE_DENYWRITE ge"offnet werden.


    [R"uckgabewert]

    sal_Bool                sal_True
                        Das Dokument konnte geladen werden.

                        sal_False
                        Das Dokument konnte nicht geladen werden, ein
                        Fehlercode ist mit <SvMedium::GetError()const> zu
                        erhalten.


    [Beispiel]

    sal_Bool DocSh::ConvertFrom( SfxMedium &rMedium )
    {
        SvStreamRef xStream = rMedium.GetInStream();
        if( xStream.is() )
        {
            xStream->SetBufferSize(4096);
            *xStream >> ...;

            // NICHT 'rMedium.CloseInStream()' rufen! File gelockt halten!
            return SVSTREAM_OK == rMedium.GetError();
        }

        return sal_False;
    }


    [Querverweise]

    <SfxObjectShell::ConvertTo(SfxMedium&)>
    <SFX_FILTER_REGISTRATION>
*/
{
    return sal_False;
}

sal_Bool SfxObjectShell::ImportFrom( SfxMedium& rMedium )
{
    ::rtl::OUString aTypeName( GetMedium()->GetFilter()->GetTypeName() );
    ::rtl::OUString aFilterName( GetMedium()->GetFilter()->GetFilterName() );

    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
    ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > xFilterFact (
                xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY );

    ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aProps;
    ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > xFilters ( xFilterFact, ::com::sun::star::uno::UNO_QUERY );
    if ( xFilters->hasByName( aFilterName ) )
        xFilters->getByName( aFilterName ) >>= aProps;

    ::rtl::OUString aFilterImplName;
    sal_Int32 nFilterProps = aProps.getLength();
    for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
    {
        const ::com::sun::star::beans::PropertyValue& rFilterProp = aProps[nFilterProp];
        if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
        {
            rFilterProp.Value >>= aFilterImplName;
            break;
        }
    }

    ::com::sun::star::uno::Sequence < ::com::sun::star::uno::Any > aArgs(1);
    aArgs[0] <<= aFilterName;
    ::com::sun::star::uno::Reference< ::com::sun::star::document::XFilter > xLoader;
    if ( aFilterImplName.getLength() )
        xLoader = ::com::sun::star::uno::Reference< ::com::sun::star::document::XFilter >
            ( xFilterFact->createInstanceWithArguments( aTypeName, aArgs ), ::com::sun::star::uno::UNO_QUERY );
    if ( xLoader.is() )
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >  xComp( GetModel(), ::com::sun::star::uno::UNO_QUERY );
        ::com::sun::star::uno::Reference< ::com::sun::star::document::XImporter > xImporter( xLoader, ::com::sun::star::uno::UNO_QUERY );
        xImporter->setTargetDocument( xComp );

        ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > lDescriptor;
        rMedium.GetItemSet()->Put( SfxStringItem( SID_OPENURL, rMedium.GetName() ) );
        TransformItems( SID_OPENDOC, *rMedium.GetItemSet(), lDescriptor );
        xLoader->filter( lDescriptor );
        return sal_True;
    }

    return sal_False;
}

sal_Bool SfxObjectShell::ExportTo( SfxMedium& rMedium, const SfxItemSet& rSet )
{
    ::rtl::OUString aTypeName( GetMedium()->GetFilter()->GetTypeName() );
    ::rtl::OUString aFilterName( GetMedium()->GetFilter()->GetFilterName() );
    ::com::sun::star::uno::Reference< ::com::sun::star::document::XExporter > xExporter;

    {
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
        ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > xFilterFact (
                xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY );

        ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aProps;
        ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > xFilters ( xFilterFact, ::com::sun::star::uno::UNO_QUERY );
        if ( xFilters->hasByName( aFilterName ) )
            xFilters->getByName( aFilterName ) >>= aProps;

        ::rtl::OUString aFilterImplName;
        sal_Int32 nFilterProps = aProps.getLength();
        for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
        {
            const ::com::sun::star::beans::PropertyValue& rFilterProp = aProps[nFilterProp];
            if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
            {
                rFilterProp.Value >>= aFilterImplName;
                break;
            }
        }

        ::com::sun::star::uno::Sequence < ::com::sun::star::uno::Any > aArgs(1);
        aArgs[0] <<= aFilterName;
        if ( aFilterImplName.getLength() )
            xExporter = ::com::sun::star::uno::Reference< ::com::sun::star::document::XExporter >
                ( xFilterFact->createInstanceWithArguments( aTypeName, aArgs ), ::com::sun::star::uno::UNO_QUERY );
    }

    if ( xExporter.is() )
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >  xComp( GetModel(), ::com::sun::star::uno::UNO_QUERY );
        ::com::sun::star::uno::Reference< ::com::sun::star::document::XFilter > xFilter( xExporter, ::com::sun::star::uno::UNO_QUERY );
        xExporter->setSourceDocument( xComp );
        xFilter->filter( GetModel()->getArgs() );
        return sal_True;
    }

    return sal_False;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::ConvertTo
(
    SfxMedium&  rMedium     /*  <SfxMedium>, welches die Ziel-Datei beschreibt
                                (z.B. Dateiname, <SfxFilter>, Open-Modi etc.) */
)

/*  [Beschreibung]

    Diese Methode wird zum Speichern von Dokumenten "uber alle Filter gerufen,
    die nicht SFX_FILTER_OWN sind oder f"ur die kein Clipboard-Format
    registriert wurde (also kein Storage-Format benutzen). Mit anderen Worten:
    mit dieser Methode wird exportiert.

    Das hier zu "offende File sollte "uber 'rMedium' ge"offnet werden,
    um die richtigen Open-Modi zu gew"ahrleisten. Insbesondere wenn das
    Format beibehalten wird (nur m"oglich bei SFX_FILTER_SIMULATE oder
    SFX_FILTER_ONW) mu\s die Datei auch nach dem Speichern im Modus
    STREAM_SHARE_DENYWRITE ge"offnet bleiben.


    [R"uckgabewert]

    sal_Bool                sal_True
                        Das Dokument konnte gespeichert werden.

                        sal_False
                        Das Dokument konnte nicht gespeichert werden, ein
                        Fehlercode ist mit <SvMedium::GetError()const> zu
                        erhalten.


    [Beispiel]

    sal_Bool DocSh::ConvertTo( SfxMedium &rMedium )
    {
        SvStreamRef xStream = rMedium.GetOutStream();
        if ( xStream.is() )
        {
            xStream->SetBufferSize(4096);
            *xStream << ...;

            rMedium.CloseOutStream(); // "offnet automatisch wieder den InStream
            return SVSTREAM_OK == rMedium.GetError();
        }
        return sal_False ;
    }


    [Querverweise]

    <SfxObjectShell::ConvertFrom(SfxMedium&)>
    <SFX_FILTER_REGISTRATION>
*/

{
    return sal_False;
}

//-------------------------------------------------------------------------

void SfxObjectShell::SetEAs_Impl( SfxMedium &rMedium )
{
    //!! wenn OV eine entsprechende Funktionalitaet zur Verfuegung stellt,
    // besser auf der geoeffneten Datei arbeiten
    SvEaMgr *pMgr = rMedium.GetEaMgr();
    SvEaMgr *pOld = GetMedium()->GetEaMgr();
    if ( !pMgr )
        return;

    if ( pOld )
        pOld->Clone( *pMgr );

    String aBuffer;
    pMgr->SetComment( GetDocInfo().GetComment() );

    pMgr->SetFileType( rMedium.GetFilter()->GetTypeName().GetToken( 0, ';' ) );
    if ( SvEaMgr::GetAppCreator(aBuffer) )
        pMgr->SetCreator(aBuffer);

    if ( rMedium.GetLongName().Len() )
        pMgr->SetLongName(rMedium.GetLongName());
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
{
    SfxMedium *pMedium = GetMedium();
    const SfxFilter* pFilter = pMedium->GetFilter();

    // copy the original itemset, but remove the "version" item, because pMediumTmp
    // is a new medium "from scratch", so no version should be stored into it
    SfxItemSet* pSet = pMedium->GetItemSet() ? new SfxAllItemSet(*pMedium->GetItemSet()): 0;
    pSet->ClearItem( SID_VERSION );

    // create a medium as a copy; this medium is only for writingm, because it uses the same name as the original one
    // writing is done through a copy, that will be transferred to the target ( of course after calling HandsOff )
    SfxMedium* pMediumTmp = new SfxMedium( pMedium->GetName(), pMedium->GetOpenMode(), pMedium->IsDirect(), pFilter, pSet );
    pMediumTmp->SetLongName( pMedium->GetLongName() );
    pMediumTmp->CreateTempFileNoCopy();

    // some awful base URL stuff
    const String aOldURL( INetURLObject::GetBaseURL() );
    if( GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
        if ( ShallSetBaseURL_Impl(*pMedium) )
            INetURLObject::SetBaseURL( pMedium->GetName() );
        else
            INetURLObject::SetBaseURL( String() );

    // copy version list from "old" medium to target medium, so it can be used on saving
    pMediumTmp->TransferVersionList_Impl( *pMedium );

    if ( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PACKED ) )
        SetError( GetMedium()->Unpack_Impl( pMedium->GetPhysicalName() ) );

    sal_Bool bSaved = sal_False;
    if( !GetError() && SaveTo_Impl( *pMediumTmp, pArgs, TRUE ) )
    {
        bSaved = sal_True;

        // restore BaseURL
        INetURLObject::SetBaseURL( aOldURL );

        ByteString aKey;
        if ( IsOwnStorageFormat_Impl( *pMediumTmp ) )
            aKey = pMediumTmp->GetStorage()->GetKey();

        // retransfer parameters to original itemset
        if( pSet )
            pSet->Put( *pMediumTmp->GetItemSet() );

        // copy back version list to "old" medium, because the "old" medium will stay the objectshells' medium,
        // the temporary medium was only used in between
        pMedium->TransferVersionList_Impl( *pMediumTmp );
        SetError(pMediumTmp->GetErrorCode());

        // remove temporary medium and reconnect to original one
        pMediumTmp->Close();
        delete pMediumTmp;

        DoHandsOff();
        sal_Bool bOpen = DoSaveCompleted(pMedium);
        if (  bOpen && aKey.Len() )
            pMedium->GetStorage()->SetKey( aKey );
        DBG_ASSERT(bOpen,"Fehlerbehandlung fuer DoSaveCompleted nicht implementiert");
    }
    else
    {
        // restore BaseURL
        INetURLObject::SetBaseURL( aOldURL );

        // transfer error code from medium to objectshell
        SetError( pMediumTmp->GetError() );

        // kill temporary file and medium
        String aTmp;
        ::utl::LocalFileHelper::ConvertPhysicalNameToURL( pMediumTmp->GetPhysicalName(), aTmp );
        delete pMediumTmp;
        SfxContentHelper::Kill( aTmp );

        // reconnect to object storage
        DoSaveCompleted( (SvStorage*)0 );
    }

    SetModified( !bSaved );
    return bSaved;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::Save_Impl( const SfxItemSet* pSet )
{
    DBG_CHKTHIS(SfxObjectShell, 0);
    SfxApplication *pSfxApp = SFX_APP();

    pImp->bIsSaving = sal_True;
    sal_Bool bSaved;
    SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
    if ( pSalvageItem )
    {
        SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False);
        const SfxFilter *pFilter = pFilterItem
                    ? GetFactory().GetFilterContainer()->GetFilter(pFilterItem->GetValue())
                    : 0;
        SfxMedium *pMed = new SfxMedium(
            pSalvageItem->GetValue(), STREAM_READWRITE | STREAM_SHARE_DENYWRITE, sal_False, pFilter );

        SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False );
        if ( pPasswordItem )
            pMed->GetItemSet()->Put( *pPasswordItem );

        bSaved = DoSaveAs( *pMed );
        if ( bSaved )
            bSaved = DoSaveCompleted( pMed );
        else
            delete pMed;
    }
    else
        bSaved = DoSave_Impl( pSet );
    if ( bSaved && SvtSaveOptions().IsAutoSave() )
        pSfxApp->GetAutoSaveTimer_Impl()->Start();
    return bSaved;
}

//-------------------------------------------------------------------------

class SfxSaveAsContext_Impl
{
    String&     _rNewNameVar;
    String      _aNewName;

public:
                SfxSaveAsContext_Impl( String &rNewNameVar,
                                       const String &rNewName )
                :   _rNewNameVar( rNewNameVar ),
                    _aNewName( rNewName )
                { rNewNameVar = rNewName; }
                ~SfxSaveAsContext_Impl()
                { _rNewNameVar.Erase(); }
};

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::SaveAs_Impl(sal_Bool bUrl, SfxRequest *pRequest)
{
    // must we ask the user for the filename?
    INetURLObject aURL;
    sal_uInt16 nActFilt = 0;
    const SfxFilter* pFilt;
    for( pFilt = GetFactory().GetFilter( 0 );
         pFilt && ( !pFilt->CanExport() || pFilt->IsInternal() );
         pFilt = GetFactory().GetFilter( ++nActFilt ) );

    DBG_ASSERT( pFilt, "Kein Filter zum Speichern" );

    String aFilterName;
    if( pFilt )
        aFilterName = pFilt->GetName();

    SfxItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
    SFX_REQUEST_ARG( (*pRequest), pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False );
    if ( pRequest->GetArgs() )
        pParams->Put( *pRequest->GetArgs() );

    if ( !pFileNameItem )
    {
        if(! bUrl )
        {
            // get the filename by dialog ...
            // create the file dialog
            sfx2::FileDialogHelper aFileDlg( FILESAVE_AUTOEXTENSION_PASSWORD,
                                             0L, GetFactory() );

            if ( HasName() )
            {
                String aLastName = QueryTitle( SFX_TITLE_QUERY_SAVE_NAME_PROPOSAL );
                const SfxFilter* pMedFilter = GetMedium()->GetFilter();
                if( pImp->bSetStandardName && !IsTemplate() || !pMedFilter ||
                    !pMedFilter->CanExport() /*!!!||
                    pMedFilter->GetVersion() != SOFFICE_FILEFORMAT_CURRENT*/ )
                {
                    if( aLastName.Len() )
                    {
                        String aPath( aLastName );
                        bool bWasAbsolute = FALSE;
                        INetURLObject aObj( SvtPathOptions().GetWorkPath() );
                        aObj.setFinalSlash();
                        aObj = INetURLObject( aObj.RelToAbs( aPath, bWasAbsolute ) );
                        aObj.SetExtension( pFilt->GetDefaultExtension().Copy(2) );
                        aFileDlg.SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
                    }

                    aFileDlg.SetCurrentFilter( pFilt->GetName() );
                }
                else
                {
                    if( aLastName.Len() )
                        aFileDlg.SetDisplayDirectory( aLastName );

                    aFileDlg.SetCurrentFilter( pMedFilter->GetName() );
                }
            }
            else
            {
                aFileDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
            }

            if ( aFileDlg.Execute( pParams, aFilterName ) != ERRCODE_NONE )
            {
                SetError(ERRCODE_IO_ABORT);
                return sal_False;
            }

            // get the path from the dialog
            aURL.SetURL( aFileDlg.GetPath() );

            // gibt es schon ein Doc mit dem Namen?
            if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
            {
                SfxObjectShell* pDoc = 0;
                for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst();
                      pTmp && !pDoc;
                      pTmp = SfxObjectShell::GetNext(*pTmp) )
                {
                    if( ( pTmp != this ) && pTmp->GetMedium() )
                    {
                        INetURLObject aCompare( pTmp->GetMedium()->GetName() );
                        if ( aCompare == aURL )
                            pDoc = pTmp;
                    }
                }
                if ( pDoc )
                {
                    // dann Fehlermeldeung: "schon offen"
                    SetError(ERRCODE_SFX_ALREADYOPEN);
                    return sal_False;
                }
            }

            // --**-- pParams->Put( *pDlg->GetItemSet() );
            Reference< XFilePickerControlAccess > xExtFileDlg( aFileDlg.GetFilePicker(), UNO_QUERY );
            if ( xExtFileDlg.is() )
            {
                try
                {
                    Any aValue = xExtFileDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, 0 );
                    sal_Bool bSelectFilter = sal_False;

                    aValue >>= bSelectFilter;
                    pParams->Put( SfxBoolItem( SID_USE_FILTEROPTIONS, bSelectFilter ) );
                }
                catch( IllegalArgumentException ){}
            }
        }
        else
        {
            SfxUrlDialog aDlg( 0 );
            if( aDlg.Execute() == RET_OK )
                aURL.SetURL( aDlg.GetUrl() );
            else
            {
                SetError(ERRCODE_IO_ABORT);
                return sal_False;
            }
        }

        // Request mit Dateiname und Filter vervollst"andigen
        pRequest->AppendItem(SfxStringItem( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE )) );
        pRequest->AppendItem(SfxStringItem( SID_FILTER_NAME, aFilterName));
        const SfxPoolItem* pItem=0;
        pRequest->GetArgs()->GetItemState( SID_FILE_NAME, sal_False, &pItem );
        pFileNameItem = PTR_CAST( SfxStringItem, pItem );
    }

    // neuen Namen an der Object-Shell merken
    SfxSaveAsContext_Impl aSaveAsCtx( pImp->aNewName, aURL.GetMainURL( INetURLObject::NO_DECODE ) );

    // now we can get the filename from the SfxRequest
    DBG_ASSERT( pRequest->GetArgs() != 0, "fehlerhafte Parameter");
    SFX_REQUEST_ARG( (*pRequest), pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
    FASTBOOL bSaveTo = pSaveToItem ? pSaveToItem->GetValue() : sal_False;

    if ( !pFileNameItem && bSaveTo )
    {
        // get the filename by dialog ...
        // create the file dialog
        sfx2::FileDialogHelper aFileDlg( FILESAVE_AUTOEXTENSION_PASSWORD,
                                         0L, GetFactory() );

        if ( aFileDlg.Execute( pParams, aFilterName ) != ERRCODE_NONE )
        {
            SetError(ERRCODE_IO_ABORT);
            return sal_False;
        }

        // get the path from the dialog
        aURL.SetURL( aFileDlg.GetPath() );
    }
    else if ( pFileNameItem )
    {
        aURL.SetURL(((const SfxStringItem *)pFileNameItem)->GetValue() );
        DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" );

        const SfxPoolItem* pFilterNameItem=0;
        const SfxItemState eState = pRequest->GetArgs()->GetItemState(SID_FILTER_NAME, sal_True, &pFilterNameItem);
        if ( SFX_ITEM_SET == eState )
        {
            DBG_ASSERT(pFilterNameItem->IsA( TYPE(SfxStringItem) ), "Fehler Parameter");
            aFilterName = ((const SfxStringItem *)pFilterNameItem)->GetValue();
        }
    }
    else
    {
        SetError( ERRCODE_IO_INVALIDPARAMETER );
        return sal_False;
    }

    const SfxFilter* pFilter = GetFactory().GetFilterContainer()->GetFilter( aFilterName );
    if ( !pFilter )
    {
        SetError( ERRCODE_IO_INVALIDPARAMETER );
        return sal_False;
    }

    pImp->bPasswd = pParams && SFX_ITEM_SET == pParams->GetItemState(SID_PASSWORD);

    // unter gleichem Namen speichern?
    SfxMedium *pActMed = GetMedium();
    const INetURLObject aActName(pActMed->GetName());

    if ( aURL == aActName )
    {
        if ( IsReadOnly() )
        {
            SetError(ERRCODE_SFX_DOCUMENTREADONLY);
            return sal_False;
        }
        // gleicher Filter? -> Save()
        const SfxFilter *pFilter = pActMed->GetFilter();
        if ( pFilter && pFilter->GetName() == aFilterName )
        {
            pImp->bIsSaving=sal_False;
            if ( pParams )
            {
                SfxItemSet* pSet = pMedium->GetItemSet();
                pSet->ClearItem( SID_PASSWORD );
                pSet->Put( *pParams );
            }
            return DoSave_Impl();
        }
    }

    if( aURL.HasError() )
    {
        SetError( ERRCODE_IO_INVALIDPARAMETER );
        return sal_False;
    }

    if ( SvtSaveOptions().IsSaveUnpacked() )
        pParams->Put( SfxBoolItem( SID_PACK, FALSE ) );

    if ( PreDoSaveAs_Impl(aURL.GetMainURL( INetURLObject::NO_DECODE ),aFilterName,pParams))
    {
        pImp->bWaitingForPicklist = sal_True;
        if (!pImp->bSetStandardName)
            pImp->bDidWarnFormat=sal_False;
        // Muss !!!
        if ( IsOwnStorageFormat_Impl(*GetMedium()))
        {
            SetFileName( GetMedium()->GetPhysicalName() );
        }

        return sal_True;
    }
    else
        return sal_False;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::PreDoSaveAs_Impl
(
    const String&   rFileName,
    const String&   aFilterName,
    SfxItemSet*     pParams
)
{
    // copy all items stored in the itemset of the current medium
    SfxAllItemSet* pMergedParams = new SfxAllItemSet( *pMedium->GetItemSet() );

    // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
    pMergedParams->ClearItem( SID_PASSWORD );
    pMergedParams->ClearItem( SID_DOCINFO_TITLE );

    // "SaveAs" will never store any version information - it's a complete new file !
    pMergedParams->ClearItem( SID_VERSION );

    // merge the new parameters into the copy
    // all values present in both itemsets will be overwritten by the new parameters
    if( pParams )
        pMergedParams->Put( *pParams );
    delete pParams;

    // should be unneccessary - too hot to handle!
    pMergedParams->ClearItem( SID_DOC_SALVAGE );

#ifdef DBG_UTIL
    if ( pMergedParams->GetItemState( SID_DOC_SALVAGE) >= SFX_ITEM_AVAILABLE )
        DBG_ERROR("Salvage item present in Itemset, check the parameters!");
#endif

    // take over the new merged itemset
    pParams = pMergedParams;

    // create a medium for the target URL
    SfxMedium *pNewFile = new SfxMedium( rFileName, STREAM_READWRITE | STREAM_SHARE_DENYWRITE, sal_False, 0, pParams );

    // check if a "SaveTo" is wanted, no "SaveAs"
    SFX_ITEMSET_ARG( pParams, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
    sal_Bool bCopyTo = GetCreateMode() == SFX_CREATE_MODE_EMBEDDED || pSaveToItem && pSaveToItem->GetValue();

    // because saving a document modified its DocumentInfo, the current DocumentInfo must be saved on "SaveTo", because
    // it must be restored after saving
    SfxDocumentInfo aSavedInfo;
    if ( bCopyTo )
        aSavedInfo = GetDocInfo();

    // set filter; if no filter is given, take the default filter of the factory
    if ( aFilterName.Len() )
        pNewFile->SetFilter( GetFactory(), aFilterName );
    else
        pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetFilter(0) );

    // saving is alway done using a temporary file
    pNewFile->CreateTempFileNoCopy();

    // some base URL stuff ( awful, but not avoidable ... )
    const String aOldURL( INetURLObject::GetBaseURL() );
    if( GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
        if ( ShallSetBaseURL_Impl(*pNewFile) )
            INetURLObject::SetBaseURL( pNewFile->GetName() );
        else
            INetURLObject::SetBaseURL( String() );

    // distinguish between "Save" and "SaveAs"
    pImp-> bIsSaving = sal_False;

    if ( IsOwnStorageFormat_Impl(*pNewFile) )
    {
        // If the filter is a "cross export" filter ( f.e. a filter for exporting an impress document from
        // a draw document ), the ClassId of the destination storage is different from the ClassId of this
        // document. It can be retrieved from the default filter for the desired target format
        long nFormat = pNewFile->GetFilter()->GetFormat();
        SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
        const SfxFilter *pFilt = rMatcher.GetFilter4ClipBoardId( nFormat );
        if ( pFilt )
        {
            if ( pFilt->GetFilterContainer() != pNewFile->GetFilter()->GetFilterContainer() )
                pNewFile->GetStorage()->SetClass( SvFactory::GetServerName( nFormat ), nFormat, pFilt->GetTypeName() );
        }
    }

    if ( GetMedium()->GetFilter() && ( GetMedium()->GetFilter()->GetFilterFlags() & SFX_FILTER_PACKED ) )
    {
        SfxMedium *pMed = bCopyTo ? pMedium : pNewFile;
        pNewFile->SetError( GetMedium()->Unpack_Impl( pMed->GetPhysicalName() ) );
    }

    // Save the document ( first as temporary file, then transfer to the target URL by committing the medium )
    sal_Bool bOk = sal_False;
    if ( !pNewFile->GetErrorCode() && SaveTo_Impl( *pNewFile, NULL, TRUE ) )
    {
        bOk = sal_True;

        // restore old BaseURL
        INetURLObject::SetBaseURL( aOldURL );

        // transfer a possible error from the medium to the document
        SetError( pNewFile->GetErrorCode() );

        // notify the document that saving was done successfully
        if ( bCopyTo )
            bOk = DoSaveCompleted( pMedium );
        else
            bOk = DoSaveCompleted( pNewFile );

        if( bOk )
        {
            if( !bCopyTo )
                SetModified( sal_False );
        }
        else
        {
            DBG_ASSERT( !bCopyTo, "Error while reconnecting to medium, can't be handled!");
            SetError( pNewFile->GetErrorCode() );

            if ( !bCopyTo )
            {
                // reconnect to the old medium
                BOOL bRet = DoSaveCompleted( pMedium );
                DBG_ASSERT( bRet, "Error in DoSaveCompleted, can't be handled!");
            }

            DELETEZ( pNewFile );
        }

        String aPasswd;
        if ( IsOwnStorageFormat_Impl( *GetMedium() ) && GetPasswd_Impl( GetMedium()->GetItemSet(), aPasswd ) )
            GetMedium()->GetStorage()->SetKey( S2BS( aPasswd ) );   //!!! (pb) needs new implementation
    }
    else
    {
        INetURLObject::SetBaseURL( aOldURL );
        SetError( pNewFile->GetErrorCode() );

        // reconnect to the old storage
        DoSaveCompleted( (SvStorage*)0 );
    }

    if( !bOk )
        SetModified( sal_True );

    if ( bCopyTo )
    {
        // restore DocumentInfo if only a copy was created
        SfxDocumentInfo &rDocInfo = GetDocInfo();
        rDocInfo = aSavedInfo;
        DELETEZ( pNewFile );
    }

    return bOk;
}

//------------------------------------------------------------------------

sal_Bool SfxObjectShell::LoadFrom( SvStorage *pStor )
{
#if SUPD<635
    if (pStor->IsStream(SfxConfigManager::GetStreamName()))
        SetConfigManager (new SfxConfigManager( pStor, 0));
#else
    GetConfigManager();
#endif
    GetDocInfo().Load(pStor);
    return sal_True;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::CanReload_Impl()

/*  [Beschreibung]

    Interne Methode zum Feststellen, ob eine erneutes Laden des
    Dokuments (auch als RevertToSaved oder LastVersion bekannt)
    m"oglich ist.
*/

{
    const SfxMedium *pMedium = GetMedium();
    const SfxFilter *pFilter = pMedium ? pMedium->GetFilter() : 0;
    return pMedium && HasName() &&
        ( !pFilter || ! pFilter->GetFilterName().EqualsAscii( SFX_FILTER_DOWNLOAD ) ) &&
        !IsInModalMode() && !Application::IsInModalMode() &&
        !pImp->bForbidReload;
    // Fuer AutoLoad muss Reload immer enabled sein, also NICHT:
    // ( IsModified() || GetMedium()->IsRemote()
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::LoadLayout() const
{
    return pImp->bLoadLayout;
}

//-------------------------------------------------------------------------

void SfxObjectShell::SetLoadLayout_Impl( sal_Bool bLoadLayout )
{
    pImp->bLoadLayout = bLoadLayout;
}

//-------------------------------------------------------------------------

sal_Bool SfxObjectShell::IsInformationLost()
{
    const SfxFilter *pFilt = GetMedium()->GetFilter();
    return pFilt && pFilt->IsAlienFormat() && pImp->bDidDangerousSave && !(pFilt->GetFilterFlags() & SFX_FILTER_SILENTEXPORT);
}

sal_Bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium )
{
    SvStorageRef xStor = rMedium.GetStorage();
    if ( xStor.Is() )
    {
#if SUPD < 635
        // Config
        if ( xStor->IsStream(SfxConfigManager::GetStreamName()) )
            SetConfigManager (new SfxConfigManager( xStor, SFX_CFGMANAGER()));
#endif
        if ( rMedium.GetFileVersion() )
            xStor->SetVersion( rMedium.GetFileVersion() );

        // Password
        SFX_ITEMSET_ARG( rMedium.GetItemSet(), pPasswdItem,
                         SfxStringItem, SID_PASSWORD, sal_False );
        SfxApplication *pApp = SFX_APP();
        if ( pPasswdItem || ERRCODE_IO_ABORT != CheckPasswd_Impl( 0, pApp->GetPool(), pMedium ) )
        {
            String aPasswd;
            if ( GetPasswd_Impl(pMedium->GetItemSet(), aPasswd) )
                xStor->SetKey( S2BS( aPasswd ) ); //!!! (pb) needs new implementation

            // load document
            return Load( xStor );
        }
        return sal_False;
    }
    else
        return sal_False;
}

sal_Bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium )
{
    SvStorageRef xStor = rMedium.GetStorage();
    if( xStor.Is() )
    {
        ULONG nVersion = rMedium.GetFilter()->GetVersion();
        xStor->SetVersion( nVersion );

        // Initialize Basic
        GetBasicManager();

        // Save dialog container
        if( nVersion >= 6200 )
        {
            SfxDialogLibraryContainer* pDialogCont = pImp->pDialogLibContainer;
            if( pDialogCont )
                pDialogCont->storeLibrariesToStorage( (SotStorage*)(SvStorage*)xStor );

            SfxScriptLibraryContainer* pBasicCont = pImp->pBasicLibContainer;
            if( pBasicCont )
                pBasicCont->storeLibrariesToStorage( (SotStorage*)(SvStorage*)xStor );
        }

        const SfxFilter* pFilter = rMedium.GetFilter();
        return SaveAs( xStor );
    }
    else return sal_False;
}


void SfxObjectShell::AddXMLAsZipToTheStorage( SvStorage& rRoot )
{
    static struct _ObjExpType {
        sal_Bool (SvtAddXMLToStorageOptions:: *fnIsAdd)() const;
        const sal_Char* pModuleNm;
        // GlobalNameId
        UINT32 n1;
        USHORT n2, n3;
        BYTE b8, b9, b10, b11, b12, b13, b14, b15;
    } aArr[] = {
        { &SvtAddXMLToStorageOptions::IsWriter_Add_XML_to_Storage,
            "Writer", SO3_SW_CLASSID_50 },
        { &SvtAddXMLToStorageOptions::IsCalc_Add_XML_to_Storage,
            "Calc", SO3_SC_CLASSID_50 },
        { &SvtAddXMLToStorageOptions::IsImpress_Add_XML_to_Storage,
            "Impress", SO3_SIMPRESS_CLASSID_50 },
        { &SvtAddXMLToStorageOptions::IsDraw_Add_XML_to_Storage,
            "Draw", SO3_SDRAW_CLASSID_50 },
        { 0 }
    };

    for( const _ObjExpType* pArr = aArr; pArr->fnIsAdd; ++pArr )
    {
        SvGlobalName aGlbNm( pArr->n1, pArr->n2, pArr->n3,
                            pArr->b8, pArr->b9, pArr->b10, pArr->b11,
                            pArr->b12, pArr->b13, pArr->b14, pArr->b15 );
        if( *GetSvFactory() == aGlbNm )
        {
            // 1. check if the option is set and unequal 0 or is not set
            SvtAddXMLToStorageOptions aOpt;
            if( (aOpt.*pArr->fnIsAdd)() )
            {
                // the flag is set
                String sStr;
                sStr.AssignAscii( "StarOffice XML (" );
                sStr.AppendAscii( pArr->pModuleNm );
                sStr += ')';
                // 2. exist the XML filter? "StarOffice XML (<Application>)"?
                const SfxFilter* pFilter = GetFactory().GetFilterContainer()->
                                                GetFilter4FilterName( sStr );
                if( pFilter )
                {
                    ::utl::TempFile aTempFile;
                    SfxMedium       aTmpMed( aTempFile.GetURL(), STREAM_READ | STREAM_WRITE, TRUE );

                    aTmpMed.SetFilter( pFilter );

                    if( ConvertTo( aTmpMed ) )
                    {
                        SvStorage* pXMLStor = aTmpMed.GetStorage();

                        if( pXMLStor )
                        {
                            const String    aContent( String::CreateFromAscii( "Content" ) );
                            const String    aContentXML( String::CreateFromAscii( "Content.xml" ) );
                            const String    aXMLFormatName( String::CreateFromAscii( "XMLFormat2" ) );
                            String          aContentName;

                            if( pXMLStor->IsContained( aContentXML ) )
                                aContentName = aContentXML;
                            else if( pXMLStor->IsContained( aContent ) )
                                aContentName = aContent;

                            if( aContentName.Len() )
                            {
                                SvStorageStreamRef  xOStm( rRoot.OpenStream( aXMLFormatName, STREAM_WRITE | STREAM_TRUNC ) );
                                SvStorageStreamRef  xIStm( pXMLStor->OpenStream( aContentName, STREAM_READ | STREAM_NOCREATE ) );

                                if( xOStm.Is() && xIStm.Is() )
                                {
                                    ZCodec aCodec;

                                    xIStm->Seek( 0 );
                                    aCodec.BeginCompression( ZCODEC_BEST_COMPRESSION );
                                    aCodec.Compress( *xIStm, *xOStm );
                                    aCodec.EndCompression();
                                    xOStm->Commit();
                                }
                            }
                        }
                    }
                }
            }
            // that's all
            break;
        }
    }
}