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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
#include <rsc/rscsfx.hxx>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/io/XActiveDataControl.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/document/NamedPropertyValues.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
#include <com/sun/star/io/XActiveDataSource.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
#include <sfx2/docfile.hxx>
#include <svtools/sfxecode.hxx>
#include <svl/stritem.hxx>
#include <unotools/streamwrap.hxx>
#include <svx/xmlgrhlp.hxx>
#include <svx/xmleohlp.hxx>
#include <comphelper/genericpropertyset.hxx>
#include <rtl/strbuf.hxx>
#include <sfx2/frame.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <swerror.h>
#include <fltini.hxx>
#include <doc.hxx>
#include <docary.hxx>
#include <docsh.hxx>
#include <unotextrange.hxx>
#include <swmodule.hxx>
#include <SwXMLSectionList.hxx>
#include <statstr.hrc>
#include <SwStyleNameMapper.hxx>
#include <poolfmt.hxx>
#include <numrule.hxx>
#include <paratr.hxx>
#include <svx/svdmodel.hxx>
#include <svx/svdpage.hxx>
#include <svx/svditer.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdograf.hxx>
#include <sfx2/docfilt.hxx>
#include <istyleaccess.hxx>
#include <sfx2/DocumentMetadataAccess.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::lang;
static void lcl_EnsureValidPam( SwPaM& rPam )
{
if( rPam.GetCntntNode() != NULL )
{
// set proper point content
if( rPam.GetCntntNode() != rPam.GetPoint()->nContent.GetIdxReg() )
{
rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
}
// else: point was already valid
// if mark is invalid, we delete it
if( ( rPam.GetCntntNode( false ) == NULL ) ||
( rPam.GetCntntNode( false ) != rPam.GetMark()->nContent.GetIdxReg() ) )
{
rPam.DeleteMark();
}
}
else
{
// point is not valid, so move it into the first content
rPam.DeleteMark();
rPam.GetPoint()->nNode =
*rPam.GetDoc()->GetNodes().GetEndOfContent().StartOfSectionNode();
++ rPam.GetPoint()->nNode;
rPam.Move( fnMoveForward, fnGoCntnt ); // go into content
}
}
XMLReader::XMLReader()
{
}
int XMLReader::GetReaderType()
{
return SW_STORAGE_READER;
}
/// read a component (file + filter version)
sal_Int32 ReadThroughComponent(
uno::Reference<io::XInputStream> xInputStream,
uno::Reference<XComponent> xModelComponent,
const OUString& rStreamName,
uno::Reference<uno::XComponentContext> & rxContext,
const sal_Char* pFilterName,
const Sequence<Any>& rFilterArguments,
const OUString& rName,
bool bMustBeSuccessfull,
bool bEncrypted )
{
OSL_ENSURE(xInputStream.is(), "input stream missing");
OSL_ENSURE(xModelComponent.is(), "document missing");
OSL_ENSURE(rxContext.is(), "factory missing");
OSL_ENSURE(NULL != pFilterName,"I need a service name for the component!");
// prepare ParserInputSrouce
xml::sax::InputSource aParserInput;
aParserInput.sSystemId = rName;
aParserInput.aInputStream = xInputStream;
// get parser
uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext);
SAL_INFO( "sw.filter", "parser created" );
// get filter
const OUString aFilterName(OUString::createFromAscii(pFilterName));
uno::Reference< xml::sax::XDocumentHandler > xFilter(
rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(aFilterName, rFilterArguments, rxContext),
UNO_QUERY);
SAL_WARN_IF(!xFilter.is(), "sw", "Can't instantiate filter component: " << aFilterName);
if( !xFilter.is() )
return ERR_SWG_READ_ERROR;
SAL_INFO( "sw.filter", "" << pFilterName << " created" );
// connect parser and filter
xParser->setDocumentHandler( xFilter );
// connect model and filter
uno::Reference < XImporter > xImporter( xFilter, UNO_QUERY );
xImporter->setTargetDocument( xModelComponent );
// finally, parser the stream
try
{
xParser->parseStream( aParserInput );
}
catch( xml::sax::SAXParseException& r )
{
// sax parser sends wrapped exceptions,
// try to find the original one
xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
bool bTryChild = true;
while( bTryChild )
{
xml::sax::SAXException aTmp;
if ( aSaxEx.WrappedException >>= aTmp )
aSaxEx = aTmp;
else
bTryChild = false;
}
packages::zip::ZipIOException aBrokenPackage;
if ( aSaxEx.WrappedException >>= aBrokenPackage )
return ERRCODE_IO_BROKENPACKAGE;
if( bEncrypted )
return ERRCODE_SFX_WRONGPASSWORD;
#if OSL_DEBUG_LEVEL > 0
OStringBuffer aError("SAX parse exception caught while importing:\n");
aError.append(OUStringToOString(r.Message,
RTL_TEXTENCODING_ASCII_US));
OSL_FAIL(aError.getStr());
#endif
const OUString sErr( OUString::number( r.LineNumber )
+ ","
+ OUString::number( r.ColumnNumber ) );
if( !rStreamName.isEmpty() )
{
return *new TwoStringErrorInfo(
(bMustBeSuccessfull ? ERR_FORMAT_FILE_ROWCOL
: WARN_FORMAT_FILE_ROWCOL),
rStreamName, sErr,
ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
}
else
{
OSL_ENSURE( bMustBeSuccessfull, "Warnings are not supported" );
return *new StringErrorInfo( ERR_FORMAT_ROWCOL, sErr,
ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
}
}
catch(const xml::sax::SAXException& r)
{
packages::zip::ZipIOException aBrokenPackage;
if ( r.WrappedException >>= aBrokenPackage )
return ERRCODE_IO_BROKENPACKAGE;
if( bEncrypted )
return ERRCODE_SFX_WRONGPASSWORD;
#if OSL_DEBUG_LEVEL > 0
OStringBuffer aError("SAX exception caught while importing:\n");
aError.append(OUStringToOString(r.Message,
RTL_TEXTENCODING_ASCII_US));
OSL_FAIL(aError.getStr());
#endif
return ERR_SWG_READ_ERROR;
}
catch(const packages::zip::ZipIOException& r)
{
(void)r;
#if OSL_DEBUG_LEVEL > 0
OStringBuffer aError("Zip exception caught while importing:\n");
aError.append(OUStringToOString(r.Message,
RTL_TEXTENCODING_ASCII_US));
OSL_FAIL(aError.getStr());
#endif
return ERRCODE_IO_BROKENPACKAGE;
}
catch(const io::IOException& r)
{
(void)r;
#if OSL_DEBUG_LEVEL > 0
OStringBuffer aError("IO exception caught while importing:\n");
aError.append(OUStringToOString(r.Message,
RTL_TEXTENCODING_ASCII_US));
OSL_FAIL(aError.getStr());
#endif
return ERR_SWG_READ_ERROR;
}
catch(const uno::Exception& r)
{
(void)r;
#if OSL_DEBUG_LEVEL > 0
OStringBuffer aError("uno exception caught while importing:\n");
aError.append(OUStringToOString(r.Message,
RTL_TEXTENCODING_ASCII_US));
OSL_FAIL(aError.getStr());
#endif
return ERR_SWG_READ_ERROR;
}
// success!
return 0;
}
// read a component (storage version)
sal_Int32 ReadThroughComponent(
uno::Reference<embed::XStorage> xStorage,
uno::Reference<XComponent> xModelComponent,
const sal_Char* pStreamName,
const sal_Char* pCompatibilityStreamName,
uno::Reference<uno::XComponentContext> & rxContext,
const sal_Char* pFilterName,
const Sequence<Any>& rFilterArguments,
const OUString& rName,
bool bMustBeSuccessfull)
{
OSL_ENSURE(xStorage.is(), "Need storage!");
OSL_ENSURE(NULL != pStreamName, "Please, please, give me a name!");
// open stream (and set parser input)
OUString sStreamName = OUString::createFromAscii(pStreamName);
bool bContainsStream = false;
try
{
bContainsStream = xStorage->isStreamElement(sStreamName);
}
catch( container::NoSuchElementException& )
{
}
if (!bContainsStream )
{
// stream name not found! Then try the compatibility name.
// if no stream can be opened, return immediately with OK signal
// do we even have an alternative name?
if ( NULL == pCompatibilityStreamName )
return 0;
// if so, does the stream exist?
sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
try
{
bContainsStream = xStorage->isStreamElement(sStreamName);
}
catch( container::NoSuchElementException& )
{
}
if (! bContainsStream )
return 0;
}
// set Base URL
uno::Reference< beans::XPropertySet > xInfoSet;
if( rFilterArguments.getLength() > 0 )
rFilterArguments.getConstArray()[0] >>= xInfoSet;
OSL_ENSURE( xInfoSet.is(), "missing property set" );
if( xInfoSet.is() )
{
xInfoSet->setPropertyValue( "StreamName", makeAny( sStreamName ) );
}
try
{
// get input stream
uno::Reference <io::XStream> xStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
uno::Reference <beans::XPropertySet > xProps( xStream, uno::UNO_QUERY );
Any aAny = xProps->getPropertyValue("Encrypted");
bool bEncrypted = aAny.getValueType() == ::getBooleanCppuType() &&
*(sal_Bool *)aAny.getValue();
uno::Reference <io::XInputStream> xInputStream = xStream->getInputStream();
// read from the stream
return ReadThroughComponent(
xInputStream, xModelComponent, sStreamName, rxContext,
pFilterName, rFilterArguments,
rName, bMustBeSuccessfull, bEncrypted );
}
catch ( packages::WrongPasswordException& )
{
return ERRCODE_SFX_WRONGPASSWORD;
}
catch( packages::zip::ZipIOException& )
{
return ERRCODE_IO_BROKENPACKAGE;
}
catch ( uno::Exception& )
{
OSL_FAIL( "Error on import!\n" );
// TODO/LATER: error handling
}
return ERR_SWG_READ_ERROR;
}
// #i44177#
static void lcl_AdjustOutlineStylesForOOo( SwDoc& _rDoc )
{
// array containing the names of the default outline styles ('Heading 1',
// 'Heading 2', ..., 'Heading 10')
OUString aDefOutlStyleNames[ MAXLEVEL ];
{
OUString sStyleName;
for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
{
sStyleName =
SwStyleNameMapper::GetProgName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i),
sStyleName );
aDefOutlStyleNames[i] = sStyleName;
}
}
// array indicating, which outline level already has a style assigned.
bool aOutlineLevelAssigned[ MAXLEVEL ];
// array of the default outline styles, which are created for the document.
SwTxtFmtColl* aCreatedDefaultOutlineStyles[ MAXLEVEL ];
{
for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
{
aOutlineLevelAssigned[ i ] = false;
aCreatedDefaultOutlineStyles[ i ] = 0L;
}
}
// determine, which outline level has already a style assigned and
// which of the default outline styles is created.
const SwTxtFmtColls& rColls = *(_rDoc.GetTxtFmtColls());
for ( size_t n = 1; n < rColls.size(); ++n )
{
SwTxtFmtColl* pColl = rColls[ n ];
if ( pColl->IsAssignedToListLevelOfOutlineStyle() )
{
aOutlineLevelAssigned[ pColl->GetAssignedOutlineStyleLevel() ] = true;
}
for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
{
if ( aCreatedDefaultOutlineStyles[ i ] == 0L &&
pColl->GetName() == aDefOutlStyleNames[i] )
{
aCreatedDefaultOutlineStyles[ i ] = pColl;
break;
}
}
}
// assign already created default outline style to outline level, which
// doesn't have a style assigned to it.
const SwNumRule* pOutlineRule = _rDoc.GetOutlineNumRule();
for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
{
// #i73361#
// Do not change assignment of already created default outline style
// to a certain outline level.
if ( !aOutlineLevelAssigned[ i ] &&
aCreatedDefaultOutlineStyles[ i ] != 0 &&
! aCreatedDefaultOutlineStyles[ i ]->IsAssignedToListLevelOfOutlineStyle() )
{
// apply outline level at created default outline style
aCreatedDefaultOutlineStyles[ i ]->AssignToListLevelOfOutlineStyle(i);
// apply outline numbering rule, if none is set.
const SfxPoolItem& rItem =
aCreatedDefaultOutlineStyles[ i ]->GetFmtAttr( RES_PARATR_NUMRULE, false );
if ( static_cast<const SwNumRuleItem&>(rItem).GetValue().isEmpty() )
{
SwNumRuleItem aItem( pOutlineRule->GetName() );
aCreatedDefaultOutlineStyles[ i ]->SetFmtAttr( aItem );
}
}
}
}
static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs( SwDoc& _rDoc )
{
if ( _rDoc.GetDrawModel() &&
_rDoc.GetDrawModel()->GetPage( 0 ) )
{
const SdrPage& rSdrPage( *(_rDoc.GetDrawModel()->GetPage( 0 )) );
// iterate recursive with group objects over all shapes on the draw page
SdrObjListIter aIter( rSdrPage );
while( aIter.IsMore() )
{
SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( aIter.Next() );
if( pOle2Obj )
{
// found an ole2 shape
SdrObjList* pObjList = pOle2Obj->GetObjList();
// get its graphic
Graphic aGraphic;
pOle2Obj->Connect();
const Graphic* pGraphic = pOle2Obj->GetGraphic();
if( pGraphic )
aGraphic = *pGraphic;
pOle2Obj->Disconnect();
// create new graphic shape with the ole graphic and shape size
SdrGrafObj* pGraphicObj = new SdrGrafObj( aGraphic, pOle2Obj->GetCurrentBoundRect() );
// apply layer of ole2 shape at graphic shape
pGraphicObj->SetLayer( pOle2Obj->GetLayer() );
// replace ole2 shape with the new graphic object and delete the ol2 shape
SdrObject* pReplaced = pObjList->ReplaceObject( pGraphicObj, pOle2Obj->GetOrdNum() );
SdrObject::Free( pReplaced );
}
}
}
}
sal_uLong XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, const OUString & rName )
{
// Get service factory
uno::Reference< uno::XComponentContext > xContext =
comphelper::getProcessComponentContext();
uno::Reference< io::XActiveDataSource > xSource;
uno::Reference< XInterface > xPipe;
uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
SvXMLGraphicHelper *pGraphicHelper = 0;
uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
SvXMLEmbeddedObjectHelper *pObjectHelper = 0;
// get the input stream (storage or stream)
uno::Reference<io::XInputStream> xInputStream;
uno::Reference<embed::XStorage> xStorage;
if( pMedium )
xStorage = pMedium->GetStorage();
else
xStorage = xStg;
if( !xStorage.is() )
return ERR_SWG_READ_ERROR;
pGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
GRAPHICHELPER_MODE_READ,
false );
xGraphicResolver = pGraphicHelper;
SfxObjectShell *pPersist = rDoc.GetPersist();
if( pPersist )
{
pObjectHelper = SvXMLEmbeddedObjectHelper::Create(
xStorage, *pPersist,
EMBEDDEDOBJECTHELPER_MODE_READ,
false );
xObjectResolver = pObjectHelper;
}
// Get the docshell, the model, and finally the model's component
SwDocShell *pDocSh = rDoc.GetDocShell();
OSL_ENSURE( pDocSh, "XMLReader::Read: got no doc shell" );
if( !pDocSh )
return ERR_SWG_READ_ERROR;
uno::Reference< lang::XComponent > xModelComp( pDocSh->GetModel(), UNO_QUERY );
OSL_ENSURE( xModelComp.is(),
"XMLReader::Read: got no model" );
if( !xModelComp.is() )
return ERR_SWG_READ_ERROR;
// create and prepare the XPropertySet that gets passed through
// the components, and the XStatusIndicator that shows progress to
// the user.
// create XPropertySet with three properties for status indicator
comphelper::PropertyMapEntry const aInfoMap[] =
{
{ OUString("ProgressRange"), 0,
::cppu::UnoType<sal_Int32>::get(),
beans::PropertyAttribute::MAYBEVOID, 0},
{ OUString("ProgressMax"), 0,
::cppu::UnoType<sal_Int32>::get(),
beans::PropertyAttribute::MAYBEVOID, 0},
{ OUString("ProgressCurrent"), 0,
::cppu::UnoType<sal_Int32>::get(),
beans::PropertyAttribute::MAYBEVOID, 0},
{ OUString("NumberStyles"), 0,
cppu::UnoType<container::XNameContainer>::get(),
beans::PropertyAttribute::MAYBEVOID, 0},
{ OUString("RecordChanges"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("ShowChanges"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("RedlineProtectionKey"), 0,
::getCppuType((Sequence<sal_Int8>*)0),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("PrivateData"), 0,
cppu::UnoType<XInterface>::get(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("BaseURI"), 0,
::cppu::UnoType<OUString>::get(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("StreamRelPath"), 0,
::cppu::UnoType<OUString>::get(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("StreamName"), 0,
::cppu::UnoType<OUString>::get(),
beans::PropertyAttribute::MAYBEVOID, 0 },
// properties for insert modes
{ OUString("StyleInsertModeFamilies"), 0,
::getCppuType((Sequence<OUString>*)0),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("StyleInsertModeOverwrite"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("TextInsertModeRange"), 0,
cppu::UnoType<text::XTextRange>::get(),
beans::PropertyAttribute::MAYBEVOID, 0},
{ OUString("AutoTextMode"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("OrganizerMode"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
// #i28749# - Add property, which indicates, if the
// shape position attributes are given in horizontal left-to-right layout.
// This is the case for the OpenOffice.org file format.
{ OUString("ShapePositionInHoriL2R"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("BuildId"), 0,
::cppu::UnoType<OUString>::get(),
beans::PropertyAttribute::MAYBEVOID, 0 },
// Add property, which indicates, if a text document in OpenOffice.org
// file format is read.
// Note: Text documents read via the binary filter are also finally
// read using the OpenOffice.org file format. Thus, e.g. for text
// documents in StarOffice 5.2 binary file format this property
// will be sal_True.
{ OUString("TextDocInOOoFileFormat"), 0,
::getBooleanCppuType(),
beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(),
::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString(), 0, css::uno::Type(), 0, 0 }
};
uno::Reference< beans::XPropertySet > xInfoSet(
comphelper::GenericPropertySet_CreateInstance(
new comphelper::PropertySetInfo( aInfoMap ) ) );
// get BuildId from parent container if available
uno::Reference< container::XChild > xChild( xModelComp, uno::UNO_QUERY );
if( xChild.is() )
{
uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
if( xParentSet.is() )
{
uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
const OUString sPropName("BuildId" );
if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
{
xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
}
}
}
// try to get an XStatusIndicator from the Medium
uno::Reference<task::XStatusIndicator> xStatusIndicator;
if (pDocSh->GetMedium())
{
SfxItemSet* pSet = pDocSh->GetMedium()->GetItemSet();
if (pSet)
{
const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
if (pItem)
{
pItem->GetValue() >>= xStatusIndicator;
}
}
}
// set progress range and start status indicator
sal_Int32 nProgressRange(1000000);
if (xStatusIndicator.is())
{
xStatusIndicator->start(SW_RESSTR(STR_STATSTR_SWGREAD), nProgressRange);
}
uno::Any aProgRange;
aProgRange <<= nProgressRange;
xInfoSet->setPropertyValue("ProgressRange", aProgRange);
Reference< container::XNameAccess > xLateInitSettings( document::NamedPropertyValues::create(xContext), UNO_QUERY_THROW );
beans::NamedValue aLateInitSettings( "LateInitSettings", makeAny( xLateInitSettings ) );
xInfoSet->setPropertyValue( "SourceStorage", Any( xStorage ) );
// prepare filter arguments, WARNING: the order is important!
Sequence<Any> aFilterArgs( 5 );
Any *pArgs = aFilterArgs.getArray();
*pArgs++ <<= xInfoSet;
*pArgs++ <<= xStatusIndicator;
*pArgs++ <<= xGraphicResolver;
*pArgs++ <<= xObjectResolver;
*pArgs++ <<= aLateInitSettings;
Sequence<Any> aEmptyArgs( 3 );
// cppcheck-suppress redundantAssignment
pArgs = aEmptyArgs.getArray();
*pArgs++ <<= xInfoSet;
*pArgs++ <<= xStatusIndicator;
// prepare for special modes
if( aOpt.IsFmtsOnly() )
{
sal_Int32 nCount =
(aOpt.IsFrmFmts() ? 1 : 0) +
(aOpt.IsPageDescs() ? 1 : 0) +
(aOpt.IsTxtFmts() ? 2 : 0) +
(aOpt.IsNumRules() ? 1 : 0);
Sequence< OUString> aFamiliesSeq( nCount );
OUString *pSeq = aFamiliesSeq.getArray();
if( aOpt.IsFrmFmts() )
// SFX_STYLE_FAMILY_FRAME;
*pSeq++ = "FrameStyles";
if( aOpt.IsPageDescs() )
// SFX_STYLE_FAMILY_PAGE;
*pSeq++ = "PageStyles";
if( aOpt.IsTxtFmts() )
{
// (SFX_STYLE_FAMILY_CHAR|SFX_STYLE_FAMILY_PARA);
*pSeq++ = "CharacterStyles";
*pSeq++ = "ParagraphStyles";
}
if( aOpt.IsNumRules() )
// SFX_STYLE_FAMILY_PSEUDO;
*pSeq++ = "NumberingStyles";
xInfoSet->setPropertyValue( "StyleInsertModeFamilies",
makeAny(aFamiliesSeq) );
sal_Bool bTmp = !aOpt.IsMerge();
Any aAny;
aAny.setValue( &bTmp, ::getBooleanCppuType() );
xInfoSet->setPropertyValue( "StyleInsertModeOverwrite", aAny );
}
else if( bInsertMode )
{
const uno::Reference<text::XTextRange> xInsertTextRange =
SwXTextRange::CreateXTextRange(rDoc, *rPaM.GetPoint(), 0);
xInfoSet->setPropertyValue( "TextInsertModeRange",
makeAny(xInsertTextRange) );
}
else
{
rPaM.GetBound(true).nContent.Assign(0, 0);
rPaM.GetBound(false).nContent.Assign(0, 0);
}
if( IsBlockMode() )
{
sal_Bool bTmp = sal_True;
Any aAny;
aAny.setValue( &bTmp, ::getBooleanCppuType() );
xInfoSet->setPropertyValue( "AutoTextMode", aAny );
}
if( IsOrganizerMode() )
{
sal_Bool bTmp = sal_True;
Any aAny;
aAny.setValue( &bTmp, ::getBooleanCppuType() );
xInfoSet->setPropertyValue( "OrganizerMode", aAny );
}
// Set base URI
// there is ambiguity which medium should be used here
// for now the own medium has a preference
SfxMedium* pMedDescrMedium = pMedium ? pMedium : pDocSh->GetMedium();
OSL_ENSURE( pMedDescrMedium, "There is no medium to get MediaDescriptor from!\n" );
xInfoSet->setPropertyValue( "BaseURI", makeAny( rBaseURL ) );
// TODO/LATER: separate links from usual embedded objects
OUString StreamPath;
if( SFX_CREATE_MODE_EMBEDDED == rDoc.GetDocShell()->GetCreateMode() )
{
if ( pMedDescrMedium && pMedDescrMedium->GetItemSet() )
{
const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
pMedDescrMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
if ( pDocHierarchItem )
StreamPath = pDocHierarchItem->GetValue();
}
else
{
StreamPath = "dummyObjectName";
}
if( !StreamPath.isEmpty() )
{
xInfoSet->setPropertyValue( "StreamRelPath", makeAny( StreamPath ) );
}
}
rDoc.acquire(); // prevent deletion
sal_uInt32 nRet = 0;
// save redline mode into import info property set
Any aAny;
sal_Bool bTmp;
const OUString sShowChanges("ShowChanges");
const OUString sRecordChanges("RecordChanges");
const OUString sRedlineProtectionKey("RedlineProtectionKey");
bTmp = IDocumentRedlineAccess::IsShowChanges( rDoc.GetRedlineMode() );
aAny.setValue( &bTmp, ::getBooleanCppuType() );
xInfoSet->setPropertyValue( sShowChanges, aAny );
bTmp = IDocumentRedlineAccess::IsRedlineOn(rDoc.GetRedlineMode());
aAny.setValue( &bTmp, ::getBooleanCppuType() );
xInfoSet->setPropertyValue( sRecordChanges, aAny );
aAny <<= rDoc.GetRedlinePassword();
xInfoSet->setPropertyValue( sRedlineProtectionKey, aAny );
// force redline mode to "none"
rDoc.SetRedlineMode_intern( nsRedlineMode_t::REDLINE_NONE );
const bool bOASIS = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
// #i28749# - set property <ShapePositionInHoriL2R>
{
const bool bShapePositionInHoriL2R = !bOASIS;
xInfoSet->setPropertyValue(
"ShapePositionInHoriL2R",
makeAny( bShapePositionInHoriL2R ) );
}
{
const bool bTextDocInOOoFileFormat = !bOASIS;
xInfoSet->setPropertyValue(
"TextDocInOOoFileFormat",
makeAny( bTextDocInOOoFileFormat ) );
}
sal_uInt32 nWarnRDF = 0;
if ( !(IsOrganizerMode() || IsBlockMode() || aOpt.IsFmtsOnly() ||
bInsertMode) )
{
// RDF metadata - must be read before styles/content
// N.B.: embedded documents have their own manifest.rdf!
try
{
const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(xModelComp,
uno::UNO_QUERY_THROW);
const uno::Reference<rdf::XURI> xBaseURI( ::sfx2::createBaseURI(
xContext, xStorage, rBaseURL, StreamPath) );
const uno::Reference<task::XInteractionHandler> xHandler(
pDocSh->GetMedium()->GetInteractionHandler() );
xDMA->loadMetadataFromStorage(xStorage, xBaseURI, xHandler);
}
catch (const lang::WrappedTargetException & e)
{
ucb::InteractiveAugmentedIOException iaioe;
if (e.TargetException >>= iaioe)
{
// import error that was not ignored by InteractionHandler!
nWarnRDF = ERR_SWG_READ_ERROR;
}
else
{
nWarnRDF = WARN_SWG_FEATURES_LOST; // uhh... something wrong?
}
}
catch (uno::Exception &)
{
nWarnRDF = WARN_SWG_FEATURES_LOST; // uhh... something went wrong?
}
}
// read storage streams
// #i103539#: always read meta.xml for generator
sal_uInt32 const nWarn = ReadThroughComponent(
xStorage, xModelComp, "meta.xml", "Meta.xml", xContext,
(bOASIS ? "com.sun.star.comp.Writer.XMLOasisMetaImporter"
: "com.sun.star.comp.Writer.XMLMetaImporter"),
aEmptyArgs, rName, false );
sal_uInt32 nWarn2 = 0;
if( !(IsOrganizerMode() || IsBlockMode() || aOpt.IsFmtsOnly() ||
bInsertMode) )
{
nWarn2 = ReadThroughComponent(
xStorage, xModelComp, "settings.xml", NULL, xContext,
(bOASIS ? "com.sun.star.comp.Writer.XMLOasisSettingsImporter"
: "com.sun.star.comp.Writer.XMLSettingsImporter"),
aFilterArgs, rName, false );
}
nRet = ReadThroughComponent(
xStorage, xModelComp, "styles.xml", NULL, xContext,
(bOASIS ? "com.sun.star.comp.Writer.XMLOasisStylesImporter"
: "com.sun.star.comp.Writer.XMLStylesImporter"),
aFilterArgs, rName, true );
if( !nRet && !(IsOrganizerMode() || aOpt.IsFmtsOnly()) )
nRet = ReadThroughComponent(
xStorage, xModelComp, "content.xml", "Content.xml", xContext,
(bOASIS ? "com.sun.star.comp.Writer.XMLOasisContentImporter"
: "com.sun.star.comp.Writer.XMLContentImporter"),
aFilterArgs, rName, true );
if( !(IsOrganizerMode() || IsBlockMode() || bInsertMode ||
aOpt.IsFmtsOnly() ) )
{
try
{
uno::Reference < io::XStream > xStm = xStorage->openStreamElement( "layout-cache", embed::ElementModes::READ );
SvStream* pStrm2 = utl::UcbStreamHelper::CreateStream( xStm );
if( !pStrm2->GetError() )
rDoc.ReadLayoutCache( *pStrm2 );
delete pStrm2;
}
catch ( uno::Exception& )
{
}
}
// Notify math objects
if( bInsertMode )
rDoc.PrtOLENotify( false );
else if ( rDoc.IsOLEPrtNotifyPending() )
rDoc.PrtOLENotify( true );
nRet = nRet ? nRet : (nWarn ? nWarn : (nWarn2 ? nWarn2 : nWarnRDF ) );
aOpt.ResetAllFmtsOnly();
// redline password
aAny = xInfoSet->getPropertyValue( sRedlineProtectionKey );
Sequence<sal_Int8> aKey;
aAny >>= aKey;
rDoc.SetRedlinePassword( aKey );
// restore redline mode from import info property set
sal_Int16 nRedlineMode = nsRedlineMode_t::REDLINE_SHOW_INSERT;
aAny = xInfoSet->getPropertyValue( sShowChanges );
if ( *(sal_Bool*)aAny.getValue() )
nRedlineMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
aAny = xInfoSet->getPropertyValue( sRecordChanges );
if ( *(sal_Bool*)aAny.getValue() || (aKey.getLength() > 0) )
nRedlineMode |= nsRedlineMode_t::REDLINE_ON;
else
nRedlineMode |= nsRedlineMode_t::REDLINE_NONE;
// ... restore redline mode
// (First set bogus mode to make sure the mode in SetRedlineMode()
// is different from it's previous mode.)
rDoc.SetRedlineMode_intern((RedlineMode_t)( ~nRedlineMode ));
rDoc.SetRedlineMode( (RedlineMode_t)( nRedlineMode ));
lcl_EnsureValidPam( rPaM ); // move Pam into valid content
if( pGraphicHelper )
SvXMLGraphicHelper::Destroy( pGraphicHelper );
xGraphicResolver = 0;
if( pObjectHelper )
SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
xObjectResolver = 0;
rDoc.release();
if ( !bOASIS )
{
// #i44177# - assure that for documents in OpenOffice.org
// file format the relation between outline numbering rule and styles is
// filled-up accordingly.
// Note: The OpenOffice.org file format, which has no content that applys
// a certain style, which is related to the outline numbering rule,
// has lost the information, that this certain style is related to
// the outline numbering rule.
// #i70748# - only for templates
if ( pMedium && pMedium->GetFilter() &&
pMedium->GetFilter()->IsOwnTemplateFormat() )
{
lcl_AdjustOutlineStylesForOOo( rDoc );
}
// Fix #i58251#: Unfortunately is the static default different to SO7 behaviour,
// so we have to set a dynamic default after importing SO7
rDoc.SetDefault( SfxBoolItem( RES_ROW_SPLIT, false ) );
}
rDoc.PropagateOutlineRule();
// #i62875#
if ( rDoc.get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && !docfunc::ExistsDrawObjs( rDoc ) )
{
rDoc.set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
}
// Convert all instances of <SdrOle2Obj> into <SdrGrafObj>, because the
// Writer doesn't support such objects.
lcl_ConvertSdrOle2ObjsToSdrGrafObjs( rDoc );
// set BuildId on XModel for later OLE object loading
if( xInfoSet.is() )
{
uno::Reference< beans::XPropertySet > xModelSet( xModelComp, uno::UNO_QUERY );
if( xModelSet.is() )
{
uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
const OUString sName("BuildId" );
if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sName) )
{
xModelSet->setPropertyValue( sName, xInfoSet->getPropertyValue(sName) );
}
}
}
if (xStatusIndicator.is())
{
xStatusIndicator->end();
}
rDoc.GetIStyleAccess().clearCaches(); // Clear Automatic-Style-Caches(shared_pointer!)
return nRet;
}
// read the sections of the document, which is equal to the medium.
// returns the count of it
size_t XMLReader::GetSectionList( SfxMedium& rMedium,
std::vector<OUString*>& rStrings ) const
{
uno::Reference< uno::XComponentContext > xContext =
comphelper::getProcessComponentContext();
uno::Reference < embed::XStorage > xStg2;
if( ( xStg2 = rMedium.GetStorage() ).is() )
{
try
{
xml::sax::InputSource aParserInput;
const OUString sDocName( "content.xml" );
aParserInput.sSystemId = sDocName;
uno::Reference < io::XStream > xStm = xStg2->openStreamElement( sDocName, embed::ElementModes::READ );
aParserInput.aInputStream = xStm->getInputStream();
// get filter
uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLSectionList( xContext, rStrings );
// connect parser and filter
uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
xParser->setDocumentHandler( xFilter );
// parse
xParser->parseStream( aParserInput );
}
catch( xml::sax::SAXParseException& )
{
// re throw ?
}
catch( xml::sax::SAXException& )
{
// re throw ?
}
catch( io::IOException& )
{
// re throw ?
}
catch( packages::WrongPasswordException& )
{
// re throw ?
}
}
return rStrings.size();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|