1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScriptURI.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
33 #include <osl/diagnose.h>
41 #include "ScriptURI.hxx"
42 #include <util/util.hxx>
44 using namespace ::rtl
;
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::lang
;
50 namespace scripting_impl
{
52 static const OUString schema
= OUString::createFromAscii( "vnd.sun.star.script://" );
57 * @param scriptURI the string script URI
59 ScriptURI::ScriptURI( const ::rtl::OUString
& scriptURI
)
60 throw ( IllegalArgumentException
) : m_uri( scriptURI
)
62 OSL_TRACE( "received uri: %s\n",::rtl::OUStringToOString( m_uri
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
63 set_values( parseIt() );
66 OSL_TRACE( "ScriptURI ctor: throwing IllegalArgException" );
67 throw IllegalArgumentException(
68 OUSTR( "Failed to parse invalid URI: " ).concat( scriptURI
),
69 Reference
< XInterface
> (), 1 );
77 // dtor should never throw exceptions, so ensure this by specifying it
78 ScriptURI::~ScriptURI() SAL_THROW( () )
80 OSL_TRACE( "< ScriptURI dtor called >\n" );
84 * This function is used to determine if this object represents a valid URI
87 bool ScriptURI::isValid( ) {
88 return ( m_valid
== sal_True
);
92 * This function returns the location of the script
95 ::rtl::OUString
ScriptURI::getLocation( )
101 * This function returns the language of the script, eg. java, StarBasic,...
104 ::rtl::OUString
ScriptURI::getLanguage( )
110 * This function returns the language dependent function name of the script
113 ::rtl::OUString
ScriptURI::getFunctionName( )
115 return m_functionName
;
119 * This function returns the language independent logical name of the script
122 ::rtl::OUString
ScriptURI::getLogicalName( )
124 return m_logicalName
;
128 * This function returns the full URI
131 ::rtl::OUString
ScriptURI::getURI( )
136 //Private mutex guarded method for setting the members
137 void ScriptURI::set_values( scripting_impl::Uri values
)
139 osl::Guard
< ::osl::Mutex
> aGuard( m_mutex
);
140 m_valid
= values
.valid
;
141 m_location
= values
.location
;
142 m_language
= values
.language
;
143 // format is vnd.sun.star.script://[function_name]?language=[languge]&location=[location]
144 // LogicalName is now not used anymore, further more the ScriptURI class
145 // will be retired also and a new UNO service will be used. Additionally the
146 // parcel-description will also need to be modified to remove logical name
147 // In order to temporarly support the existing code functionname is
148 // set to the logica name parsed by this class. So getLogicalName() and
149 // getFunctionName() return identical string.
152 m_functionName
= values
.logicalName
;
153 m_logicalName
= values
.logicalName
;
157 * This is a private method used for parsing the URI received by the
161 // rather naive parsing?
162 Uri
ScriptURI::parseIt()
164 sal_Int32 schemaLen
= schema
.getLength();
165 scripting_impl::Uri results
;
166 results
.valid
= sal_True
;
168 // check that it starts vnd.sun.star.script
169 // better check for OBO errors here
170 if( m_uri
.indexOf( schema
) != 0 )
172 OSL_TRACE( "wrong schema" );
173 results
.valid
=sal_False
;
177 // substr from here to the '?' and set the logical name
178 sal_Int32 len
= m_uri
.indexOf( '?' );
181 // no queries so just set the logical name
182 results
.logicalName
= m_uri
.copy( schemaLen
);
185 results
.logicalName
= m_uri
.copy( schemaLen
, len
-schemaLen
);
186 OSL_TRACE( "log name: %s\n", ::rtl::OUStringToOString( results
.logicalName
,
187 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
190 // now get the attributes
194 attr
= m_uri
.getToken( 0, '&', len
);
195 OSL_TRACE( "chunk: %s\n", ::rtl::OUStringToOString( attr
,
196 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
198 if( attr
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "language" ) )
201 sal_Int32 len2
= attr
.indexOf('=');
202 results
.language
= attr
.copy( len2
+ 1 );
205 else if ( attr
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "location" ) )
208 sal_Int32 len2
= attr
.indexOf( '=' );
209 results
.location
= attr
.copy( len2
+ 1 );
212 else if ( attr
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "function" ) )
215 sal_Int32 len2
= attr
.indexOf( '=' );
216 results
.functionName
= attr
.copy( len2
+ 1 );
221 OSL_TRACE( "Unknown attribute?\n" );
230 } // namespace script_uri