1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 31 #include <tools/debug.hxx> 32 #include <com/sun/star/util/DateTime.hpp> 33 #include <com/sun/star/xml/sax/XAttributeList.hpp> 34 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 35 #include <com/sun/star/container/XNameContainer.hpp> 36 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp> 37 #include <com/sun/star/presentation/XPresentationSupplier.hpp> 38 #include <com/sun/star/container/XIndexContainer.hpp> 39 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> 40 #include <xmloff/xmltoken.hxx> 41 #include <comphelper/extract.hxx> 42 #include "xmloff/xmlnmspe.hxx" 43 #include <xmloff/nmspmap.hxx> 44 #include <xmloff/xmluconv.hxx> 45 #include "ximpshow.hxx" 46 47 using ::rtl::OUString; 48 using ::rtl::OUStringBuffer; 49 50 using namespace ::std; 51 using namespace ::cppu; 52 using namespace ::com::sun::star; 53 using namespace ::com::sun::star::xml; 54 using namespace ::com::sun::star::xml::sax; 55 using namespace ::com::sun::star::uno; 56 using namespace ::com::sun::star::drawing; 57 using namespace ::com::sun::star::beans; 58 using namespace ::com::sun::star::lang; 59 using namespace ::com::sun::star::util; 60 using namespace ::com::sun::star::container; 61 using namespace ::com::sun::star::presentation; 62 using namespace ::xmloff::token; 63 64 /////////////////////////////////////////////////////////////////////// 65 66 class ShowsImpImpl 67 { 68 public: 69 Reference< XSingleServiceFactory > mxShowFactory; 70 Reference< XNameContainer > mxShows; 71 Reference< XPropertySet > mxPresProps; 72 Reference< XNameAccess > mxPages; 73 OUString maCustomShowName; 74 SdXMLImport& mrImport; 75 76 ShowsImpImpl( SdXMLImport& rImport ) 77 : mrImport( rImport ) 78 {} 79 }; 80 81 /////////////////////////////////////////////////////////////////////// 82 83 TYPEINIT1( SdXMLShowsContext, SvXMLImportContext ); 84 85 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ) 86 : SvXMLImportContext(rImport, nPrfx, rLocalName) 87 { 88 mpImpl = new ShowsImpImpl( rImport ); 89 90 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY ); 91 if( xShowsSupplier.is() ) 92 { 93 mpImpl->mxShows = xShowsSupplier->getCustomPresentations(); 94 mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows ); 95 } 96 97 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY ); 98 if( xDrawPagesSupplier.is() ) 99 mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() ); 100 101 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY ); 102 if( xPresentationSupplier.is() ) 103 mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() ); 104 105 106 if( mpImpl->mxPresProps.is() ) 107 { 108 sal_Bool bAll = sal_True; 109 uno::Any aAny; 110 111 // read attributes 112 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 113 for(sal_Int16 i=0; i < nAttrCount; i++) 114 { 115 OUString sAttrName = xAttrList->getNameByIndex( i ); 116 OUString aLocalName; 117 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 118 OUString sValue = xAttrList->getValueByIndex( i ); 119 120 switch( nPrefix ) 121 { 122 case XML_NAMESPACE_PRESENTATION: 123 if( IsXMLToken( aLocalName, XML_START_PAGE ) ) 124 { 125 aAny <<= sValue; 126 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPage" ) ), aAny ); 127 bAll = sal_False; 128 } 129 else if( IsXMLToken( aLocalName, XML_SHOW ) ) 130 { 131 mpImpl->maCustomShowName = sValue; 132 bAll = sal_False; 133 } 134 else if( IsXMLToken( aLocalName, XML_PAUSE ) ) 135 { 136 DateTime aTime; 137 if( !SvXMLUnitConverter::convertTime( aTime, sValue ) ) 138 continue; 139 140 const sal_Int32 nMS = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds; 141 aAny <<= nMS; 142 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ), aAny ); 143 } 144 else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) ) 145 { 146 aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) ); 147 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowAnimations" ) ), aAny ); 148 } 149 else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) ) 150 { 151 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 152 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAlwaysOnTop" ) ), aAny ); 153 } 154 else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) ) 155 { 156 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 157 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ), aAny ); 158 } 159 else if( IsXMLToken( aLocalName, XML_ENDLESS ) ) 160 { 161 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 162 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEndless" ) ), aAny ); 163 } 164 else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) ) 165 { 166 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 167 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), aAny ); 168 } 169 else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) ) 170 { 171 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 172 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsMouseVisible" ) ), aAny ); 173 } 174 else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) ) 175 { 176 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 177 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "StartWithNavigator" ) ), aAny ); 178 } 179 else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) ) 180 { 181 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 182 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "UsePen" ) ), aAny ); 183 } 184 else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) ) 185 { 186 aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) ); 187 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTransitionOnClick" ) ), aAny ); 188 } 189 else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) ) 190 { 191 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) ); 192 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowLogo" ) ), aAny ); 193 } 194 } 195 } 196 aAny = bool2any( bAll ); 197 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowAll" ) ), aAny ); 198 } 199 } 200 201 SdXMLShowsContext::~SdXMLShowsContext() 202 { 203 if( mpImpl && mpImpl->maCustomShowName.getLength() ) 204 { 205 uno::Any aAny; 206 aAny <<= mpImpl->maCustomShowName; 207 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomShow" ) ), aAny ); 208 } 209 210 delete mpImpl; 211 } 212 213 SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList ) 214 { 215 if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) ) 216 { 217 OUString aName; 218 OUString aPages; 219 220 // read attributes 221 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 222 for(sal_Int16 i=0; i < nAttrCount; i++) 223 { 224 OUString sAttrName = xAttrList->getNameByIndex( i ); 225 OUString aLocalName; 226 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 227 OUString sValue = xAttrList->getValueByIndex( i ); 228 229 switch( nPrefix ) 230 { 231 case XML_NAMESPACE_PRESENTATION: 232 if( IsXMLToken( aLocalName, XML_NAME ) ) 233 { 234 aName = sValue; 235 } 236 else if( IsXMLToken( aLocalName, XML_PAGES ) ) 237 { 238 aPages = sValue; 239 } 240 } 241 } 242 243 if( aName.getLength() != 0 && aPages.getLength() != 0 ) 244 { 245 Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY ); 246 if( xShow.is() ) 247 { 248 SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') ); 249 OUString sPageName; 250 Any aAny; 251 252 while( aPageNames.getNextToken( sPageName ) ) 253 { 254 if( !mpImpl->mxPages->hasByName( sPageName ) ) 255 continue; 256 257 Reference< XDrawPage > xPage; 258 mpImpl->mxPages->getByName( sPageName ) >>= xPage; 259 if( xPage.is() ) 260 { 261 aAny <<= xPage; 262 xShow->insertByIndex( xShow->getCount(), aAny ); 263 } 264 } 265 266 aAny <<= xShow; 267 268 if( mpImpl->mxShows->hasByName( aName ) ) 269 { 270 mpImpl->mxShows->replaceByName( aName, aAny ); 271 } 272 else 273 { 274 mpImpl->mxShows->insertByName( aName, aAny ); 275 } 276 } 277 } 278 } 279 280 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); 281 } 282 283