22#include <com/sun/star/lang/XServiceInfo.hpp>
23#include <com/sun/star/uno/Sequence.hxx>
24#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
28#include <osl/thread.h>
29#include <rtl/string.h>
30#include <rtl/textenc.h>
33#include <rtl/ustrbuf.hxx>
34#include <rtl/ustring.hxx>
43 public cppu::WeakImplHelper<
44 css::lang::XServiceInfo, css::uri::XExternalUriReferenceTranslator>
50 Translator& operator=(
const Translator&) =
delete;
56 virtual css::uno::Sequence< OUString > SAL_CALL
59 virtual OUString SAL_CALL
60 translateToInternal(OUString
const & externalUriReference)
override;
62 virtual OUString SAL_CALL
63 translateToExternal(OUString
const & internalUriReference)
override;
66 virtual ~Translator()
override {}
69OUString Translator::getImplementationName()
71 return "com.sun.star.comp.uri.ExternalUriReferenceTranslator";
74sal_Bool Translator::supportsService(OUString
const & serviceName)
79css::uno::Sequence< OUString > Translator::getSupportedServiceNames()
81 css::uno::Sequence< OUString > s {
"com.sun.star.uri.ExternalUriReferenceTranslator" };
85OUString Translator::translateToInternal(
86 OUString
const & externalUriReference)
88 if (!externalUriReference.matchIgnoreAsciiCase(
"file:/"))
90 return externalUriReference;
92 sal_Int32
i = RTL_CONSTASCII_LENGTH(
"file:");
93 OUStringBuffer buf(128);
94 buf.append(externalUriReference.subView(0, i));
97 if (!externalUriReference.match(
"//", i))
101 rtl_TextEncoding encoding = osl_getThreadTextEncoding();
102 for (
bool path =
true;;) {
104 while (j != externalUriReference.getLength()
105 && externalUriReference[j] !=
'#'
106 && (!path || externalUriReference[j] !=
'/'))
114 externalUriReference.copy(i, j - i),
115 rtl_UriDecodeStrict, encoding),
116 rtl_UriCharClassPchar, rtl_UriEncodeStrict,
117 RTL_TEXTENCODING_UTF8));
123 if (j == externalUriReference.getLength()) {
126 buf.append(externalUriReference[j]);
127 path = externalUriReference[j] ==
'/';
130 return buf.makeStringAndClear();
133OUString Translator::translateToExternal(
134 OUString
const & internalUriReference)
136 if (!internalUriReference.matchIgnoreAsciiCase(
"file://"))
138 return internalUriReference;
140 sal_Int32
i = RTL_CONSTASCII_LENGTH(
"file://");
141 OUStringBuffer buf(128);
142 buf.append(internalUriReference.subView(0, i));
143 rtl_TextEncoding encoding = osl_getThreadTextEncoding();
144 for (
bool path =
true;;) {
146 while (j != internalUriReference.getLength()
147 && internalUriReference[j] !=
'#'
148 && (!path || internalUriReference[j] !=
'/'))
159 internalUriReference.copy(i, j - i),
160 rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8),
161 rtl_UriCharClassPchar, rtl_UriEncodeStrictKeepEscapes,
168 if (j == internalUriReference.getLength()) {
171 buf.append(internalUriReference[j]);
172 path = internalUriReference[j] ==
'/';
175 return buf.makeStringAndClear();
180extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
182 css::uno::Sequence<css::uno::Any>
const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_uri_ExternalUriReferenceTranslator_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Sequence< Any >(* Translator)(const Sequence< Any > &)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)