1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_sd.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "framework/ResourceId.hxx" 27cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 28cdf0e10cSrcweir #include "tools/SdGlobalResourceContainer.hxx" 29cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 30cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 31cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 32cdf0e10cSrcweir #include <rtl/ref.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace ::com::sun::star; 35cdf0e10cSrcweir using namespace ::com::sun::star::uno; 36cdf0e10cSrcweir using namespace ::com::sun::star::lang; 37cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 38cdf0e10cSrcweir using ::rtl::OUString; 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** When the USE_OPTIMIZATIONS symbol is defined then at some optimizations 41cdf0e10cSrcweir are activated that work only together with XResourceId objects that are 42cdf0e10cSrcweir implemented by the ResourceId class. For other implementations of when 43cdf0e10cSrcweir the USE_OPTIMIZATIONS symbol is not defined then alternative code is 44cdf0e10cSrcweir used instead. 45cdf0e10cSrcweir */ 46cdf0e10cSrcweir #define USE_OPTIMIZATIONS 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace sd { namespace framework { 49cdf0e10cSrcweir 50cdf0e10cSrcweir Reference<XInterface> SAL_CALL ResourceId_createInstance ( 51cdf0e10cSrcweir const Reference<XComponentContext>& rxContext) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir (void)rxContext; 54cdf0e10cSrcweir return Reference<XInterface>(static_cast<XWeak*>(new ::sd::framework::ResourceId())); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir ::rtl::OUString ResourceId_getImplementationName (void) throw(RuntimeException) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir return ::rtl::OUString( 63cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.framework.ResourceId")); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir 67cdf0e10cSrcweir 68cdf0e10cSrcweir 69cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL ResourceId_getSupportedServiceNames (void) 70cdf0e10cSrcweir throw (RuntimeException) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir static const ::rtl::OUString sServiceName( 73cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.ResourceId")); 74cdf0e10cSrcweir return Sequence<rtl::OUString>(&sServiceName, 1); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir 78cdf0e10cSrcweir 79cdf0e10cSrcweir 80cdf0e10cSrcweir //===== ResourceId ============================================================ 81cdf0e10cSrcweir 82cdf0e10cSrcweir WeakReference<util::XURLTransformer> ResourceId::mxURLTransformerWeak; 83cdf0e10cSrcweir 84cdf0e10cSrcweir ResourceId::ResourceId (void) 85cdf0e10cSrcweir : ResourceIdInterfaceBase(), 86cdf0e10cSrcweir maResourceURLs(0), 87cdf0e10cSrcweir mpURL() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir 94cdf0e10cSrcweir ResourceId::ResourceId ( 95cdf0e10cSrcweir const std::vector<OUString>& rResourceURLs) 96cdf0e10cSrcweir : ResourceIdInterfaceBase(), 97cdf0e10cSrcweir maResourceURLs(rResourceURLs), 98cdf0e10cSrcweir mpURL() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir ParseResourceURL(); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir ResourceId::ResourceId ( 107cdf0e10cSrcweir const OUString& rsResourceURL) 108cdf0e10cSrcweir : ResourceIdInterfaceBase(), 109cdf0e10cSrcweir maResourceURLs(1, rsResourceURL), 110cdf0e10cSrcweir mpURL() 111cdf0e10cSrcweir { 112cdf0e10cSrcweir // Handle the special case of an empty resource URL. 113cdf0e10cSrcweir if (rsResourceURL.getLength() == 0) 114cdf0e10cSrcweir maResourceURLs.clear(); 115cdf0e10cSrcweir ParseResourceURL(); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir 121cdf0e10cSrcweir ResourceId::ResourceId ( 122cdf0e10cSrcweir const OUString& rsResourceURL, 123cdf0e10cSrcweir const OUString& rsAnchorURL) 124cdf0e10cSrcweir : ResourceIdInterfaceBase(), 125cdf0e10cSrcweir maResourceURLs(2), 126cdf0e10cSrcweir mpURL() 127cdf0e10cSrcweir { 128cdf0e10cSrcweir maResourceURLs[0] = rsResourceURL; 129cdf0e10cSrcweir maResourceURLs[1] = rsAnchorURL; 130cdf0e10cSrcweir ParseResourceURL(); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir 134cdf0e10cSrcweir 135cdf0e10cSrcweir 136cdf0e10cSrcweir ResourceId::ResourceId ( 137cdf0e10cSrcweir const OUString& rsResourceURL, 138cdf0e10cSrcweir const ::std::vector<OUString>& rAnchorURLs) 139cdf0e10cSrcweir : ResourceIdInterfaceBase(), 140cdf0e10cSrcweir maResourceURLs(1+rAnchorURLs.size()), 141cdf0e10cSrcweir mpURL() 142cdf0e10cSrcweir { 143cdf0e10cSrcweir maResourceURLs[0] = rsResourceURL; 144cdf0e10cSrcweir for (sal_uInt32 nIndex=0; nIndex<rAnchorURLs.size(); ++nIndex) 145cdf0e10cSrcweir maResourceURLs[nIndex+1] = rAnchorURLs[nIndex]; 146cdf0e10cSrcweir ParseResourceURL(); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir 152cdf0e10cSrcweir ResourceId::ResourceId ( 153cdf0e10cSrcweir const OUString& rsResourceURL, 154cdf0e10cSrcweir const OUString& rsFirstAnchorURL, 155cdf0e10cSrcweir const Sequence<OUString>& rAnchorURLs) 156cdf0e10cSrcweir : ResourceIdInterfaceBase(), 157cdf0e10cSrcweir maResourceURLs(2+rAnchorURLs.getLength()), 158cdf0e10cSrcweir mpURL() 159cdf0e10cSrcweir { 160cdf0e10cSrcweir maResourceURLs[0] = rsResourceURL; 161cdf0e10cSrcweir maResourceURLs[1] = rsFirstAnchorURL; 162cdf0e10cSrcweir for (sal_Int32 nIndex=0; nIndex<rAnchorURLs.getLength(); ++nIndex) 163cdf0e10cSrcweir maResourceURLs[nIndex+2] = rAnchorURLs[nIndex]; 164cdf0e10cSrcweir ParseResourceURL(); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir ResourceId::~ResourceId (void) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir mpURL.reset(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir 177cdf0e10cSrcweir 178cdf0e10cSrcweir OUString SAL_CALL 179cdf0e10cSrcweir ResourceId::getResourceURL (void) 180cdf0e10cSrcweir throw(com::sun::star::uno::RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if (!maResourceURLs.empty()) 183cdf0e10cSrcweir return maResourceURLs[0]; 184cdf0e10cSrcweir else 185cdf0e10cSrcweir return OUString(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir 189cdf0e10cSrcweir 190cdf0e10cSrcweir 191cdf0e10cSrcweir util::URL SAL_CALL 192cdf0e10cSrcweir ResourceId::getFullResourceURL (void) 193cdf0e10cSrcweir throw(com::sun::star::uno::RuntimeException) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir if (mpURL.get() != NULL) 196cdf0e10cSrcweir return *mpURL; 197cdf0e10cSrcweir 198cdf0e10cSrcweir Reference<util::XURLTransformer> xURLTransformer (mxURLTransformerWeak); 199cdf0e10cSrcweir if (xURLTransformer.is() && !maResourceURLs.empty() ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir mpURL.reset(new util::URL); 202cdf0e10cSrcweir mpURL->Complete = maResourceURLs[0]; 203cdf0e10cSrcweir xURLTransformer->parseStrict(*mpURL); 204cdf0e10cSrcweir return *mpURL; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir util::URL aURL; 208cdf0e10cSrcweir if (!maResourceURLs.empty()) 209cdf0e10cSrcweir aURL.Complete = maResourceURLs[0]; 210cdf0e10cSrcweir return aURL; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215cdf0e10cSrcweir 216cdf0e10cSrcweir sal_Bool SAL_CALL 217cdf0e10cSrcweir ResourceId::hasAnchor (void) 218cdf0e10cSrcweir throw (RuntimeException) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir return maResourceURLs.size()>1; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir 226cdf0e10cSrcweir Reference<XResourceId> SAL_CALL 227cdf0e10cSrcweir ResourceId::getAnchor (void) 228cdf0e10cSrcweir throw (RuntimeException) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir ::rtl::Reference<ResourceId> rResourceId (new ResourceId()); 231cdf0e10cSrcweir const sal_Int32 nAnchorCount (maResourceURLs.size()-1); 232cdf0e10cSrcweir if (nAnchorCount > 0) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir rResourceId->maResourceURLs.resize(nAnchorCount); 235cdf0e10cSrcweir for (sal_Int32 nIndex=0; nIndex<nAnchorCount; ++nIndex) 236cdf0e10cSrcweir rResourceId->maResourceURLs[nIndex] = maResourceURLs[nIndex+1]; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir return Reference<XResourceId>(rResourceId.get()); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir 242cdf0e10cSrcweir 243cdf0e10cSrcweir 244cdf0e10cSrcweir Sequence<OUString> SAL_CALL 245cdf0e10cSrcweir ResourceId::getAnchorURLs (void) 246cdf0e10cSrcweir throw (RuntimeException) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir const sal_Int32 nAnchorCount (maResourceURLs.size() - 1); 249cdf0e10cSrcweir if (nAnchorCount > 0) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir Sequence<OUString> aAnchorURLs (nAnchorCount); 252cdf0e10cSrcweir for (sal_Int32 nIndex=0; nIndex<nAnchorCount; ++nIndex) 253cdf0e10cSrcweir aAnchorURLs[nIndex] = maResourceURLs[nIndex+1]; 254cdf0e10cSrcweir return aAnchorURLs; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir else 257cdf0e10cSrcweir return Sequence<OUString>(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir 261cdf0e10cSrcweir 262cdf0e10cSrcweir 263cdf0e10cSrcweir OUString SAL_CALL 264cdf0e10cSrcweir ResourceId::getResourceTypePrefix (void) 265cdf0e10cSrcweir throw (RuntimeException) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir if (!maResourceURLs.empty() ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // Return the "private:resource/<type>/" prefix. 270cdf0e10cSrcweir 271cdf0e10cSrcweir // Get the the prefix that ends with the second "/". 272cdf0e10cSrcweir const OUString& rsResourceURL (maResourceURLs[0]); 273cdf0e10cSrcweir sal_Int32 nPrefixEnd (rsResourceURL.indexOf(sal_Unicode('/'), 0)); 274cdf0e10cSrcweir if (nPrefixEnd >= 0) 275cdf0e10cSrcweir nPrefixEnd = rsResourceURL.indexOf(sal_Unicode('/'), nPrefixEnd+1) + 1; 276cdf0e10cSrcweir else 277cdf0e10cSrcweir nPrefixEnd = 0; 278cdf0e10cSrcweir 279cdf0e10cSrcweir return rsResourceURL.copy(0,nPrefixEnd); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir else 282cdf0e10cSrcweir return OUString(); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir 286cdf0e10cSrcweir 287cdf0e10cSrcweir 288cdf0e10cSrcweir sal_Int16 SAL_CALL 289cdf0e10cSrcweir ResourceId::compareTo (const Reference<XResourceId>& rxResourceId) 290cdf0e10cSrcweir throw (RuntimeException) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir sal_Int16 nResult (0); 293cdf0e10cSrcweir 294cdf0e10cSrcweir if ( ! rxResourceId.is()) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir // The empty reference is interpreted as empty resource id object. 297cdf0e10cSrcweir if (!maResourceURLs.empty()) 298cdf0e10cSrcweir nResult = +1; 299cdf0e10cSrcweir else 300cdf0e10cSrcweir nResult = 0; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir else 303cdf0e10cSrcweir { 304cdf0e10cSrcweir ResourceId* pId = NULL; 305cdf0e10cSrcweir #ifdef USE_OPTIMIZATIONS 306cdf0e10cSrcweir pId = dynamic_cast<ResourceId*>(rxResourceId.get()); 307cdf0e10cSrcweir #endif 308cdf0e10cSrcweir if (pId != NULL) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir // We have direct access to the implementation of the given 311cdf0e10cSrcweir // resource id object. 312cdf0e10cSrcweir nResult = CompareToLocalImplementation(*pId); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir else 315cdf0e10cSrcweir { 316cdf0e10cSrcweir // We have to do the comparison via the UNO interface of the 317cdf0e10cSrcweir // given resource id object. 318cdf0e10cSrcweir nResult = CompareToExternalImplementation(rxResourceId); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir return nResult; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir 326cdf0e10cSrcweir 327cdf0e10cSrcweir 328cdf0e10cSrcweir sal_Int16 ResourceId::CompareToLocalImplementation (const ResourceId& rId) const 329cdf0e10cSrcweir { 330cdf0e10cSrcweir sal_Int16 nResult (0); 331cdf0e10cSrcweir 332cdf0e10cSrcweir const sal_uInt32 nLocalURLCount (maResourceURLs.size()); 333cdf0e10cSrcweir const sal_uInt32 nURLCount(rId.maResourceURLs.size()); 334cdf0e10cSrcweir 335cdf0e10cSrcweir // Start comparison with the top most anchors. 336cdf0e10cSrcweir for (sal_Int32 nIndex=nURLCount-1,nLocalIndex=nLocalURLCount-1; 337cdf0e10cSrcweir nIndex>=0 && nLocalIndex>=0; 338cdf0e10cSrcweir --nIndex,--nLocalIndex) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir const OUString sLocalURL (maResourceURLs[nLocalIndex]); 341cdf0e10cSrcweir const OUString sURL (rId.maResourceURLs[nIndex]); 342cdf0e10cSrcweir const sal_Int32 nLocalResult (sURL.compareTo(sLocalURL)); 343cdf0e10cSrcweir if (nLocalResult != 0) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir if (nLocalResult < 0) 346cdf0e10cSrcweir nResult = -1; 347cdf0e10cSrcweir else 348cdf0e10cSrcweir nResult = +1; 349cdf0e10cSrcweir break; 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir if (nResult == 0) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir // No difference found yet. When the lengths are the same then the 356cdf0e10cSrcweir // two resource ids are equivalent. Otherwise the shorter comes 357cdf0e10cSrcweir // first. 358cdf0e10cSrcweir if (nLocalURLCount != nURLCount) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir if (nLocalURLCount < nURLCount) 361cdf0e10cSrcweir nResult = -1; 362cdf0e10cSrcweir else 363cdf0e10cSrcweir nResult = +1; 364cdf0e10cSrcweir } 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir return nResult; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir 371cdf0e10cSrcweir 372cdf0e10cSrcweir 373cdf0e10cSrcweir sal_Int16 ResourceId::CompareToExternalImplementation (const Reference<XResourceId>& rxId) const 374cdf0e10cSrcweir { 375cdf0e10cSrcweir sal_Int16 nResult (0); 376cdf0e10cSrcweir 377cdf0e10cSrcweir const Sequence<OUString> aAnchorURLs (rxId->getAnchorURLs()); 378cdf0e10cSrcweir const sal_uInt32 nLocalURLCount (maResourceURLs.size()); 379cdf0e10cSrcweir const sal_uInt32 nURLCount(1+aAnchorURLs.getLength()); 380cdf0e10cSrcweir 381cdf0e10cSrcweir // Start comparison with the top most anchors. 382cdf0e10cSrcweir sal_Int32 nLocalResult (0); 383cdf0e10cSrcweir for (sal_Int32 nIndex=nURLCount-1,nLocalIndex=nLocalURLCount-1; 384cdf0e10cSrcweir nIndex>=0&&nLocalIndex>=0; 385cdf0e10cSrcweir --nIndex,--nLocalIndex) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir if (nIndex == 0 ) 388cdf0e10cSrcweir nLocalResult = maResourceURLs[nIndex].compareTo(rxId->getResourceURL()); 389cdf0e10cSrcweir else 390cdf0e10cSrcweir nLocalResult = maResourceURLs[nIndex].compareTo(aAnchorURLs[nIndex-1]); 391cdf0e10cSrcweir if (nLocalResult != 0) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir if (nLocalResult < 0) 394cdf0e10cSrcweir nResult = -1; 395cdf0e10cSrcweir else 396cdf0e10cSrcweir nResult = +1; 397cdf0e10cSrcweir break; 398cdf0e10cSrcweir } 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir if (nResult == 0) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir // No difference found yet. When the lengths are the same then the 404cdf0e10cSrcweir // two resource ids are equivalent. Otherwise the shorter comes 405cdf0e10cSrcweir // first. 406cdf0e10cSrcweir if (nLocalURLCount != nURLCount) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir if (nLocalURLCount < nURLCount) 409cdf0e10cSrcweir nResult = -1; 410cdf0e10cSrcweir else 411cdf0e10cSrcweir nResult = +1; 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir return nResult; 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir 419cdf0e10cSrcweir 420cdf0e10cSrcweir 421cdf0e10cSrcweir sal_Bool SAL_CALL 422cdf0e10cSrcweir ResourceId::isBoundTo ( 423cdf0e10cSrcweir const Reference<XResourceId>& rxResourceId, 424cdf0e10cSrcweir AnchorBindingMode eMode) 425cdf0e10cSrcweir throw (RuntimeException) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir if ( ! rxResourceId.is()) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir // An empty reference is interpreted as empty resource id. 430cdf0e10cSrcweir return IsBoundToAnchor(NULL, NULL, eMode); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir ResourceId* pId = NULL; 434cdf0e10cSrcweir #ifdef USE_OPTIMIZATIONS 435cdf0e10cSrcweir pId = dynamic_cast<ResourceId*>(rxResourceId.get()); 436cdf0e10cSrcweir #endif 437cdf0e10cSrcweir if (pId != NULL) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir return IsBoundToAnchor(pId->maResourceURLs, eMode); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir else 442cdf0e10cSrcweir { 443cdf0e10cSrcweir const OUString sResourceURL (rxResourceId->getResourceURL()); 444cdf0e10cSrcweir const Sequence<OUString> aAnchorURLs (rxResourceId->getAnchorURLs()); 445cdf0e10cSrcweir return IsBoundToAnchor(&sResourceURL, &aAnchorURLs, eMode); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir 450cdf0e10cSrcweir 451cdf0e10cSrcweir 452cdf0e10cSrcweir sal_Bool SAL_CALL 453cdf0e10cSrcweir ResourceId::isBoundToURL ( 454cdf0e10cSrcweir const OUString& rsAnchorURL, 455cdf0e10cSrcweir AnchorBindingMode eMode) 456cdf0e10cSrcweir throw (RuntimeException) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir return IsBoundToAnchor(&rsAnchorURL, NULL, eMode); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir 461cdf0e10cSrcweir 462cdf0e10cSrcweir 463cdf0e10cSrcweir 464cdf0e10cSrcweir Reference<XResourceId> SAL_CALL 465cdf0e10cSrcweir ResourceId::clone (void) 466cdf0e10cSrcweir throw(RuntimeException) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir return new ResourceId(maResourceURLs); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir 472cdf0e10cSrcweir 473cdf0e10cSrcweir 474cdf0e10cSrcweir //----- XInitialization ------------------------------------------------------- 475cdf0e10cSrcweir 476cdf0e10cSrcweir void SAL_CALL ResourceId::initialize (const Sequence<Any>& aArguments) 477cdf0e10cSrcweir throw (RuntimeException) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir sal_uInt32 nCount (aArguments.getLength()); 480cdf0e10cSrcweir for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir OUString sResourceURL; 483cdf0e10cSrcweir if (aArguments[nIndex] >>= sResourceURL) 484cdf0e10cSrcweir maResourceURLs.push_back(sResourceURL); 485cdf0e10cSrcweir else 486cdf0e10cSrcweir { 487cdf0e10cSrcweir Reference<XResourceId> xAnchor; 488cdf0e10cSrcweir if (aArguments[nIndex] >>= xAnchor) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir if (xAnchor.is()) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir maResourceURLs.push_back(xAnchor->getResourceURL()); 493cdf0e10cSrcweir Sequence<OUString> aAnchorURLs (xAnchor->getAnchorURLs()); 494cdf0e10cSrcweir for (sal_Int32 nURLIndex=0; nURLIndex<aAnchorURLs.getLength(); ++nURLIndex) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir maResourceURLs.push_back(aAnchorURLs[nURLIndex]); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir } 500cdf0e10cSrcweir } 501cdf0e10cSrcweir } 502cdf0e10cSrcweir ParseResourceURL(); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir 506cdf0e10cSrcweir 507cdf0e10cSrcweir 508cdf0e10cSrcweir //----------------------------------------------------------------------------- 509cdf0e10cSrcweir 510cdf0e10cSrcweir /** When eMode is DIRECTLY then the anchor of the called object and the 511cdf0e10cSrcweir anchor represented by the given sequence of anchor URLs have to be 512cdf0e10cSrcweir identical. When eMode is RECURSIVE then the anchor of the called 513cdf0e10cSrcweir object has to start with the given anchor URLs. 514cdf0e10cSrcweir */ 515cdf0e10cSrcweir bool ResourceId::IsBoundToAnchor ( 516cdf0e10cSrcweir const OUString* psFirstAnchorURL, 517cdf0e10cSrcweir const Sequence<OUString>* paAnchorURLs, 518cdf0e10cSrcweir AnchorBindingMode eMode) const 519cdf0e10cSrcweir { 520cdf0e10cSrcweir const sal_uInt32 nLocalAnchorURLCount (maResourceURLs.size() - 1); 521cdf0e10cSrcweir const bool bHasFirstAnchorURL (psFirstAnchorURL!=NULL); 522cdf0e10cSrcweir const sal_uInt32 nAnchorURLCount ((bHasFirstAnchorURL?1:0) 523cdf0e10cSrcweir + (paAnchorURLs!=NULL ? paAnchorURLs->getLength() : 0)); 524cdf0e10cSrcweir 525cdf0e10cSrcweir // Check the lengths. 526cdf0e10cSrcweir if (nLocalAnchorURLCount<nAnchorURLCount || 527cdf0e10cSrcweir (eMode==AnchorBindingMode_DIRECT && nLocalAnchorURLCount!=nAnchorURLCount)) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir return false; 530cdf0e10cSrcweir } 531cdf0e10cSrcweir 532cdf0e10cSrcweir // Compare the nAnchorURLCount bottom-most anchor URLs of this resource 533cdf0e10cSrcweir // id and the given anchor. 534cdf0e10cSrcweir sal_uInt32 nOffset = 0; 535cdf0e10cSrcweir if (paAnchorURLs != NULL) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir sal_uInt32 nCount = paAnchorURLs->getLength(); 538cdf0e10cSrcweir while (nOffset < nCount) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir if ( ! maResourceURLs[nLocalAnchorURLCount - nOffset].equals( 541cdf0e10cSrcweir (*paAnchorURLs)[nCount - 1 - nOffset])) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir return false; 544cdf0e10cSrcweir } 545cdf0e10cSrcweir ++nOffset; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir if (bHasFirstAnchorURL) 549cdf0e10cSrcweir { 550cdf0e10cSrcweir if ( ! psFirstAnchorURL->equals(maResourceURLs[nLocalAnchorURLCount - nOffset])) 551cdf0e10cSrcweir return false; 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir return true; 555cdf0e10cSrcweir } 556cdf0e10cSrcweir 557cdf0e10cSrcweir 558cdf0e10cSrcweir 559cdf0e10cSrcweir 560cdf0e10cSrcweir bool ResourceId::IsBoundToAnchor ( 561cdf0e10cSrcweir const ::std::vector<OUString>& rAnchorURLs, 562cdf0e10cSrcweir AnchorBindingMode eMode) const 563cdf0e10cSrcweir { 564cdf0e10cSrcweir const sal_uInt32 nLocalAnchorURLCount (maResourceURLs.size() - 1); 565cdf0e10cSrcweir const sal_uInt32 nAnchorURLCount (rAnchorURLs.size()); 566cdf0e10cSrcweir 567cdf0e10cSrcweir // Check the lengths. 568cdf0e10cSrcweir if (nLocalAnchorURLCount<nAnchorURLCount || 569cdf0e10cSrcweir (eMode==AnchorBindingMode_DIRECT && nLocalAnchorURLCount!=nAnchorURLCount)) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir return false; 572cdf0e10cSrcweir } 573cdf0e10cSrcweir 574cdf0e10cSrcweir // Compare the nAnchorURLCount bottom-most anchor URLs of this resource 575cdf0e10cSrcweir // id and the given anchor. 576cdf0e10cSrcweir for (sal_uInt32 nOffset=0; nOffset<nAnchorURLCount; ++nOffset) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir if ( ! maResourceURLs[nLocalAnchorURLCount - nOffset].equals( 579cdf0e10cSrcweir rAnchorURLs[nAnchorURLCount - 1 - nOffset])) 580cdf0e10cSrcweir { 581cdf0e10cSrcweir return false; 582cdf0e10cSrcweir } 583cdf0e10cSrcweir } 584cdf0e10cSrcweir 585cdf0e10cSrcweir return true; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir 589cdf0e10cSrcweir 590cdf0e10cSrcweir 591cdf0e10cSrcweir void ResourceId::ParseResourceURL (void) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard (::osl::Mutex::getGlobalMutex()); 594cdf0e10cSrcweir Reference<util::XURLTransformer> xURLTransformer (mxURLTransformerWeak); 595cdf0e10cSrcweir if ( ! xURLTransformer.is()) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir // Create the URL transformer. 598cdf0e10cSrcweir Reference<lang::XMultiServiceFactory> xServiceManager ( 599cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()); 600cdf0e10cSrcweir xURLTransformer = Reference<util::XURLTransformer>( 601cdf0e10cSrcweir xServiceManager->createInstance( 602cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))), 603cdf0e10cSrcweir UNO_QUERY); 604cdf0e10cSrcweir mxURLTransformerWeak = xURLTransformer; 605cdf0e10cSrcweir SdGlobalResourceContainer::Instance().AddResource( 606cdf0e10cSrcweir Reference<XInterface>(xURLTransformer,UNO_QUERY)); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir if (xURLTransformer.is() && !maResourceURLs.empty() ) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir mpURL.reset(new util::URL); 612cdf0e10cSrcweir mpURL->Complete = maResourceURLs[0]; 613cdf0e10cSrcweir xURLTransformer->parseStrict(*mpURL); 614cdf0e10cSrcweir if (mpURL->Main == maResourceURLs[0]) 615cdf0e10cSrcweir mpURL.reset(); 616cdf0e10cSrcweir else 617cdf0e10cSrcweir maResourceURLs[0] = mpURL->Main; 618cdf0e10cSrcweir } 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir 622cdf0e10cSrcweir } } // end of namespace sd::framework 623