1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "urltransformer.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir /** === end UNO includes === **/
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir //........................................................................
33cdf0e10cSrcweir namespace frm
34cdf0e10cSrcweir {
35cdf0e10cSrcweir //........................................................................
36cdf0e10cSrcweir 
37cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir     using namespace ::com::sun::star::util;
39cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 	//====================================================================
42cdf0e10cSrcweir 	//= UrlTransformer
43cdf0e10cSrcweir 	//====================================================================
44cdf0e10cSrcweir 	//--------------------------------------------------------------------
UrlTransformer(const Reference<XMultiServiceFactory> & _rxORB)45cdf0e10cSrcweir     UrlTransformer::UrlTransformer( const Reference< XMultiServiceFactory >& _rxORB )
46cdf0e10cSrcweir         :m_xORB( _rxORB )
47cdf0e10cSrcweir         ,m_bTriedToCreateTransformer( false )
48cdf0e10cSrcweir     {
49cdf0e10cSrcweir         DBG_ASSERT( _rxORB.is(), "UrlTransformer::UrlTransformer: invalid service factory!" );
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	//--------------------------------------------------------------------
implEnsureTransformer() const53cdf0e10cSrcweir     bool UrlTransformer::implEnsureTransformer() const
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         // create the transformer, if not already attempted to do so
56cdf0e10cSrcweir         if ( !m_xTransformer.is() && !m_bTriedToCreateTransformer )
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             if ( m_xORB.is() )
59cdf0e10cSrcweir             {
60cdf0e10cSrcweir 		        m_xTransformer = m_xTransformer.query(
61cdf0e10cSrcweir                     m_xORB->createInstance(
62cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) )
63cdf0e10cSrcweir                     )
64cdf0e10cSrcweir                 );
65cdf0e10cSrcweir                 DBG_ASSERT( m_xTransformer.is(), "UrlTransformer::getStrictURL: couldn't get an URL transformer!" );
66cdf0e10cSrcweir             }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir             m_bTriedToCreateTransformer = true;
69cdf0e10cSrcweir         }
70cdf0e10cSrcweir         return m_xTransformer.is();
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	//--------------------------------------------------------------------
getStrictURL(const::rtl::OUString & _rURL) const74cdf0e10cSrcweir     URL UrlTransformer::getStrictURL( const ::rtl::OUString& _rURL ) const
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         URL aReturn;
77cdf0e10cSrcweir         aReturn.Complete = _rURL;
78cdf0e10cSrcweir         if ( implEnsureTransformer() )
79cdf0e10cSrcweir             m_xTransformer->parseStrict( aReturn );
80cdf0e10cSrcweir         return aReturn;
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	//--------------------------------------------------------------------
getStrictURLFromAscii(const sal_Char * _pAsciiURL) const84cdf0e10cSrcweir     URL UrlTransformer::getStrictURLFromAscii( const sal_Char* _pAsciiURL ) const
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         return getStrictURL( ::rtl::OUString::createFromAscii( _pAsciiURL ) );
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	//--------------------------------------------------------------------
parseSmartWithAsciiProtocol(::com::sun::star::util::URL & _rURL,const sal_Char * _pAsciiURL) const90cdf0e10cSrcweir     void UrlTransformer::parseSmartWithAsciiProtocol( ::com::sun::star::util::URL& _rURL, const sal_Char* _pAsciiURL ) const
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         if ( implEnsureTransformer() )
93cdf0e10cSrcweir             m_xTransformer->parseSmart( _rURL, ::rtl::OUString::createFromAscii( _pAsciiURL ) );
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //........................................................................
97cdf0e10cSrcweir } // namespace frm
98cdf0e10cSrcweir //........................................................................
99