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