Files
libreoffice/sd/source/ui/framework/configuration/ResourceId.cxx

534 lines
16 KiB
C++
Raw Normal View History

/* -*- 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 "framework/ResourceId.hxx"
#include "framework/FrameworkHelper.hxx"
#include "tools/SdGlobalResourceContainer.hxx"
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <comphelper/processfactory.hxx>
#include <rtl/ref.hxx>
#include <facreg.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::drawing::framework;
/** When the USE_OPTIMIZATIONS symbol is defined then at some optimizations
are activated that work only together with XResourceId objects that are
implemented by the ResourceId class. For other implementations of when
the USE_OPTIMIZATIONS symbol is not defined then alternative code is
used instead.
*/
#define USE_OPTIMIZATIONS
namespace sd { namespace framework {
//===== ResourceId ============================================================
WeakReference<util::XURLTransformer> ResourceId::mxURLTransformerWeak;
ResourceId::ResourceId()
: ResourceIdInterfaceBase(),
maResourceURLs(0),
mpURL()
{
}
ResourceId::ResourceId (
const std::vector<OUString>& rResourceURLs)
: ResourceIdInterfaceBase(),
maResourceURLs(rResourceURLs),
mpURL()
{
ParseResourceURL();
}
ResourceId::ResourceId (
const OUString& rsResourceURL)
: ResourceIdInterfaceBase(),
maResourceURLs(1, rsResourceURL),
mpURL()
{
// Handle the special case of an empty resource URL.
if (rsResourceURL.isEmpty())
maResourceURLs.clear();
ParseResourceURL();
}
ResourceId::ResourceId (
const OUString& rsResourceURL,
const OUString& rsAnchorURL)
: ResourceIdInterfaceBase(),
maResourceURLs(2),
mpURL()
{
maResourceURLs[0] = rsResourceURL;
maResourceURLs[1] = rsAnchorURL;
ParseResourceURL();
}
ResourceId::ResourceId (
const OUString& rsResourceURL,
const OUString& rsFirstAnchorURL,
const Sequence<OUString>& rAnchorURLs)
: ResourceIdInterfaceBase(),
maResourceURLs(2+rAnchorURLs.getLength()),
mpURL()
{
maResourceURLs[0] = rsResourceURL;
maResourceURLs[1] = rsFirstAnchorURL;
for (sal_Int32 nIndex=0; nIndex<rAnchorURLs.getLength(); ++nIndex)
maResourceURLs[nIndex+2] = rAnchorURLs[nIndex];
ParseResourceURL();
}
ResourceId::~ResourceId()
{
mpURL.reset();
}
OUString SAL_CALL
ResourceId::getResourceURL()
throw(com::sun::star::uno::RuntimeException, std::exception)
{
if (!maResourceURLs.empty())
return maResourceURLs[0];
else
return OUString();
}
util::URL SAL_CALL
ResourceId::getFullResourceURL()
throw(com::sun::star::uno::RuntimeException, std::exception)
{
if (mpURL.get() != NULL)
return *mpURL;
Reference<util::XURLTransformer> xURLTransformer (mxURLTransformerWeak);
if (xURLTransformer.is() && !maResourceURLs.empty() )
{
mpURL.reset(new util::URL);
mpURL->Complete = maResourceURLs[0];
xURLTransformer->parseStrict(*mpURL);
return *mpURL;
}
util::URL aURL;
if (!maResourceURLs.empty())
aURL.Complete = maResourceURLs[0];
return aURL;
}
sal_Bool SAL_CALL
ResourceId::hasAnchor()
throw (RuntimeException, std::exception)
{
return maResourceURLs.size()>1;
}
Reference<XResourceId> SAL_CALL
ResourceId::getAnchor()
throw (RuntimeException, std::exception)
{
::rtl::Reference<ResourceId> rResourceId (new ResourceId());
const sal_Int32 nAnchorCount (maResourceURLs.size()-1);
if (nAnchorCount > 0)
{
rResourceId->maResourceURLs.resize(nAnchorCount);
for (sal_Int32 nIndex=0; nIndex<nAnchorCount; ++nIndex)
rResourceId->maResourceURLs[nIndex] = maResourceURLs[nIndex+1];
}
return Reference<XResourceId>(rResourceId.get());
}
Sequence<OUString> SAL_CALL
ResourceId::getAnchorURLs()
throw (RuntimeException, std::exception)
{
const sal_Int32 nAnchorCount (maResourceURLs.size() - 1);
if (nAnchorCount > 0)
{
Sequence<OUString> aAnchorURLs (nAnchorCount);
for (sal_Int32 nIndex=0; nIndex<nAnchorCount; ++nIndex)
aAnchorURLs[nIndex] = maResourceURLs[nIndex+1];
return aAnchorURLs;
}
else
return Sequence<OUString>();
}
OUString SAL_CALL
ResourceId::getResourceTypePrefix()
throw (RuntimeException, std::exception)
{
if (!maResourceURLs.empty() )
{
// Return the "private:resource/<type>/" prefix.
// Get the prefix that ends with the second "/".
const OUString& rsResourceURL (maResourceURLs[0]);
sal_Int32 nPrefixEnd (rsResourceURL.indexOf('/', 0));
if (nPrefixEnd >= 0)
nPrefixEnd = rsResourceURL.indexOf('/', nPrefixEnd+1) + 1;
else
nPrefixEnd = 0;
return rsResourceURL.copy(0,nPrefixEnd);
}
else
return OUString();
}
sal_Int16 SAL_CALL
ResourceId::compareTo (const Reference<XResourceId>& rxResourceId)
throw (RuntimeException, std::exception)
{
sal_Int16 nResult (0);
if ( ! rxResourceId.is())
{
// The empty reference is interpreted as empty resource id object.
if (!maResourceURLs.empty())
nResult = +1;
else
nResult = 0;
}
else
{
ResourceId* pId = NULL;
#ifdef USE_OPTIMIZATIONS
pId = dynamic_cast<ResourceId*>(rxResourceId.get());
#endif
if (pId != NULL)
{
// We have direct access to the implementation of the given
// resource id object.
nResult = CompareToLocalImplementation(*pId);
}
else
{
// We have to do the comparison via the UNO interface of the
// given resource id object.
nResult = CompareToExternalImplementation(rxResourceId);
}
}
return nResult;
}
sal_Int16 ResourceId::CompareToLocalImplementation (const ResourceId& rId) const
{
sal_Int16 nResult (0);
const sal_uInt32 nLocalURLCount (maResourceURLs.size());
const sal_uInt32 nURLCount(rId.maResourceURLs.size());
// Start comparison with the top most anchors.
for (sal_Int32 nIndex=nURLCount-1,nLocalIndex=nLocalURLCount-1;
nIndex>=0 && nLocalIndex>=0;
--nIndex,--nLocalIndex)
{
const OUString sLocalURL (maResourceURLs[nLocalIndex]);
const OUString sURL (rId.maResourceURLs[nIndex]);
const sal_Int32 nLocalResult (sURL.compareTo(sLocalURL));
if (nLocalResult != 0)
{
if (nLocalResult < 0)
nResult = -1;
else
nResult = +1;
break;
}
}
if (nResult == 0)
{
// No difference found yet. When the lengths are the same then the
// two resource ids are equivalent. Otherwise the shorter comes
// first.
if (nLocalURLCount != nURLCount)
CWS-TOOLING: integrate CWS cmcfixes51 2008-12-08 10:12:55 +0100 cmc r264975 : #i96203# protect with ifdefs to avoid unused symbol on mac 2008-12-05 12:23:47 +0100 cmc r264898 : CWS-TOOLING: rebase CWS cmcfixes51 to trunk@264807 (milestone: DEV300:m37) 2008-12-01 14:45:17 +0100 cmc r264606 : #i76655# ehlos apparently required 2008-11-28 17:49:30 +0100 cmc r264567 : #i96655# remove newly unused method 2008-11-28 10:41:28 +0100 cmc r264531 : #i96647# better ppc-bridges flushCode impl 2008-11-27 12:58:40 +0100 cmc r264478 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 12:32:49 +0100 cmc r264476 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 12:26:02 +0100 cmc r264475 : #i96655# redundant old table export helpers 2008-11-27 11:49:06 +0100 cmc r264473 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 11:38:35 +0100 cmc r264471 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 11:14:21 +0100 cmc r264467 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 11:06:22 +0100 cmc r264464 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:58:18 +0100 cmc r264462 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:41:44 +0100 cmc r264461 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:19:24 +0100 cmc r264460 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:13:39 +0100 cmc r264459 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:06:14 +0100 cmc r264458 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:59:54 +0100 cmc r264457 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:52:51 +0100 cmc r264456 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:48:26 +0100 cmc r264454 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:40:20 +0100 cmc r264452 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:35:26 +0100 cmc r264451 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:31:00 +0100 cmc r264450 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:24:08 +0100 cmc r264449 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 00:26:15 +0100 cmc r264443 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 00:21:01 +0100 cmc r264442 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 00:09:40 +0100 cmc r264441 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 23:51:56 +0100 cmc r264440 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 23:49:09 +0100 cmc r264439 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 18:09:54 +0100 cmc r264432 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 18:07:40 +0100 cmc r264431 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 17:28:02 +0100 cmc r264429 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 17:27:39 +0100 cmc r264428 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 17:18:36 +0100 cmc r264426 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 16:22:16 +0100 cmc r264415 : #i96624# make implicit braces and brackets explicit to avoid warnings 2008-11-26 16:00:23 +0100 cmc r264409 : #i90426# remove warnings from svtools 2008-11-26 15:59:17 +0100 cmc r264408 : #i90426# remove warnings 2008-11-26 15:47:32 +0100 cmc r264404 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:46:57 +0100 cmc r264394 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:19:50 +0100 cmc r264387 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:15:26 +0100 cmc r264386 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:11:26 +0100 cmc r264384 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 13:44:23 +0100 cmc r264380 : #i96084# comfirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 13:12:24 +0100 cmc r264372 : #i96604# silence new warnings 2008-11-26 12:35:02 +0100 cmc r264369 : #i96203# make qstarter work in 3-layer land 2008-11-26 12:33:04 +0100 cmc r264368 : #i96170# ensure gtypes are up and running
2008-12-11 07:05:03 +00:00
{
if (nLocalURLCount < nURLCount)
nResult = -1;
else
nResult = +1;
CWS-TOOLING: integrate CWS cmcfixes51 2008-12-08 10:12:55 +0100 cmc r264975 : #i96203# protect with ifdefs to avoid unused symbol on mac 2008-12-05 12:23:47 +0100 cmc r264898 : CWS-TOOLING: rebase CWS cmcfixes51 to trunk@264807 (milestone: DEV300:m37) 2008-12-01 14:45:17 +0100 cmc r264606 : #i76655# ehlos apparently required 2008-11-28 17:49:30 +0100 cmc r264567 : #i96655# remove newly unused method 2008-11-28 10:41:28 +0100 cmc r264531 : #i96647# better ppc-bridges flushCode impl 2008-11-27 12:58:40 +0100 cmc r264478 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 12:32:49 +0100 cmc r264476 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 12:26:02 +0100 cmc r264475 : #i96655# redundant old table export helpers 2008-11-27 11:49:06 +0100 cmc r264473 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 11:38:35 +0100 cmc r264471 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 11:14:21 +0100 cmc r264467 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 11:06:22 +0100 cmc r264464 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:58:18 +0100 cmc r264462 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:41:44 +0100 cmc r264461 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:19:24 +0100 cmc r264460 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:13:39 +0100 cmc r264459 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 10:06:14 +0100 cmc r264458 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:59:54 +0100 cmc r264457 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:52:51 +0100 cmc r264456 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:48:26 +0100 cmc r264454 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:40:20 +0100 cmc r264452 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:35:26 +0100 cmc r264451 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:31:00 +0100 cmc r264450 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 09:24:08 +0100 cmc r264449 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 00:26:15 +0100 cmc r264443 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 00:21:01 +0100 cmc r264442 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-27 00:09:40 +0100 cmc r264441 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 23:51:56 +0100 cmc r264440 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 23:49:09 +0100 cmc r264439 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 18:09:54 +0100 cmc r264432 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 18:07:40 +0100 cmc r264431 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 17:28:02 +0100 cmc r264429 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 17:27:39 +0100 cmc r264428 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 17:18:36 +0100 cmc r264426 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 16:22:16 +0100 cmc r264415 : #i96624# make implicit braces and brackets explicit to avoid warnings 2008-11-26 16:00:23 +0100 cmc r264409 : #i90426# remove warnings from svtools 2008-11-26 15:59:17 +0100 cmc r264408 : #i90426# remove warnings 2008-11-26 15:47:32 +0100 cmc r264404 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:46:57 +0100 cmc r264394 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:19:50 +0100 cmc r264387 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:15:26 +0100 cmc r264386 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 14:11:26 +0100 cmc r264384 : #i96084# confirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 13:44:23 +0100 cmc r264380 : #i96084# comfirm existing logic with explicit brackets to remove new gcc warnings 2008-11-26 13:12:24 +0100 cmc r264372 : #i96604# silence new warnings 2008-11-26 12:35:02 +0100 cmc r264369 : #i96203# make qstarter work in 3-layer land 2008-11-26 12:33:04 +0100 cmc r264368 : #i96170# ensure gtypes are up and running
2008-12-11 07:05:03 +00:00
}
}
return nResult;
}
sal_Int16 ResourceId::CompareToExternalImplementation (const Reference<XResourceId>& rxId) const
{
sal_Int16 nResult (0);
const Sequence<OUString> aAnchorURLs (rxId->getAnchorURLs());
const sal_uInt32 nLocalURLCount (maResourceURLs.size());
const sal_uInt32 nURLCount(1+aAnchorURLs.getLength());
// Start comparison with the top most anchors.
sal_Int32 nLocalResult (0);
for (sal_Int32 nIndex=nURLCount-1,nLocalIndex=nLocalURLCount-1;
nIndex>=0&&nLocalIndex>=0;
--nIndex,--nLocalIndex)
{
if (nIndex == 0 )
nLocalResult = maResourceURLs[nIndex].compareTo(rxId->getResourceURL());
else
nLocalResult = maResourceURLs[nIndex].compareTo(aAnchorURLs[nIndex-1]);
if (nLocalResult != 0)
{
if (nLocalResult < 0)
nResult = -1;
else
nResult = +1;
break;
}
}
if (nResult == 0)
{
// No difference found yet. When the lengths are the same then the
// two resource ids are equivalent. Otherwise the shorter comes
// first.
if (nLocalURLCount != nURLCount)
{
if (nLocalURLCount < nURLCount)
nResult = -1;
else
nResult = +1;
}
}
return nResult;
}
sal_Bool SAL_CALL
ResourceId::isBoundTo (
const Reference<XResourceId>& rxResourceId,
AnchorBindingMode eMode)
throw (RuntimeException, std::exception)
{
if ( ! rxResourceId.is())
{
// An empty reference is interpreted as empty resource id.
return IsBoundToAnchor(NULL, NULL, eMode);
}
ResourceId* pId = NULL;
#ifdef USE_OPTIMIZATIONS
pId = dynamic_cast<ResourceId*>(rxResourceId.get());
#endif
if (pId != NULL)
{
return IsBoundToAnchor(pId->maResourceURLs, eMode);
}
else
{
const OUString sResourceURL (rxResourceId->getResourceURL());
const Sequence<OUString> aAnchorURLs (rxResourceId->getAnchorURLs());
return IsBoundToAnchor(&sResourceURL, &aAnchorURLs, eMode);
}
}
sal_Bool SAL_CALL
ResourceId::isBoundToURL (
const OUString& rsAnchorURL,
AnchorBindingMode eMode)
throw (RuntimeException, std::exception)
{
return IsBoundToAnchor(&rsAnchorURL, NULL, eMode);
}
Reference<XResourceId> SAL_CALL
ResourceId::clone()
throw(RuntimeException, std::exception)
{
return new ResourceId(maResourceURLs);
}
//----- XInitialization -------------------------------------------------------
void SAL_CALL ResourceId::initialize (const Sequence<Any>& aArguments)
throw (RuntimeException, std::exception)
{
sal_uInt32 nCount (aArguments.getLength());
for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
{
OUString sResourceURL;
if (aArguments[nIndex] >>= sResourceURL)
maResourceURLs.push_back(sResourceURL);
else
{
Reference<XResourceId> xAnchor;
if (aArguments[nIndex] >>= xAnchor)
{
if (xAnchor.is())
{
maResourceURLs.push_back(xAnchor->getResourceURL());
Sequence<OUString> aAnchorURLs (xAnchor->getAnchorURLs());
for (sal_Int32 nURLIndex=0; nURLIndex<aAnchorURLs.getLength(); ++nURLIndex)
{
maResourceURLs.push_back(aAnchorURLs[nURLIndex]);
}
}
}
}
}
ParseResourceURL();
}
OUString ResourceId::getImplementationName()
throw (css::uno::RuntimeException, std::exception)
{
return OUString("com.sun.star.comp.Draw.framework.ResourceId");
}
sal_Bool ResourceId::supportsService(OUString const & ServiceName)
throw (css::uno::RuntimeException, std::exception)
{
return cppu::supportsService(this, ServiceName);
}
css::uno::Sequence<OUString> ResourceId::getSupportedServiceNames()
throw (css::uno::RuntimeException, std::exception)
{
return css::uno::Sequence<OUString>{
"com.sun.star.drawing.framework.ResourceId"};
}
/** When eMode is DIRECTLY then the anchor of the called object and the
anchor represented by the given sequence of anchor URLs have to be
identical. When eMode is RECURSIVE then the anchor of the called
object has to start with the given anchor URLs.
*/
bool ResourceId::IsBoundToAnchor (
const OUString* psFirstAnchorURL,
const Sequence<OUString>* paAnchorURLs,
AnchorBindingMode eMode) const
{
const sal_uInt32 nLocalAnchorURLCount (maResourceURLs.size() - 1);
const bool bHasFirstAnchorURL (psFirstAnchorURL!=NULL);
const sal_uInt32 nAnchorURLCount ((bHasFirstAnchorURL?1:0)
+ (paAnchorURLs!=NULL ? paAnchorURLs->getLength() : 0));
// Check the lengths.
if (nLocalAnchorURLCount<nAnchorURLCount ||
(eMode==AnchorBindingMode_DIRECT && nLocalAnchorURLCount!=nAnchorURLCount))
{
return false;
}
// Compare the nAnchorURLCount bottom-most anchor URLs of this resource
// id and the given anchor.
sal_uInt32 nOffset = 0;
if (paAnchorURLs != NULL)
{
sal_uInt32 nCount = paAnchorURLs->getLength();
while (nOffset < nCount)
{
if ( ! maResourceURLs[nLocalAnchorURLCount - nOffset].equals(
(*paAnchorURLs)[nCount - 1 - nOffset]))
{
return false;
}
++nOffset;
}
}
if (bHasFirstAnchorURL)
{
if ( ! psFirstAnchorURL->equals(maResourceURLs[nLocalAnchorURLCount - nOffset]))
return false;
}
return true;
}
bool ResourceId::IsBoundToAnchor (
const ::std::vector<OUString>& rAnchorURLs,
AnchorBindingMode eMode) const
{
const sal_uInt32 nLocalAnchorURLCount (maResourceURLs.size() - 1);
const sal_uInt32 nAnchorURLCount (rAnchorURLs.size());
// Check the lengths.
if (nLocalAnchorURLCount<nAnchorURLCount ||
(eMode==AnchorBindingMode_DIRECT && nLocalAnchorURLCount!=nAnchorURLCount))
{
return false;
}
// Compare the nAnchorURLCount bottom-most anchor URLs of this resource
// id and the given anchor.
for (sal_uInt32 nOffset=0; nOffset<nAnchorURLCount; ++nOffset)
{
if ( ! maResourceURLs[nLocalAnchorURLCount - nOffset].equals(
rAnchorURLs[nAnchorURLCount - 1 - nOffset]))
{
return false;
}
}
return true;
}
void ResourceId::ParseResourceURL()
{
::osl::Guard< ::osl::Mutex > aGuard (::osl::Mutex::getGlobalMutex());
Reference<util::XURLTransformer> xURLTransformer (mxURLTransformerWeak);
if ( ! xURLTransformer.is())
{
// Create the URL transformer.
Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
xURLTransformer = Reference<util::XURLTransformer>(util::URLTransformer::create(xContext));
mxURLTransformerWeak = xURLTransformer;
SdGlobalResourceContainer::Instance().AddResource(
Reference<XInterface>(xURLTransformer,UNO_QUERY));
}
if (xURLTransformer.is() && !maResourceURLs.empty() )
{
mpURL.reset(new util::URL);
mpURL->Complete = maResourceURLs[0];
xURLTransformer->parseStrict(*mpURL);
if (mpURL->Main == maResourceURLs[0])
mpURL.reset();
else
maResourceURLs[0] = mpURL->Main;
}
}
} } // end of namespace sd::framework
extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
com_sun_star_comp_Draw_framework_ResourceID_get_implementation(::com::sun::star::uno::XComponentContext*,
::com::sun::star::uno::Sequence<css::uno::Any> const &)
{
return cppu::acquire(new sd::framework::ResourceId());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */