25#include <com/sun/star/sdbc/XResultSet.hpp>
26#include <com/sun/star/task/XInteractionHandler.hpp>
27#include <com/sun/star/task/InteractionHandler.hpp>
28#include <com/sun/star/ucb/CommandAbortedException.hpp>
29#include <com/sun/star/ucb/ContentInfo.hpp>
30#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
31#include <com/sun/star/ucb/IOErrorCode.hpp>
32#include <com/sun/star/ucb/InteractiveIOException.hpp>
33#include <com/sun/star/ucb/NameClashException.hpp>
34#include <com/sun/star/ucb/UniversalContentBroker.hpp>
35#include <com/sun/star/ucb/XCommandEnvironment.hpp>
36#include <com/sun/star/ucb/XContentAccess.hpp>
37#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
38#include <com/sun/star/uno/Any.hxx>
39#include <com/sun/star/uno/Exception.hpp>
40#include <com/sun/star/uno/Reference.hxx>
41#include <com/sun/star/uno/RuntimeException.hpp>
42#include <com/sun/star/uno/Sequence.hxx>
45#include <osl/file.hxx>
46#include <rtl/ustring.hxx>
48#include <tools/datetime.hxx>
61OUString canonic(OUString
const & url) {
63 SAL_WARN_IF(o.HasError(),
"unotools.ucbhelper",
"Invalid URL \"" << url <<
'"');
81std::vector<OUString> getContents(OUString
const & url) {
83 std::vector<OUString> cs;
85 css::uno::Sequence<OUString>
args {
"Title" };
86 css::uno::Reference<css::sdbc::XResultSet> res( c.createCursor(args), css::uno::UNO_SET_THROW);
87 css::uno::Reference<css::ucb::XContentAccess> acc( res, css::uno::UNO_QUERY_THROW);
89 cs.push_back(acc->queryContentIdentifierString());
92 }
catch (css::uno::RuntimeException
const &) {
94 }
catch (css::ucb::CommandAbortedException
const &) {
95 assert(
false &&
"this cannot happen");
97 }
catch (css::uno::Exception
const &) {
99 return std::vector<OUString>();
105 content(url).executeCommand(
106 "getCasePreservingURL",
119 css::uno::Reference< css::task::XInteractionHandler > xIH(
120 css::task::InteractionHandler::createWithParent(
123 css::uno::Reference< css::ucb::XProgressHandler > xProgress;
125 new ::ucbhelper::CommandEnvironment(
133 return content(url).isDocument();
134 }
catch (css::uno::RuntimeException
const &) {
136 }
catch (css::ucb::CommandAbortedException
const &) {
137 assert(
false &&
"this cannot happen");
139 }
catch (css::uno::Exception
const &) {
146 OUString
const & url, OUString
const &
property)
149 return content(url).getPropertyValue(
property);
150 }
catch (css::uno::RuntimeException
const &) {
152 }
catch (css::ucb::CommandAbortedException
const &) {
153 assert(
false &&
"this cannot happen");
155 }
catch (css::uno::Exception
const &) {
157 return css::uno::Any();
163 return content(url).isFolder();
164 }
catch (css::uno::RuntimeException
const &) {
166 }
catch (css::ucb::CommandAbortedException
const &) {
167 assert(
false &&
"this cannot happen");
169 }
catch (css::uno::Exception
const &) {
176 OUString
const & url, OUString * title)
178 assert(title !=
nullptr);
180 return content(url).getPropertyValue(
"Title") >>= *title;
181 }
catch (css::uno::RuntimeException
const &) {
183 }
catch (css::ucb::CommandAbortedException
const &) {
184 assert(
false &&
"this cannot happen");
186 }
catch (css::uno::Exception
const &) {
194 content(url).executeCommand(
196 css::uno::Any(
true));
198 }
catch (css::uno::RuntimeException
const &) {
200 }
catch (css::ucb::CommandAbortedException
const &) {
201 assert(
false &&
"this cannot happen");
203 }
catch (css::uno::Exception
const &) {
215 const css::uno::Sequence<css::ucb::ContentInfo> info(
217 for (
const auto& rInfo : info) {
219 if ((rInfo.Attributes
220 & css::ucb::ContentInfoAttribute::KIND_FOLDER)
224 if ( rInfo.Properties.getLength() != 1 || rInfo.Properties[0].Name !=
"Title" )
234 }
catch (css::ucb::InteractiveIOException
const & e) {
235 if (e.Code == css::ucb::IOErrorCode_ALREADY_EXISTING) {
239 "unotools.ucbhelper",
240 "UCBContentHelper::MakeFolder(" << title <<
")");
242 }
catch (css::ucb::NameClashException
const &) {
244 }
catch (css::uno::RuntimeException
const &) {
246 }
catch (css::ucb::CommandAbortedException
const &) {
247 assert(
false &&
"this cannot happen");
249 }
catch (css::uno::Exception
const &) {
251 "unotools.ucbhelper",
252 "UCBContentHelper::MakeFolder(" << title <<
") ");
265 OUString
const & younger, OUString
const & older)
272 get<css::util::DateTime>())
276 get<css::util::DateTime>());
277 }
catch (css::uno::RuntimeException
const &) {
279 }
catch (css::ucb::CommandAbortedException
const &) {
280 assert(
false &&
"this cannot happen");
282 }
catch (css::uno::Exception
const &) {
284 "unotools.ucbhelper",
285 "UCBContentHelper::IsYounger(" << younger <<
", " << older <<
")");
292 if (osl::FileBase::getSystemPathFromFileURL(url, pathname)
293 == osl::FileBase::E_None)
297 if (osl::FileBase::getFileURLFromSystemPath(pathname, url2)
298 == osl::FileBase::E_None)
302 osl::DirectoryItem item;
316 std::vector<OUString> cs(
318 return std::any_of(cs.begin(), cs.end(),
319 [&
name](
const OUString& rItem) {
320 return INetURLObject(rItem).
321 getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset).
322 equalsIgnoreAsciiCase(name); });
327 OUString
const & parent, OUString
const & child)
346 if (candidate == folder
348 && candidateLower == folderLower
349 && (getCasePreservingUrl(candidate)
350 == getCasePreservingUrl(folder))))
356 && candidate != tmp);
359 }
catch (css::uno::RuntimeException
const &) {
361 }
catch (css::ucb::CommandAbortedException
const &) {
362 assert(
false &&
"this cannot happen");
364 }
catch (css::uno::Exception
const &) {
366 "unotools.ucbhelper",
367 "UCBContentHelper::IsSubPath(" << parent <<
", " << child <<
")");
373 OUString
const & url1, OUString
const & url2)
375 if (url1.isEmpty() || url2.isEmpty()) {
378 css::uno::Reference< css::ucb::XUniversalContentBroker >
ucb(
379 css::ucb::UniversalContentBroker::create(
382 ucb->compareContentIds(
383 ucb->createContentIdentifier(canonic(url1)),
384 ucb->createContentIdentifier(canonic(url2)))
389 const css::uno::Reference< css::uno::XComponentContext >& xCtx,
390 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
397 aURL.removeSegment();
401 xEnv, xCtx, aParent ) )
DateTime(DateTimeInitEmpty)
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
INetProtocol GetProtocol() const
bool Append(std::u16string_view rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
const OUString & getURL() const
static bool create(const OUString &rURL, const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnv, const css::uno::Reference< css::uno::XComponentContext > &rCtx, Content &rContent)
bool insertNewContent(const OUString &rContentType, const css::uno::Sequence< OUString > &rPropertyNames, const css::uno::Sequence< css::uno::Any > &rPropertyValues, Content &rNewContent)
css::uno::Sequence< css::ucb::ContentInfo > queryCreatableContentsInfo()
#define TOOLS_INFO_EXCEPTION(area, stream)
#define SAL_WARN_IF(condition, area, stream)
OUString get(TranslateId sContextAndId, const std::locale &loc)
Reference< XComponentContext > getProcessComponentContext()
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
UNOTOOLS_DLLPUBLIC bool Exists(OUString const &url)
UNOTOOLS_DLLPUBLIC bool IsDocument(OUString const &url)
UNOTOOLS_DLLPUBLIC bool MakeFolder(ucbhelper::Content &parent, OUString const &title, ucbhelper::Content &result)
UNOTOOLS_DLLPUBLIC css::uno::Any GetProperty(OUString const &url, OUString const &property)
UNOTOOLS_DLLPUBLIC bool ensureFolder(const css::uno::Reference< css::uno::XComponentContext > &xCtx, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, std::u16string_view rFolder, ucbhelper::Content &result) noexcept
like mkdir -p
UNOTOOLS_DLLPUBLIC css::uno::Reference< css::ucb::XCommandEnvironment > getDefaultCommandEnvironment()
Returns a default XCommandEnvironment to be used when creating a ucbhelper::Content.
UNOTOOLS_DLLPUBLIC bool EqualURLs(OUString const &url1, OUString const &url2)
UNOTOOLS_DLLPUBLIC bool IsFolder(OUString const &url)
UNOTOOLS_DLLPUBLIC bool IsSubPath(OUString const &parent, OUString const &child)
UNOTOOLS_DLLPUBLIC bool IsYounger(OUString const &younger, OUString const &older)
UNOTOOLS_DLLPUBLIC bool GetTitle(OUString const &url, OUString *title)
UNOTOOLS_DLLPUBLIC bool Kill(OUString const &url)