LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / helper / urltransformer.cxx
blobe112041c2256e690ab678cf2abc2d903c0572bbb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <urltransformer.hxx>
22 #include <com/sun/star/util/URLTransformer.hpp>
23 #include <tools/debug.hxx>
26 namespace frm
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::util;
32 using namespace ::com::sun::star::lang;
34 UrlTransformer::UrlTransformer( const Reference< XComponentContext >& _rxORB )
35 :m_xORB( _rxORB )
36 ,m_bTriedToCreateTransformer( false )
38 DBG_ASSERT( _rxORB.is(), "UrlTransformer::UrlTransformer: invalid service factory!" );
42 bool UrlTransformer::implEnsureTransformer() const
44 // create the transformer, if not already attempted to do so
45 if ( !m_xTransformer.is() && !m_bTriedToCreateTransformer )
47 if ( m_xORB.is() )
49 m_xTransformer.set(URLTransformer::create(m_xORB));
52 m_bTriedToCreateTransformer = true;
54 return m_xTransformer.is();
58 URL UrlTransformer::getStrictURL( const OUString& _rURL ) const
60 URL aReturn;
61 aReturn.Complete = _rURL;
62 if ( implEnsureTransformer() )
63 m_xTransformer->parseStrict( aReturn );
64 return aReturn;
68 URL UrlTransformer::getStrictURLFromAscii( const char* _pAsciiURL ) const
70 return getStrictURL( OUString::createFromAscii( _pAsciiURL ) );
74 void UrlTransformer::parseSmartWithProtocol( css::util::URL& _rURL, const OUString& _rProtocol ) const
76 if ( implEnsureTransformer() )
77 m_xTransformer->parseSmart( _rURL, _rProtocol );
80 } // namespace frm
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */