Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "urltransformer.hxx"
21 :
22 : #include <com/sun/star/util/URLTransformer.hpp>
23 : #include <tools/debug.hxx>
24 : #include <comphelper/processfactory.hxx>
25 :
26 :
27 : namespace frm
28 : {
29 :
30 :
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::util;
33 : using namespace ::com::sun::star::lang;
34 :
35 369 : UrlTransformer::UrlTransformer( const Reference< XComponentContext >& _rxORB )
36 : :m_xORB( _rxORB )
37 369 : ,m_bTriedToCreateTransformer( false )
38 : {
39 : DBG_ASSERT( _rxORB.is(), "UrlTransformer::UrlTransformer: invalid service factory!" );
40 369 : }
41 :
42 :
43 19 : bool UrlTransformer::implEnsureTransformer() const
44 : {
45 : // create the transformer, if not already attempted to do so
46 19 : if ( !m_xTransformer.is() && !m_bTriedToCreateTransformer )
47 : {
48 1 : if ( m_xORB.is() )
49 : {
50 1 : m_xTransformer.set(URLTransformer::create(m_xORB));
51 : }
52 :
53 1 : m_bTriedToCreateTransformer = true;
54 : }
55 19 : return m_xTransformer.is();
56 : }
57 :
58 :
59 19 : URL UrlTransformer::getStrictURL( const OUString& _rURL ) const
60 : {
61 19 : URL aReturn;
62 19 : aReturn.Complete = _rURL;
63 19 : if ( implEnsureTransformer() )
64 19 : m_xTransformer->parseStrict( aReturn );
65 19 : return aReturn;
66 : }
67 :
68 :
69 19 : URL UrlTransformer::getStrictURLFromAscii( const sal_Char* _pAsciiURL ) const
70 : {
71 19 : return getStrictURL( OUString::createFromAscii( _pAsciiURL ) );
72 : }
73 :
74 :
75 0 : void UrlTransformer::parseSmartWithAsciiProtocol( ::com::sun::star::util::URL& _rURL, const sal_Char* _pAsciiURL ) const
76 : {
77 0 : if ( implEnsureTransformer() )
78 0 : m_xTransformer->parseSmart( _rURL, OUString::createFromAscii( _pAsciiURL ) );
79 0 : }
80 :
81 :
82 : } // namespace frm
83 :
84 :
85 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|