xref: /trunk/main/ucbhelper/source/client/fileidentifierconverter.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
50     // If there were more file systems than just "file:///" (e.g., the obsolete
51     // "vnd.sun.star.wfs:///"), this code should query all relevant UCPs for
52     // their com.sun.star.ucb.XFileIdentifierConverter.getFileProviderLocality
53     // and return the most local one:
54     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///"));
55 }
56 
57 //============================================================================
58 //
59 //  getFileURLFromSystemPath
60 //
61 //============================================================================
62 
63 rtl::OUString
getFileURLFromSystemPath(uno::Reference<ucb::XContentProviderManager> const & rManager,rtl::OUString const & rBaseURL,rtl::OUString const & rSystemPath)64 getFileURLFromSystemPath(
65     uno::Reference< ucb::XContentProviderManager > const & rManager,
66     rtl::OUString const & rBaseURL,
67     rtl::OUString const & rSystemPath)
68 {
69     OSL_ASSERT(rManager.is());
70 
71     uno::Reference< ucb::XFileIdentifierConverter >
72         xConverter(rManager->queryContentProvider(rBaseURL), uno::UNO_QUERY);
73     if (xConverter.is())
74         return xConverter->getFileURLFromSystemPath(rBaseURL, rSystemPath);
75     else
76         return rtl::OUString();
77 }
78 
79 //============================================================================
80 //
81 //  getSystemPathFromFileURL
82 //
83 //============================================================================
84 
85 rtl::OUString
getSystemPathFromFileURL(uno::Reference<ucb::XContentProviderManager> const & rManager,rtl::OUString const & rURL)86 getSystemPathFromFileURL(
87     uno::Reference< ucb::XContentProviderManager > const & rManager,
88     rtl::OUString const & rURL)
89 {
90     OSL_ASSERT(rManager.is());
91 
92     uno::Reference< ucb::XFileIdentifierConverter >
93         xConverter(rManager->queryContentProvider(rURL), uno::UNO_QUERY);
94     if (xConverter.is())
95         return xConverter->getSystemPathFromFileURL(rURL);
96     else
97         return rtl::OUString();
98 }
99 
100 }
101