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_forms.hxx"
26 #include "urltransformer.hxx"
27 
28 /** === begin UNO includes === **/
29 /** === end UNO includes === **/
30 #include <tools/debug.hxx>
31 
32 //........................................................................
33 namespace frm
34 {
35 //........................................................................
36 
37     using namespace ::com::sun::star::uno;
38     using namespace ::com::sun::star::util;
39     using namespace ::com::sun::star::lang;
40 
41 	//====================================================================
42 	//= UrlTransformer
43 	//====================================================================
44 	//--------------------------------------------------------------------
UrlTransformer(const Reference<XMultiServiceFactory> & _rxORB)45     UrlTransformer::UrlTransformer( const Reference< XMultiServiceFactory >& _rxORB )
46         :m_xORB( _rxORB )
47         ,m_bTriedToCreateTransformer( false )
48     {
49         DBG_ASSERT( _rxORB.is(), "UrlTransformer::UrlTransformer: invalid service factory!" );
50     }
51 
52 	//--------------------------------------------------------------------
implEnsureTransformer() const53     bool UrlTransformer::implEnsureTransformer() const
54     {
55         // create the transformer, if not already attempted to do so
56         if ( !m_xTransformer.is() && !m_bTriedToCreateTransformer )
57         {
58             if ( m_xORB.is() )
59             {
60 		        m_xTransformer = m_xTransformer.query(
61                     m_xORB->createInstance(
62                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) )
63                     )
64                 );
65                 DBG_ASSERT( m_xTransformer.is(), "UrlTransformer::getStrictURL: couldn't get an URL transformer!" );
66             }
67 
68             m_bTriedToCreateTransformer = true;
69         }
70         return m_xTransformer.is();
71     }
72 
73 	//--------------------------------------------------------------------
getStrictURL(const::rtl::OUString & _rURL) const74     URL UrlTransformer::getStrictURL( const ::rtl::OUString& _rURL ) const
75     {
76         URL aReturn;
77         aReturn.Complete = _rURL;
78         if ( implEnsureTransformer() )
79             m_xTransformer->parseStrict( aReturn );
80         return aReturn;
81     }
82 
83 	//--------------------------------------------------------------------
getStrictURLFromAscii(const sal_Char * _pAsciiURL) const84     URL UrlTransformer::getStrictURLFromAscii( const sal_Char* _pAsciiURL ) const
85     {
86         return getStrictURL( ::rtl::OUString::createFromAscii( _pAsciiURL ) );
87     }
88 
89 	//--------------------------------------------------------------------
parseSmartWithAsciiProtocol(::com::sun::star::util::URL & _rURL,const sal_Char * _pAsciiURL) const90     void UrlTransformer::parseSmartWithAsciiProtocol( ::com::sun::star::util::URL& _rURL, const sal_Char* _pAsciiURL ) const
91     {
92         if ( implEnsureTransformer() )
93             m_xTransformer->parseSmart( _rURL, ::rtl::OUString::createFromAscii( _pAsciiURL ) );
94     }
95 
96 //........................................................................
97 } // namespace frm
98 //........................................................................
99