summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sot/source/sdstor/ucbstorage.cxx1
-rw-r--r--svl/source/fsstor/fsstorage.cxx1
-rw-r--r--svtools/source/contnr/templwin.cxx7
-rw-r--r--svtools/source/control/inettbc.cxx9
-rw-r--r--unotools/inc/unotools/ucbhelper.hxx91
-rw-r--r--unotools/source/ucbhelper/ucbhelper.cxx995
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx15
7 files changed, 465 insertions, 654 deletions
diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx
index d0b353450b5d..b6fb581057fc 100644
--- a/sot/source/sdstor/ucbstorage.cxx
+++ b/sot/source/sdstor/ucbstorage.cxx
@@ -32,6 +32,7 @@
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <ucbhelper/content.hxx>
#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/ucb/NameClash.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <unotools/tempfile.hxx>
#include <unotools/ucbstreamhelper.hxx>
diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx
index 7617563eff99..4fbc78023184 100644
--- a/svl/source/fsstor/fsstorage.cxx
+++ b/svl/source/fsstor/fsstorage.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/ucb/NameClash.hpp>
#include <com/sun/star/ucb/XProgressHandler.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
diff --git a/svtools/source/contnr/templwin.cxx b/svtools/source/contnr/templwin.cxx
index 00623c3a6437..3792826ee571 100644
--- a/svtools/source/contnr/templwin.cxx
+++ b/svtools/source/contnr/templwin.cxx
@@ -236,10 +236,9 @@ void ODocumentInfoPreview::fill(
// size
if ( i_rURL.Len() > 0 )
{
- sal_uLong nDocSize = ::utl::UCBContentHelper::GetSize( i_rURL );
m_pEditWin->InsertEntry(
m_pInfoTable->GetString( DI_SIZE ),
- CreateExactSizeText_Impl( nDocSize ) );
+ CreateExactSizeText_Impl( utl::UCBContentHelper::GetSize( i_rURL ) ) );
}
// MIMEType
@@ -749,8 +748,8 @@ sal_Bool SvtFileViewWindow_Impl::HasPreviousLevel( String& rURL ) const
String SvtFileViewWindow_Impl::GetFolderTitle() const
{
- String aTitle;
- ::utl::UCBContentHelper::GetTitle( aFolderURL, aTitle );
+ rtl::OUString aTitle;
+ ::utl::UCBContentHelper::GetTitle( aFolderURL, &aTitle );
return aTitle;
}
diff --git a/svtools/source/control/inettbc.cxx b/svtools/source/control/inettbc.cxx
index 9ed13a1c674d..21547e3389c2 100644
--- a/svtools/source/control/inettbc.cxx
+++ b/svtools/source/control/inettbc.cxx
@@ -1200,7 +1200,7 @@ String SvtURLBox::GetURL()
Any aAny =
UCBContentHelper::GetProperty(aURL,aPropName);
sal_Bool success = (aAny >>= aFileURL);
- String aTitle;
+ rtl::OUString aTitle;
if(success)
aTitle = String(
INetURLObject(aFileURL).getName(
@@ -1209,12 +1209,11 @@ String SvtURLBox::GetURL()
INetURLObject::DECODE_WITH_CHARSET ));
else
success =
- UCBContentHelper::GetTitle(aURL,aTitle);
+ UCBContentHelper::GetTitle(aURL,&aTitle);
if( success &&
- ( aTitle.Len() > 1 ||
- (aTitle.CompareToAscii("/") != 0 &&
- aTitle.CompareToAscii(".") != 0) ) )
+ !(aTitle.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("/"))
+ || aTitle.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("."))) )
{
aObj.SetName( aTitle );
if ( bSlash )
diff --git a/unotools/inc/unotools/ucbhelper.hxx b/unotools/inc/unotools/ucbhelper.hxx
index b0ed12a57ecc..358d8e119c60 100644
--- a/unotools/inc/unotools/ucbhelper.hxx
+++ b/unotools/inc/unotools/ucbhelper.hxx
@@ -25,55 +25,58 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-#include "unotools/unotoolsdllapi.h"
#ifndef _UNOTOOLS_UCBHELPER_HXX
#define _UNOTOOLS_UCBHELPER_HXX
-// include ---------------------------------------------------------------
-#include <com/sun/star/uno/Sequence.hxx>
-#include <com/sun/star/uno/Reference.hxx>
-#include <com/sun/star/ucb/NameClash.hpp>
-#include <com/sun/star/ucb/XContentProvider.hpp>
-
-#include <tools/string.hxx>
-
-namespace ucbhelper
-{
- class Content;
-}
-
-namespace utl
-{
- class UNOTOOLS_DLLPUBLIC UCBContentHelper
- {
- public:
- static sal_Bool IsDocument( const String& rContent );
- static sal_Bool IsFolder( const String& rContent );
- static sal_Bool GetTitle( const String& rContent, String& rTitle );
- static sal_Bool Kill( const String& rContent );
-
- static ::com::sun::star::uno::Any GetProperty( const String& rURL, const ::rtl::OUString& rName );
-
- static ::com::sun::star::uno::Sequence< ::rtl::OUString >
- GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted = sal_False );
-
- static sal_Bool MakeFolder( const String& rFolder, sal_Bool bNewOnly = sal_False );
- static sal_Bool MakeFolder( ::ucbhelper::Content& rParent,
- const String& rTitle,
- ::ucbhelper::Content& rNewFolder,
- sal_Bool bNewOnly = sal_False );
-
- static sal_uLong GetSize( const String& rContent );
- static sal_Bool IsYounger( const String& rIsYoung, const String& rIsOlder );
-
- static sal_Bool Exists( const String& rContent );
- static sal_Bool IsSubPath( const ::rtl::OUString& rPath, const ::rtl::OUString& rChildCandidate, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProvider >& xContentProvider = ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProvider >() );
- static sal_Bool EqualURLs( const ::rtl::OUString& aFirstURL, const ::rtl::OUString& aSecondURL );
- };
-}
+#include "sal/config.h"
-#endif
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+#include "unotools/unotoolsdllapi.h"
+
+namespace com { namespace sun { namespace star { namespace uno {
+ class Any;
+} } } }
+namespace rtl { class OUString; }
+namespace ucbhelper { class Content; }
+
+namespace utl { namespace UCBContentHelper {
+
+UNOTOOLS_DLLPUBLIC bool IsDocument(rtl::OUString const & url);
+
+UNOTOOLS_DLLPUBLIC bool IsFolder(rtl::OUString const & url);
+
+UNOTOOLS_DLLPUBLIC bool GetTitle(
+ rtl::OUString const & url, rtl::OUString * title);
+
+UNOTOOLS_DLLPUBLIC bool Kill(rtl::OUString const & url);
+
+UNOTOOLS_DLLPUBLIC com::sun::star::uno::Any GetProperty(
+ rtl::OUString const & url, rtl::OUString const & property);
+UNOTOOLS_DLLPUBLIC bool MakeFolder(
+ rtl::OUString const & url, bool exclusive = false);
+
+UNOTOOLS_DLLPUBLIC bool MakeFolder(
+ ucbhelper::Content & parent, rtl::OUString const & title,
+ ucbhelper::Content & result, bool exclusive = false);
+
+UNOTOOLS_DLLPUBLIC sal_Int64 GetSize(rtl::OUString const & url);
+
+UNOTOOLS_DLLPUBLIC bool IsYounger(
+ rtl::OUString const & younger, rtl::OUString const & older);
+
+UNOTOOLS_DLLPUBLIC bool Exists(rtl::OUString const & url);
+
+UNOTOOLS_DLLPUBLIC bool IsSubPath(
+ rtl::OUString const & parent, rtl::OUString const & child);
+
+UNOTOOLS_DLLPUBLIC bool EqualURLs(
+ rtl::OUString const & url1, rtl::OUString const & url2);
+
+} }
+
+#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/source/ucbhelper/ucbhelper.cxx b/unotools/source/ucbhelper/ucbhelper.cxx
index 950572115b3a..137d170b808a 100644
--- a/unotools/source/ucbhelper/ucbhelper.cxx
+++ b/unotools/source/ucbhelper/ucbhelper.cxx
@@ -26,657 +26,478 @@
*
************************************************************************/
+#include "sal/config.h"
-#include "unotools/ucbhelper.hxx"
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/sdbc/XResultSet.hpp>
-#include <com/sun/star/sdbc/XRow.hpp>
-#include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
-#include <com/sun/star/ucb/XCommandProcessor.hpp>
-#include <com/sun/star/ucb/CommandAbortedException.hpp>
-#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
-#include <com/sun/star/ucb/NameClashException.hpp>
-#include <com/sun/star/ucb/NameClash.hpp>
-#include <com/sun/star/ucb/NumberedSortingInfo.hpp>
-#include <com/sun/star/ucb/TransferInfo.hpp>
-#include <com/sun/star/ucb/XAnyCompareFactory.hpp>
-#include <com/sun/star/ucb/XCommandInfo.hpp>
-#include <com/sun/star/ucb/XContentAccess.hpp>
-#include <com/sun/star/ucb/ContentInfo.hpp>
-#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
-#include <com/sun/star/ucb/XDynamicResultSet.hpp>
-#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
-#include <com/sun/star/util/DateTime.hpp>
-#include <com/sun/star/container/XChild.hpp>
-#include <com/sun/star/ucb/InteractiveIOException.hpp>
-#include <com/sun/star/task/XInteractionHandler.hpp>
-#include <ucbhelper/commandenvironment.hxx>
-#include <ucbhelper/content.hxx>
-#include <comphelper/processfactory.hxx>
-#include <osl/file.hxx>
-
-#include <tools/wldcrd.hxx>
-#include <tools/ref.hxx>
-#include <tools/debug.hxx>
-#include <tools/urlobj.hxx>
-#include <tools/datetime.hxx>
-#include <ucbhelper/contentbroker.hxx>
-
-#include "unotools/localfilehelper.hxx"
+#include <cassert>
#include <vector>
-using namespace ucbhelper;
-using namespace com::sun::star;
-using namespace com::sun::star::beans;
-using namespace com::sun::star::container;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::sdbc;
-using namespace com::sun::star::task;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::ucb;
-using namespace comphelper;
-using namespace osl;
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/sdbc/XResultSet.hpp"
+#include "com/sun/star/task/XInteractionHandler.hpp"
+#include "com/sun/star/ucb/CommandAbortedException.hpp"
+#include "com/sun/star/ucb/ContentInfo.hpp"
+#include "com/sun/star/ucb/ContentInfoAttribute.hpp"
+#include "com/sun/star/ucb/IOErrorCode.hpp"
+#include "com/sun/star/ucb/InteractiveIOException.hpp"
+#include "com/sun/star/ucb/NameClashException.hpp"
+#include "com/sun/star/ucb/XCommandEnvironment.hpp"
+#include "com/sun/star/ucb/XContentAccess.hpp"
+#include "com/sun/star/ucb/XContentIdentifier.hpp"
+#include "com/sun/star/ucb/XContentIdentifierFactory.hpp"
+#include "com/sun/star/ucb/XProgressHandler.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/util/DateTime.hpp"
+#include "comphelper/processfactory.hxx"
+#include "cppuhelper/exc_hlp.hxx"
+#include "osl/file.hxx"
+#include "rtl/oustringostreaminserter.hxx"
+#include "rtl/string.h"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "sal/log.hxx"
+#include "sal/types.h"
+#include "tools/datetime.hxx"
+#include "tools/urlobj.hxx"
+#include "ucbhelper/commandenvironment.hxx"
+#include "ucbhelper/content.hxx"
+#include "ucbhelper/contentbroker.hxx"
+#include "unotools/localfilehelper.hxx"
+#include "unotools/ucbhelper.hxx"
-using ::rtl::OUString;
+namespace {
-typedef ::std::vector< OUString* > StringList_Impl;
+namespace css = com::sun::star;
-#define CONVERT_DATETIME( aUnoDT, aToolsDT ) \
- aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \
- Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) );
+rtl::OUString canonic(rtl::OUString const & url) {
+ INetURLObject o(url);
+ SAL_WARN_IF(o.HasError(), "unotools", "Invalid URL \"" << url << '"');
+ return o.GetMainURL(INetURLObject::NO_DECODE);
+}
-namespace utl
-{
+ucbhelper::Content content(rtl::OUString const & url) {
+ return ucbhelper::Content(
+ canonic(url),
+ css::uno::Reference<css::ucb::XCommandEnvironment>());
+}
-sal_Bool UCBContentHelper::IsDocument( const String& rContent )
-{
- sal_Bool bRet = sal_False;
- INetURLObject aObj( rContent );
- DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ucbhelper::Content content(INetURLObject const & url) {
+ return ucbhelper::Content(
+ url.GetMainURL(INetURLObject::NO_DECODE),
+ css::uno::Reference<css::ucb::XCommandEnvironment>());
+}
- try
- {
- Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- bRet = aCnt.isDocument();
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- DBG_WARNING( "CommandAbortedException" );
- }
- catch( ::com::sun::star::ucb::IllegalIdentifierException& )
- {
- DBG_WARNING( "IllegalIdentifierException" );
- }
- catch( ContentCreationException& )
- {
- DBG_WARNING( "IllegalIdentifierException" );
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- DBG_WARNING( "Any other exception" );
+std::vector<rtl::OUString> getContents(rtl::OUString const & url) {
+ try {
+ std::vector<rtl::OUString> cs;
+ ucbhelper::Content c(content(url));
+ css::uno::Sequence<rtl::OUString> args(1);
+ args[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
+ css::uno::Reference<css::sdbc::XResultSet> res(
+ c.createCursor(args, ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS),
+ css::uno::UNO_SET_THROW);
+ css::uno::Reference<com::sun::star::ucb::XContentAccess> acc(
+ res, css::uno::UNO_QUERY_THROW);
+ while (res->next()) {
+ cs.push_back(acc->queryContentIdentifierString());
+ }
+ return cs;
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "getContents(" << url << ") " << e.getValueType().getTypeName()
+ << " \"" << e.get<css::uno::Exception>().Message << '"');
+ return std::vector<rtl::OUString>();
}
-
- return bRet;
}
-// -----------------------------------------------------------------------
+rtl::OUString getCasePreservingUrl(INetURLObject url) {
+ return
+ content(url).executeCommand(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getCasePreservingURL")),
+ css::uno::Any()).
+ get<rtl::OUString>();
+}
-Any UCBContentHelper::GetProperty( const String& rContent, const ::rtl::OUString& rName )
-{
- INetURLObject aObj( rContent );
- DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- try
- {
- Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- return aCnt.getPropertyValue( rName );
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- DBG_WARNING( "CommandAbortedException" );
- }
- catch( ::com::sun::star::ucb::IllegalIdentifierException& )
- {
- DBG_WARNING( "IllegalIdentifierException" );
- }
- catch( ContentCreationException& )
- {
- DBG_WARNING( "IllegalIdentifierException" );
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- DBG_WARNING( "Any other exception" );
- }
+DateTime convert(css::util::DateTime const & dt) {
+ return DateTime(
+ Date(dt.Day, dt.Month, dt.Year),
+ Time(dt.Hours, dt.Minutes, dt.Seconds, dt.HundredthSeconds));
+}
- return Any();
}
-sal_Bool UCBContentHelper::IsFolder( const String& rContent )
-{
- sal_Bool bRet = sal_False;
- INetURLObject aObj( rContent );
- DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- try
- {
- Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- bRet = aCnt.isFolder();
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- DBG_WARNING( "CommandAbortedException" );
- }
- catch( ::com::sun::star::ucb::IllegalIdentifierException& )
- {
- DBG_WARNING( "IllegalIdentifierException" );
- }
- catch( ContentCreationException& )
- {
- DBG_WARNING( "IllegalIdentifierException" );
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- DBG_WARNING( "Any other exception" );
+bool utl::UCBContentHelper::IsDocument(rtl::OUString const & url) {
+ try {
+ return content(url).isDocument();
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::IsDocument(" << url << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return false;
}
-
- return bRet;
}
-// -----------------------------------------------------------------------
-
-sal_Bool UCBContentHelper::GetTitle( const String& rContent, String& rTitle )
+css::uno::Any utl::UCBContentHelper::GetProperty(
+ rtl::OUString const & url, rtl::OUString const & property)
{
- sal_Bool bRet = sal_False;
- INetURLObject aObj( rContent );
- DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- try
- {
- Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- OUString aTemp;
- if ( aCnt.getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Title")) ) >>= aTemp )
- {
- rTitle = String( aTemp );
- bRet = sal_True;
- }
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
+ try {
+ return content(url).getPropertyValue(property);
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::GetProperty(" << url << ", " << property << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return css::uno::Any();
}
- catch( ::com::sun::star::uno::Exception& )
- {
- }
- return bRet;
}
-// -----------------------------------------------------------------------
-
-sal_Bool UCBContentHelper::Kill( const String& rContent )
-{
- sal_Bool bRet = sal_True;
- INetURLObject aDeleteObj( rContent );
- DBG_ASSERT( aDeleteObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
-
- try
- {
- Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- aCnt.executeCommand( OUString(RTL_CONSTASCII_USTRINGPARAM("delete")), makeAny( sal_Bool( sal_True ) ) );
+bool utl::UCBContentHelper::IsFolder(rtl::OUString const & url) {
+ try {
+ return content(url).isFolder();
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::IsFolder(" << url << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return false;
}
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- DBG_WARNING( "CommandAbortedException" );
- bRet = sal_False;
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- DBG_WARNING( "Any other exception" );
- bRet = sal_False;
- }
-
- return bRet;
}
-// -----------------------------------------------------------------------
-
-Sequence < OUString > UCBContentHelper::GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted )
+bool utl::UCBContentHelper::GetTitle(
+ rtl::OUString const & url, rtl::OUString * title)
{
- StringList_Impl* pFiles = NULL;
- INetURLObject aFolderObj( rFolder );
- DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- try
- {
- Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- uno::Reference< XResultSet > xResultSet;
- Sequence< OUString > aProps( bSorted ? 2 : 1 );
- OUString* pProps = aProps.getArray();
- pProps[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
- if ( bSorted )
- pProps[1] = OUString(RTL_CONSTASCII_USTRINGPARAM("IsFolder"));
-
- try
- {
- ResultSetInclude eInclude = bFolder ? INCLUDE_FOLDERS_AND_DOCUMENTS : INCLUDE_DOCUMENTS_ONLY;
- if ( !bSorted )
- {
- xResultSet = aCnt.createCursor( aProps, eInclude );
- }
- else
- {
- uno::Reference< com::sun::star::ucb::XDynamicResultSet > xDynResultSet;
- xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
-
- uno::Reference < com::sun::star::ucb::XAnyCompareFactory > xFactory;
- uno::Reference < XMultiServiceFactory > xMgr = getProcessServiceFactory();
- uno::Reference < com::sun::star::ucb::XSortedDynamicResultSetFactory > xSRSFac(
- xMgr->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SortedDynamicResultSetFactory")) ), UNO_QUERY );
-
- Sequence< com::sun::star::ucb::NumberedSortingInfo > aSortInfo( 2 );
- com::sun::star::ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
- pInfo[ 0 ].ColumnIndex = 2;
- pInfo[ 0 ].Ascending = sal_False;
- pInfo[ 1 ].ColumnIndex = 1;
- pInfo[ 1 ].Ascending = sal_True;
-
- uno::Reference< com::sun::star::ucb::XDynamicResultSet > xDynamicResultSet;
- xDynamicResultSet =
- xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xFactory );
- if ( xDynamicResultSet.is() )
- {
- xResultSet = xDynamicResultSet->getStaticResultSet();
- }
- }
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- // folder not exists?
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- }
-
- if ( xResultSet.is() )
- {
- pFiles = new StringList_Impl;
- uno::Reference< com::sun::star::ucb::XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
- try
- {
- while ( xResultSet->next() )
- {
- OUString aId = xContentAccess->queryContentIdentifierString();
- OUString* pFile = new OUString( aId );
- pFiles->push_back( pFile );
- }
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- }
- }
- }
- catch( ::com::sun::star::uno::Exception& )
- {
+ assert(title != 0);
+ try {
+ *title = content(url).
+ getPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"))).
+ get<rtl::OUString>();
+ return true;
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::GetTitle(" << url << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return false;
}
+}
- if ( pFiles )
- {
- size_t nCount = pFiles->size();
- Sequence < OUString > aRet( nCount );
- OUString* pRet = aRet.getArray();
- for ( size_t i = 0; i < nCount; ++i )
- {
- OUString* pFile = (*pFiles)[ i ];
- pRet[i] = *( pFile );
- delete pFile;
- }
- delete pFiles;
- return aRet;
+bool utl::UCBContentHelper::Kill(rtl::OUString const & url) {
+ try {
+ content(url).executeCommand(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("delete")),
+ css::uno::makeAny(true));
+ return true;
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::Kill(" << url << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return false;
}
- else
- return Sequence < OUString > ();
}
-// -----------------------------------------------------------------------
-
-sal_Bool UCBContentHelper::MakeFolder( const String& rFolder, sal_Bool bNewOnly )
+bool utl::UCBContentHelper::MakeFolder(
+ rtl::OUString const & url, bool exclusive)
{
- INetURLObject aURL( rFolder );
- DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
- aURL.removeSegment();
- Content aCnt;
- Content aNew;
- uno::Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
- uno::Reference< XInteractionHandler > xInteractionHandler = uno::Reference< XInteractionHandler > (
- xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uui.InteractionHandler") ) ), UNO_QUERY );
- if ( Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ), new CommandEnvironment( xInteractionHandler, uno::Reference< XProgressHandler >() ), aCnt ) )
- return MakeFolder( aCnt, aTitle, aNew, bNewOnly );
- else
- return sal_False;
+ INetURLObject o(url);
+ SAL_WARN_IF(o.HasError(), "unotools", "Invalid URL \"" << url << '"');
+ rtl::OUString title(
+ o.getName(
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET));
+ o.removeSegment();
+ ucbhelper::Content parent;
+ ucbhelper::Content res;
+ return
+ ucbhelper::Content::create(
+ o.GetMainURL(INetURLObject::NO_DECODE),
+ new ucbhelper::CommandEnvironment(
+ css::uno::Reference<css::task::XInteractionHandler>(
+ (css::uno::Reference<css::lang::XMultiServiceFactory>(
+ comphelper::getProcessServiceFactory(),
+ css::uno::UNO_SET_THROW)->
+ createInstance(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.uui.InteractionHandler")))),
+ css::uno::UNO_QUERY_THROW),
+ css::uno::Reference<css::ucb::XProgressHandler>()),
+ parent)
+ && MakeFolder(parent, title, res, exclusive);
}
-sal_Bool UCBContentHelper::MakeFolder( Content& aCnt, const String& aTitle, Content& rNew, sal_Bool bNewOnly )
+bool utl::UCBContentHelper::MakeFolder(
+ ucbhelper::Content & parent, rtl::OUString const & title,
+ ucbhelper::Content & result, bool exclusive)
{
- sal_Bool bAlreadyExists = sal_False;
-
- try
- {
- Sequence< ContentInfo > aInfo = aCnt.queryCreatableContentsInfo();
- sal_Int32 nCount = aInfo.getLength();
- if ( nCount == 0 )
- return sal_False;
-
- for ( sal_Int32 i = 0; i < nCount; ++i )
- {
- // Simply look for the first KIND_FOLDER...
- const ContentInfo & rCurr = aInfo[i];
- if ( rCurr.Attributes & ContentInfoAttribute::KIND_FOLDER )
+ bool exists = false;
+ try {
+ css::uno::Sequence<css::ucb::ContentInfo> info(
+ parent.queryCreatableContentsInfo());
+ for (sal_Int32 i = 0; i < info.getLength(); ++i) {
+ // Simply look for the first KIND_FOLDER:
+ if ((info[i].Attributes
+ & css::ucb::ContentInfoAttribute::KIND_FOLDER)
+ != 0)
{
- // Make sure the only required bootstrap property is "Title",
- const Sequence< Property > & rProps = rCurr.Properties;
- if ( rProps.getLength() != 1 )
- continue;
-
- if ( !rProps[ 0 ].Name.equalsAsciiL(
- RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
- continue;
-
- Sequence<OUString> aNames(1);
- OUString* pNames = aNames.getArray();
- pNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
- Sequence<Any> aValues(1);
- Any* pValues = aValues.getArray();
- pValues[0] = makeAny( OUString( aTitle ) );
-
- if ( !aCnt.insertNewContent( rCurr.Type, aNames, aValues, rNew ) )
+ // Make sure the only required bootstrap property is "Title":
+ if (info[i].Properties.getLength() != 1
+ || !info[i].Properties[0].Name.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("Title")))
+ {
continue;
-
- return sal_True;
+ }
+ css::uno::Sequence<rtl::OUString> keys(1);
+ keys[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
+ css::uno::Sequence<css::uno::Any> values(1);
+ values[0] <<= title;
+ if (parent.insertNewContent(info[i].Type, keys, values, result))
+ {
+ return true;
+ }
}
}
- }
- catch ( InteractiveIOException& r )
- {
- if ( r.Code == IOErrorCode_ALREADY_EXISTING )
- {
- bAlreadyExists = sal_True;
+ } catch (css::ucb::InteractiveIOException const & e) {
+ if (e.Code == css::ucb::IOErrorCode_ALREADY_EXISTING) {
+ exists = true;
+ } else {
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::MakeFolder(" << title
+ << ") InteractiveIOException \"" << e.Message
+ << "\", code " << +e.Code);
}
+ } catch (css::ucb::NameClashException const &) {
+ exists = true;
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::MakeFolder(" << title << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ }
+ if (exists && !exclusive) {
+ INetURLObject o(parent.getURL());
+ o.Append(title);
+ result = content(o);
+ return true;
+ } else {
+ return false;
}
- catch ( NameClashException& )
- {
- bAlreadyExists = sal_True;
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- }
- catch( RuntimeException& )
- {
- }
- catch( Exception& )
- {
- }
-
- if( bAlreadyExists && !bNewOnly )
- {
- INetURLObject aObj( aCnt.getURL() );
- aObj.Append( aTitle );
- rNew = Content( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference < XCommandEnvironment >() );
- return sal_True;
- }
-
- return sal_False;
}
-// -----------------------------------------------------------------------
-
-sal_uLong UCBContentHelper::GetSize( const String& rContent )
-{
- sal_uLong nSize = 0;
- sal_Int64 nTemp = 0;
- INetURLObject aObj( rContent );
- DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- try
- {
- Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
- aCnt.getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Size")) ) >>= nTemp;
- }
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
+sal_Int64 utl::UCBContentHelper::GetSize(rtl::OUString const & url) {
+ try {
+ return
+ content(url).getPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size"))).
+ get<sal_Int64>();
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::GetSize(" << url << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return 0;
}
- catch( ::com::sun::star::uno::Exception& )
- {
- }
- nSize = (sal_uInt32)nTemp;
- return nSize;
}
-// -----------------------------------------------------------------------
-
-sal_Bool UCBContentHelper::IsYounger( const String& rIsYoung, const String& rIsOlder )
+bool utl::UCBContentHelper::IsYounger(
+ rtl::OUString const & younger, rtl::OUString const & older)
{
- DateTime aYoungDate, aOlderDate;
- INetURLObject aYoungObj( rIsYoung );
- DBG_ASSERT( aYoungObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- INetURLObject aOlderObj( rIsOlder );
- DBG_ASSERT( aOlderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
- try
- {
- uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > aCmdEnv;
- Content aYoung( aYoungObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
- ::com::sun::star::util::DateTime aTempYoungDate;
- aYoung.getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DateModified")) ) >>= aTempYoungDate;
- CONVERT_DATETIME( aTempYoungDate, aYoungDate );
- Content aOlder( aOlderObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
- ::com::sun::star::util::DateTime aTempOlderDate;
- aOlder.getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DateModified")) ) >>= aTempOlderDate;
- CONVERT_DATETIME( aTempOlderDate, aOlderDate );
+ try {
+ return
+ convert(
+ content(younger).getPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DateModified"))).
+ get<css::util::DateTime>())
+ > convert(
+ content(older).getPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DateModified"))).
+ get<css::util::DateTime>());
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::IsYounger(" << younger << ", " << older << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ return false;
}
- catch( ::com::sun::star::ucb::CommandAbortedException& )
- {
- }
- catch( ::com::sun::star::uno::Exception& )
- {
- }
-
- return ( aYoungDate > aOlderDate );
}
-// -----------------------------------------------------------------------
-sal_Bool UCBContentHelper::Exists( const String& rURL )
-{
-
- String sObjectPhysicalName;
- sal_Bool bIsLocalFile = ::utl::LocalFileHelper::ConvertURLToPhysicalName( rURL, sObjectPhysicalName );
- // try to create a directory entry for the URL given
- if ( bIsLocalFile )
- {
- ::rtl::OUString sIn( sObjectPhysicalName ), sOut;
- if ( osl_File_E_None == osl_getFileURLFromSystemPath( sIn.pData, &sOut.pData ) )
+bool utl::UCBContentHelper::Exists(rtl::OUString const & url) {
+ rtl::OUString pathname;
+ if (utl::LocalFileHelper::ConvertURLToPhysicalName(url, pathname)) {
+ // Try to create a directory entry for the given URL:
+ rtl::OUString url2;
+ if (osl::FileBase::getFileURLFromSystemPath(pathname, url2)
+ == osl::FileBase::E_None)
{
- // #106526 osl_getDirectoryItem is an existence check
- // no further osl_getFileStatus call necessary
- DirectoryItem aItem;
- return (FileBase::E_None == DirectoryItem::get(sOut, aItem));
+ // #106526 osl_getDirectoryItem is an existence check, no further
+ // osl_getFileStatus call necessary:
+ osl::DirectoryItem item;
+ return osl::DirectoryItem::get(url2, item) == osl::FileBase::E_None;
+ } else {
+ return false;
}
- return sal_False;
- }
-
- // divide URL into folder and name part
- sal_Bool bRet = sal_False;
- INetURLObject aObj( rURL );
- ::rtl::OUString aFileName = aObj.getName(
- INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).toAsciiLowerCase();
- aObj.removeSegment();
- aObj.removeFinalSlash();
-
- // get a list of URLs for all children of rFolder
- Sequence< ::rtl::OUString > aFiles = GetFolderContents( aObj.GetMainURL( INetURLObject::NO_DECODE ), sal_True, sal_False );
-
- const ::rtl::OUString* pFiles = aFiles.getConstArray();
- sal_uInt32 i, nCount = aFiles.getLength();
- for ( i = 0; i < nCount; ++i )
- {
- // get the last name of the URLs and compare it with rName
- INetURLObject aFileObject( pFiles[i] );
- ::rtl::OUString aFile = aFileObject.getName(
- INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).toAsciiLowerCase();
- if ( aFile == aFileName )
+ } else {
+ // Divide URL into folder and name part:
+ INetURLObject o(url);
+ rtl::OUString name(
+ o.getName(
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET));
+ o.removeSegment();
+ o.removeFinalSlash();
+ std::vector<rtl::OUString> cs(
+ getContents(o.GetMainURL(INetURLObject::NO_DECODE)));
+ for (std::vector<rtl::OUString>::iterator i(cs.begin()); i != cs.end();
+ ++i)
{
- // names match
- bRet = sal_True;
- break;
- }
- }
-
- return bRet;
-}
-
-// -----------------------------------------------------------------------
-sal_Bool UCBContentHelper::IsSubPath( const ::rtl::OUString& rPath, const ::rtl::OUString& rSubfolderCandidate, const uno::Reference< ::com::sun::star::ucb::XContentProvider >& xProv )
-{
- sal_Bool bResult = sal_False;
-
- uno::Reference< ::com::sun::star::ucb::XContentProvider > xContentProvider = xProv;
-
- // the comparing is done in the following way:
- // - first compare in case sensitive way
- // - if name are different try a fallback comparing inf case insensitive way
- // - if the last comparing succeeded get casepreserving normalized names for the files and compare them
- // ( the second step is required because retrieving of the normalized names might be very expensive in some cases )
-
- INetURLObject aCandidate( rSubfolderCandidate );
- INetURLObject aCandidateLowCase( rSubfolderCandidate.toAsciiLowerCase() ); // will be used for case insensitive comparing
- INetURLObject aParentFolder( rPath );
- INetURLObject aParentFolderLowCase( rPath.toAsciiLowerCase() ); // will be used for case insensitive comparing
-
- if ( aCandidate.GetProtocol() == aParentFolder.GetProtocol() )
- {
- if ( !xContentProvider.is() )
- {
- ::ucbhelper::ContentBroker* pBroker = NULL;
- if ( aCandidate.GetProtocol() == INET_PROT_FILE )
+ if (INetURLObject(*i).getName(
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET).
+ equalsIgnoreAsciiCase(name))
{
- pBroker = ::ucbhelper::ContentBroker::get();
- if ( pBroker )
- xContentProvider = pBroker->getContentProviderInterface();
+ return true;
}
}
-
- INetURLObject aLastTmpObj;
- do
- {
- if ( aParentFolder == aCandidate )
- {
- // if case sensitive comparing succeeded there is no need for additional checks
- bResult = sal_True;
- }
- else if ( xContentProvider.is() && aParentFolderLowCase == aCandidateLowCase )
- {
- // the comparing was done using caseinsensitive way
- // the case sensitive comparing have failed already
- // the normalized urls must be retrieved
- try
- {
- uno::Reference< ::com::sun::star::ucb::XContent > xSecCont =
- xContentProvider->queryContent(
- uno::Reference< ::com::sun::star::ucb::XContentIdentifierFactory >(
- xContentProvider, ::com::sun::star::uno::UNO_QUERY_THROW )->createContentIdentifier(
- aParentFolder.GetMainURL( INetURLObject::NO_DECODE ) ) );
-
- uno::Reference< ::com::sun::star::ucb::XContent > xLocCont =
- xContentProvider->queryContent(
- uno::Reference< ::com::sun::star::ucb::XContentIdentifierFactory >(
- xContentProvider, ::com::sun::star::uno::UNO_QUERY_THROW )->createContentIdentifier(
- aCandidate.GetMainURL( INetURLObject::NO_DECODE ) ) );
-
- if ( !xSecCont.is() || !xLocCont.is() )
- throw ::com::sun::star::uno::RuntimeException();
-
- ::rtl::OUString aSecNormStr;
- ::rtl::OUString aLocNormStr;
-
- bResult =
- ( ( uno::Reference< ::com::sun::star::ucb::XCommandProcessor >(
- xSecCont, ::com::sun::star::uno::UNO_QUERY_THROW )->execute(
- ::com::sun::star::ucb::Command(
- rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getCasePreservingURL" ) ),
- -1,
- ::com::sun::star::uno::Any() ),
- 0,
- uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() )
- >>= aSecNormStr )
- && ( uno::Reference< ::com::sun::star::ucb::XCommandProcessor >(
- xLocCont, ::com::sun::star::uno::UNO_QUERY_THROW )->execute(
- ::com::sun::star::ucb::Command(
- rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getCasePreservingURL" ) ),
- -1,
- ::com::sun::star::uno::Any() ),
- 0,
- uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() )
- >>= aLocNormStr )
- && aLocNormStr.equals( aSecNormStr ) );
- }
- catch( ::com::sun::star::uno::Exception& )
- {}
- }
-
- // INetURLObject::removeSegment sometimes return true without exchanging URL,
- // for example in case of "file:///"
- aLastTmpObj = aCandidate;
-
- } while( aCandidate.removeSegment() && aCandidateLowCase.removeSegment() && aCandidate != aLastTmpObj && !bResult );
+ return false;
}
-
- return bResult;
}
-// -----------------------------------------------------------------------
-sal_Bool UCBContentHelper::EqualURLs( const ::rtl::OUString& aFirstURL, const ::rtl::OUString& aSecondURL )
+bool utl::UCBContentHelper::IsSubPath(
+ rtl::OUString const & parent, rtl::OUString const & child)
{
- sal_Bool bResult = sal_False;
-
- if ( aFirstURL.getLength() && aSecondURL.getLength() )
- {
- INetURLObject aFirst( aFirstURL );
- INetURLObject aSecond( aSecondURL );
-
- if ( aFirst.GetProtocol() != INET_PROT_NOT_VALID && aSecond.GetProtocol() != INET_PROT_NOT_VALID )
- {
- try
+ // The comparison is done in the following way:
+ // - First, compare case sensitively
+ // - If names are different, try a fallback comparing case insensitively
+ // - If the last comparison succeeded, get case preserving normalized names
+ // for the files and compare them
+ // (The second step is required because retrieving the normalized names
+ // might be very expensive in some cases.)
+ INetURLObject candidate(child);
+ INetURLObject folder(parent);
+ if (candidate.GetProtocol() != folder.GetProtocol()) {
+ return false;
+ }
+ INetURLObject candidateLower(child.toAsciiLowerCase());
+ INetURLObject folderLower(parent.toAsciiLowerCase());
+ try {
+ INetURLObject tmp;
+ do {
+ if (candidate == folder
+ || (candidate.GetProtocol() == INET_PROT_FILE
+ && candidateLower == folderLower
+ && (getCasePreservingUrl(candidate)
+ == getCasePreservingUrl(folder))))
{
- ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
- if ( !pBroker )
- throw uno::RuntimeException();
-
- uno::Reference< ::com::sun::star::ucb::XContentIdentifierFactory > xIdFac
- = pBroker->getContentIdentifierFactoryInterface();
- if ( !xIdFac.is() )
- throw uno::RuntimeException();
-
- uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xIdFirst
- = xIdFac->createContentIdentifier( aFirst.GetMainURL( INetURLObject::NO_DECODE ) );
- uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xIdSecond
- = xIdFac->createContentIdentifier( aSecond.GetMainURL( INetURLObject::NO_DECODE ) );
-
- if ( xIdFirst.is() && xIdSecond.is() )
- {
- uno::Reference< ::com::sun::star::ucb::XContentProvider > xProvider =
- pBroker->getContentProviderInterface();
- if ( !xProvider.is() )
- throw uno::RuntimeException();
- bResult = !xProvider->compareContentIds( xIdFirst, xIdSecond );
- }
+ return true;
}
- catch( uno::Exception& )
- {
- OSL_FAIL( "Can't compare URL's, treat as different!\n" );
- }
- }
- }
-
- return bResult;
+ tmp = candidate;
+ } while (candidate.removeSegment() && candidateLower.removeSegment()
+ && candidate != tmp);
+ // INetURLObject::removeSegment sometimes returns true without
+ // modifying the URL, e.g., in case of "file:///"
+ } catch (css::uno::RuntimeException const &) {
+ throw;
+ } catch (css::ucb::CommandAbortedException const &) {
+ assert(false); // this cannot happen
+ throw;
+ } catch (css::uno::Exception const &) {
+ css::uno::Any e(cppu::getCaughtException());
+ SAL_INFO(
+ "unotools",
+ "UCBContentHelper::IsSubPath(" << parent << ", " << child << ") "
+ << e.getValueType().getTypeName() << " \""
+ << e.get<css::uno::Exception>().Message << '"');
+ }
+ return false;
}
-
-
-} // namespace utl
+bool utl::UCBContentHelper::EqualURLs(
+ rtl::OUString const & url1, rtl::OUString const & url2)
+{
+ if (url1.isEmpty() || url2.isEmpty()) {
+ return false;
+ }
+ ucbhelper::ContentBroker * broker = ucbhelper::ContentBroker::get();
+ if (broker == 0) {
+ throw css::uno::RuntimeException(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("no ucbhelper::ContentBroker")),
+ css::uno::Reference<css::uno::XInterface>());
+ }
+ return broker->getContentProviderInterface()->compareContentIds(
+ (broker->getContentIdentifierFactoryInterface()->
+ createContentIdentifier(canonic(url1))),
+ (broker->getContentIdentifierFactoryInterface()->
+ createContentIdentifier(canonic(url2))));
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index f5463d7caa41..8f70cdd0f53d 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -42,7 +42,6 @@
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/ucb/XContent.hpp>
-#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/XCommandProcessor.hpp>
@@ -52,7 +51,6 @@
#include <unotools/securityoptions.hxx>
#include <com/sun/star/security/CertificateValidity.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
-#include <ucbhelper/contentbroker.hxx>
#include <unotools/ucbhelper.hxx>
#include <comphelper/componentcontext.hxx>
#include "comphelper/documentconstants.hxx"
@@ -434,22 +432,11 @@ void DocumentDigitalSignatures::showCertificate(
INetURLObject aLocObj( Location );
INetURLObject aLocObjLowCase( Location.toAsciiLowerCase() ); // will be used for case insensitive comparing
- ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProvider > xContentProvider;
- ::ucbhelper::ContentBroker* pBroker = NULL;
-
- //warning free code
- if ( aLocObj.GetProtocol() == INET_PROT_FILE)
- {
- pBroker = ::ucbhelper::ContentBroker::get();
- if (pBroker)
- xContentProvider = pBroker->getContentProviderInterface();
- }
-
Sequence< ::rtl::OUString > aSecURLs = SvtSecurityOptions().GetSecureURLs();
const ::rtl::OUString* pSecURLs = aSecURLs.getConstArray();
const ::rtl::OUString* pSecURLsEnd = pSecURLs + aSecURLs.getLength();
for ( ; pSecURLs != pSecURLsEnd && !bFound; ++pSecURLs )
- bFound = ::utl::UCBContentHelper::IsSubPath( *pSecURLs, Location, xContentProvider );
+ bFound = ::utl::UCBContentHelper::IsSubPath( *pSecURLs, Location );
return bFound;
}