Update ooo320-m1
[ooovba.git] / scripting / source / storage / ScriptURI.cxx
blob3ddede974762d407047a5e2c6f0f29d07ab58c26
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScriptURI.cxx,v $
10 * $Revision: 1.11 $
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>
34 #include <osl/file.h>
36 #ifdef _DEBUG
37 #include <stdio.h>
38 #endif
40 //Local headers
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://" );
54 /**
55 * Constructor
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() );
64 if( !isValid() )
66 OSL_TRACE( "ScriptURI ctor: throwing IllegalArgException" );
67 throw IllegalArgumentException(
68 OUSTR( "Failed to parse invalid URI: " ).concat( scriptURI ),
69 Reference < XInterface > (), 1 );
73 /**
74 * Destuctor
77 // dtor should never throw exceptions, so ensure this by specifying it
78 ScriptURI::~ScriptURI() SAL_THROW( () )
80 OSL_TRACE( "< ScriptURI dtor called >\n" );
83 /**
84 * This function is used to determine if this object represents a valid URI
87 bool ScriptURI::isValid( ) {
88 return ( m_valid == sal_True );
91 /**
92 * This function returns the location of the script
95 ::rtl::OUString ScriptURI::getLocation( )
97 return m_location;
101 * This function returns the language of the script, eg. java, StarBasic,...
104 ::rtl::OUString ScriptURI::getLanguage( )
106 return m_language;
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( )
133 return m_uri;
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
158 * initialization.
161 // rather naive parsing?
162 Uri ScriptURI::parseIt()
164 sal_Int32 schemaLen = schema.getLength();
165 scripting_impl::Uri results;
166 results.valid = sal_True;
167 //attempt to parse
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;
174 return results;
177 // substr from here to the '?' and set the logical name
178 sal_Int32 len = m_uri.indexOf( '?' );
179 if( len == -1 )
181 // no queries so just set the logical name
182 results.logicalName = m_uri.copy( schemaLen );
183 return results;
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 );
189 len++;
190 // now get the attributes
191 OUString attr;
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" ) )
199 == sal_True )
201 sal_Int32 len2 = attr.indexOf('=');
202 results.language = attr.copy( len2 + 1 );
203 continue;
205 else if ( attr.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "location" ) )
206 == sal_True )
208 sal_Int32 len2 = attr.indexOf( '=' );
209 results.location = attr.copy( len2 + 1 );
210 continue;
212 else if ( attr.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "function" ) )
213 == sal_True )
215 sal_Int32 len2 = attr.indexOf( '=' );
216 results.functionName = attr.copy( len2 + 1 );
217 continue;
219 else
221 OSL_TRACE( "Unknown attribute?\n" );
224 while ( len >= 0 );
226 // parse is good
227 return results;
230 } // namespace script_uri