1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucbhelper.hxx"
26 #include <ucbhelper/fileidentifierconverter.hxx>
27 #include <com/sun/star/ucb/ContentProviderInfo.hpp>
28 #include <com/sun/star/ucb/XContentProviderManager.hpp>
29 #include <com/sun/star/ucb/XFileIdentifierConverter.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <osl/diagnose.h>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
35
36 using namespace com::sun::star;
37
38 namespace ucbhelper {
39
40 //============================================================================
41 //
42 // getLocalFileURL
43 //
44 //============================================================================
45
46 rtl::OUString
getLocalFileURL(uno::Reference<ucb::XContentProviderManager> const &)47 getLocalFileURL(
48 uno::Reference< ucb::XContentProviderManager > const &)
49 SAL_THROW((uno::RuntimeException))
50 {
51 // If there were more file systems than just "file:///" (e.g., the obsolete
52 // "vnd.sun.star.wfs:///"), this code should query all relevant UCPs for
53 // their com.sun.star.ucb.XFileIdentifierConverter.getFileProviderLocality
54 // and return the most local one:
55 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///"));
56 }
57
58 //============================================================================
59 //
60 // getFileURLFromSystemPath
61 //
62 //============================================================================
63
64 rtl::OUString
getFileURLFromSystemPath(uno::Reference<ucb::XContentProviderManager> const & rManager,rtl::OUString const & rBaseURL,rtl::OUString const & rSystemPath)65 getFileURLFromSystemPath(
66 uno::Reference< ucb::XContentProviderManager > const & rManager,
67 rtl::OUString const & rBaseURL,
68 rtl::OUString const & rSystemPath)
69 SAL_THROW((uno::RuntimeException))
70 {
71 OSL_ASSERT(rManager.is());
72
73 uno::Reference< ucb::XFileIdentifierConverter >
74 xConverter(rManager->queryContentProvider(rBaseURL), uno::UNO_QUERY);
75 if (xConverter.is())
76 return xConverter->getFileURLFromSystemPath(rBaseURL, rSystemPath);
77 else
78 return rtl::OUString();
79 }
80
81 //============================================================================
82 //
83 // getSystemPathFromFileURL
84 //
85 //============================================================================
86
87 rtl::OUString
getSystemPathFromFileURL(uno::Reference<ucb::XContentProviderManager> const & rManager,rtl::OUString const & rURL)88 getSystemPathFromFileURL(
89 uno::Reference< ucb::XContentProviderManager > const & rManager,
90 rtl::OUString const & rURL)
91 SAL_THROW((uno::RuntimeException))
92 {
93 OSL_ASSERT(rManager.is());
94
95 uno::Reference< ucb::XFileIdentifierConverter >
96 xConverter(rManager->queryContentProvider(rURL), uno::UNO_QUERY);
97 if (xConverter.is())
98 return xConverter->getSystemPathFromFileURL(rURL);
99 else
100 return rtl::OUString();
101 }
102
103 }
104