23#include <rtl/ustrbuf.hxx>
25#include <com/sun/star/util/XURLTransformer.hpp>
26#include <com/sun/star/util/URL.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/uno/XComponentContext.hpp>
32class URLTransformer :
public ::cppu::WeakImplHelper< css::util::XURLTransformer, css::lang::XServiceInfo>
39 return "com.sun.star.comp.framework.URLTransformer";
49 return {
"com.sun.star.util.URLTransformer"};
52 virtual sal_Bool SAL_CALL parseStrict( css::util::URL& aURL )
override;
54 virtual sal_Bool SAL_CALL parseSmart( css::util::URL& aURL,
const OUString& sSmartProtocol )
override;
56 virtual sal_Bool SAL_CALL assemble( css::util::URL& aURL )
override;
58 virtual OUString SAL_CALL getPresentation(
const css::util::URL& aURL,
sal_Bool bWithPassword )
override;
61void lcl_ParserHelper(
INetURLObject& _rParser, css::util::URL& _rURL)
68 _rURL.Port =
static_cast<sal_Int16
>(_rParser.
GetPort());
76 OUStringBuffer aPath(128);
86 _rURL.Path = aPath.makeStringAndClear();
95 _rURL.Arguments = _rParser.
GetParam();
109sal_Bool SAL_CALL URLTransformer::parseStrict( css::util::URL& aURL )
112 if (
aURL.Complete.isEmpty() )
117 sal_Int32 nURLIndex =
aURL.Complete.indexOf(
':' );
118 if ( nURLIndex <= 1 )
121 std::u16string_view aProtocol =
aURL.Complete.subView( 0, nURLIndex+1 );
131 if ( eINetProt == INetProtocol::NotValid )
135 else if ( !aParser.HasError() )
137 lcl_ParserHelper(aParser,aURL);
146 aURL.Protocol = aProtocol;
148 aURL.Path =
aURL.Complete.copy( nURLIndex+1 );
159sal_Bool SAL_CALL URLTransformer::parseSmart( css::util::URL& aURL,
160 const OUString& sSmartProtocol )
163 if (
aURL.Complete.isEmpty() )
175 lcl_ParserHelper(aParser,aURL);
186 sal_Int32
nIndex =
aURL.Complete.indexOf(
':' );
189 OUString aProtocol =
aURL.Complete.copy( 0, nIndex+1 );
196 aURL.Protocol = aProtocol;
202 aURL.Path =
aURL.Complete.copy( nIndex+1 );
211sal_Bool SAL_CALL URLTransformer::assemble( css::util::URL& aURL )
218 OUStringBuffer aCompletePath(
aURL.Path );
221 if ( !
aURL.Name.isEmpty() )
223 sal_Int32
nIndex =
aURL.Path.lastIndexOf(
'/' );
224 if ( nIndex == (
aURL.Path.getLength() -1 ))
225 aCompletePath.append(
aURL.Name );
228 aCompletePath.append(
"/" +
aURL.Name );
253 else if ( !
aURL.Protocol.isEmpty() )
266OUString SAL_CALL URLTransformer::getPresentation(
const css::util::URL& aURL,
270 if (
aURL.Complete.isEmpty() )
276 css::util::URL aTestURL =
aURL;
277 bool bParseResult = parseSmart( aTestURL, aTestURL.Protocol );
280 if ( !bWithPassword && !aTestURL.Password.isEmpty() )
283 aTestURL.Password =
"<******>";
284 assemble( aTestURL );
288 OUString sPraesentationURL;
291 return sPraesentationURL;
299extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
301 css::uno::XComponentContext *,
302 css::uno::Sequence<css::uno::Any>
const &)
304 return cppu::acquire(
new URLTransformer());
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void SetSmartProtocol(INetProtocol eTheSmartScheme)
sal_uInt32 GetPort() const
static OUString GetScheme(INetProtocol eTheScheme)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static bool translateToExternal(std::u16string_view rTheIntURIRef, OUString &rTheExtURIRef, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString GetMark(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetPass(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool SetSmartURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool ConcatData(INetProtocol eTheScheme, std::u16string_view rTheUser, std::u16string_view rThePassword, std::u16string_view rTheHost, sal_uInt32 nThePort, std::u16string_view rThePath)
static INetProtocol CompareProtocolScheme(std::u16string_view aTheAbsURIRef)
OUString GetUser(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
sal_Int32 getSegmentCount(bool bIgnoreFinalSlash=true) const
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetParam(rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetHost(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
bool SetMark(std::u16string_view rTheFragment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool SetParam(std::u16string_view rTheQuery, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)