merge the formfield patch from ooo-build
[ooovba.git] / framework / source / jobs / joburl.cxx
blobec47dadb856da4ad6eaae7211d601822cf40e3ce
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: joburl.cxx,v $
10 * $Revision: 1.6.82.1 $
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_framework.hxx"
34 //________________________________
35 // my own includes
36 #include <jobs/joburl.hxx>
37 #include <threadhelp/readguard.hxx>
38 #include <threadhelp/writeguard.hxx>
39 #include <general.h>
41 //________________________________
42 // interface includes
44 //________________________________
45 // includes of other projects
46 #include <rtl/ustrbuf.hxx>
47 #include <vcl/svapp.hxx>
49 //________________________________
50 // namespace
52 namespace framework{
54 //________________________________
55 // non exported const
57 //________________________________
58 // non exported definitions
60 //________________________________
61 // declarations
63 //________________________________
64 /**
65 @short special ctor
66 @descr It initialize this new instance with a (hopyfully) valid job URL.
67 This URL will be parsed. After that we set our members right,
68 so other interface methods of this class can be used to get
69 all items of this URL. Of course it will be possible to know,
70 if this URL was valid too.
72 @param sURL
73 the job URL for parsing
75 JobURL::JobURL( /*IN*/ const ::rtl::OUString& sURL )
76 : ThreadHelpBase( &Application::GetSolarMutex() )
78 #ifdef ENABLE_COMPONENT_SELF_CHECK
79 JobURL::impldbg_checkIt();
80 #endif
82 m_eRequest = E_UNKNOWN;
84 // syntax: vnd.sun.star.job:{[event=<name>],[alias=<name>],[service=<name>]}
86 // check for "vnd.sun.star.job:"
87 if (sURL.matchIgnoreAsciiCaseAsciiL(JOBURL_PROTOCOL_STR,JOBURL_PROTOCOL_LEN,0))
89 sal_Int32 t = JOBURL_PROTOCOL_LEN;
92 // seperate all token of "{[event=<name>],[alias=<name>],[service=<name>]}"
93 ::rtl::OUString sToken = sURL.getToken(0, JOBURL_PART_SEPERATOR, t);
94 ::rtl::OUString sPartValue ;
95 ::rtl::OUString sPartArguments;
97 // check for "event="
98 if (
99 (JobURL::implst_split(sToken,JOBURL_EVENT_STR,JOBURL_EVENT_LEN,sPartValue,sPartArguments)) &&
100 (sPartValue.getLength()>0 )
103 // set the part value
104 m_sEvent = sPartValue ;
105 m_sEventArgs = sPartArguments;
106 m_eRequest |= E_EVENT ;
108 else
109 // check for "alias="
110 if (
111 (JobURL::implst_split(sToken,JOBURL_ALIAS_STR,JOBURL_ALIAS_LEN,sPartValue,sPartArguments)) &&
112 (sPartValue.getLength()>0 )
115 // set the part value
116 m_sAlias = sPartValue ;
117 m_sAliasArgs = sPartArguments;
118 m_eRequest |= E_ALIAS ;
120 else
121 // check for "service="
122 if (
123 (JobURL::implst_split(sToken,JOBURL_SERVICE_STR,JOBURL_SERVICE_LEN,sPartValue,sPartArguments)) &&
124 (sPartValue.getLength()>0 )
127 // set the part value
128 m_sService = sPartValue ;
129 m_sServiceArgs = sPartArguments;
130 m_eRequest |= E_SERVICE ;
133 while(t!=-1);
137 //________________________________
139 @short knows, if this job URL object hold a valid URL inside
141 @return <TRUE/> if it represent a valid job URL.
143 sal_Bool JobURL::isValid() const
145 /* SAFE { */
146 ReadGuard aReadLock(m_aLock);
147 return (m_eRequest!=E_UNKNOWN);
150 //________________________________
152 @short get the event item of this job URL
153 @descr Because the three possible parts of such URL (event, alias, service)
154 can't be combined, this method can(!) return a valid value - but it's
155 not a must. Thats why the return value must be used too, to detect a missing
156 event value.
158 @param sEvent
159 returns the possible existing event value
160 e.g. "vnd.sun.star.job:event=myEvent" returns "myEvent"
162 @return <TRUE/> if an event part of the job URL exist and the out parameter
163 sEvent was filled.
165 @attention The out parameter will be reseted everytime. Don't use it if method returns <FALSE/>!
167 sal_Bool JobURL::getEvent( /*OUT*/ ::rtl::OUString& sEvent ) const
169 /* SAFE { */
170 ReadGuard aReadLock(m_aLock);
172 sEvent = ::rtl::OUString();
173 sal_Bool bSet = ((m_eRequest & E_EVENT) == E_EVENT);
174 if (bSet)
175 sEvent = m_sEvent;
177 aReadLock.unlock();
178 /* } SAFE */
180 return bSet;
183 //________________________________
185 @short get the alias item of this job URL
186 @descr Because the three possible parts of such URL (event, alias, service)
187 can't be combined, this method can(!) return a valid value - but it's
188 not a must. Thats why the return value must be used too, to detect a missing
189 alias value.
191 @param sAlias
192 returns the possible existing alias value
193 e.g. "vnd.sun.star.job:alias=myAlias" returns "myAlias"
195 @return <TRUE/> if an alias part of the job URL exist and the out parameter
196 sAlias was filled.
198 @attention The out parameter will be reseted everytime. Don't use it if method returns <FALSE/>!
200 sal_Bool JobURL::getAlias( /*OUT*/ ::rtl::OUString& sAlias ) const
202 /* SAFE { */
203 ReadGuard aReadLock(m_aLock);
205 sAlias = ::rtl::OUString();
206 sal_Bool bSet = ((m_eRequest & E_ALIAS) == E_ALIAS);
207 if (bSet)
208 sAlias = m_sAlias;
210 aReadLock.unlock();
211 /* } SAFE */
213 return bSet;
216 //________________________________
218 @short get the service item of this job URL
219 @descr Because the three possible parts of such URL (event, service, service)
220 can't be combined, this method can(!) return a valid value - but it's
221 not a must. Thats why the return value must be used too, to detect a missing
222 service value.
224 @param sAlias
225 returns the possible existing service value
226 e.g. "vnd.sun.star.job:service=com.sun.star.Service" returns "com.sun.star.Service"
228 @return <TRUE/> if an service part of the job URL exist and the out parameter
229 sService was filled.
231 @attention The out parameter will be reseted everytime. Don't use it if method returns <FALSE/>!
233 sal_Bool JobURL::getService( /*OUT*/ ::rtl::OUString& sService ) const
235 /* SAFE { */
236 ReadGuard aReadLock(m_aLock);
238 sService = ::rtl::OUString();
239 sal_Bool bSet = ((m_eRequest & E_SERVICE) == E_SERVICE);
240 if (bSet)
241 sService = m_sService;
243 aReadLock.unlock();
244 /* } SAFE */
246 return bSet;
249 //________________________________
251 @short searches for a special identifier in the given string and split it
252 @descr If the given identifier could be found at the beginning of the given string,
253 this method split it into different parts and return it.
254 Following schema is used: <partidentifier>=<partvalue>[?<partarguments>]
256 @param sPart
257 the string, which should be analyzed
259 @param pPartIdentifier
260 the part identifier value, which must be found at the beginning of the
261 parameter <var>sPart</var>
263 @param nPartLength
264 the length of the ascii value <var>pPartIdentifier</var>
266 @param rPartValue
267 returns the part value if <var>sPart</var> was splitted successfully
269 @param rPartArguments
270 returns the part arguments if <var>sPart</var> was splitted successfully
272 @return <TRUE/> if the identifier could be found and the string was splitted.
273 <FALSE/> otherwhise.
275 sal_Bool JobURL::implst_split( /*IN*/ const ::rtl::OUString& sPart ,
276 /*IN*/ const sal_Char* pPartIdentifier ,
277 /*IN*/ sal_Int32 nPartLength ,
278 /*OUT*/ ::rtl::OUString& rPartValue ,
279 /*OUT*/ ::rtl::OUString& rPartArguments )
281 // first search for the given identifier
282 sal_Bool bPartFound = (sPart.matchIgnoreAsciiCaseAsciiL(pPartIdentifier,nPartLength,0));
284 // If it exist - we can split the part and return TRUE.
285 // Otherwhise we do nothing and return FALSE.
286 if (bPartFound)
288 // But may the part has optional arguments - seperated by a "?".
289 // Do so - we set the return value with the whole part string.
290 // Arguments will be set to an empty string as default.
291 // If we detect the right sign - we split the arguments and overwrite the default.
292 ::rtl::OUString sValueAndArguments = sPart.copy(nPartLength);
293 ::rtl::OUString sValue = sValueAndArguments ;
294 ::rtl::OUString sArguments;
296 sal_Int32 nArgStart = sValueAndArguments.indexOf('?',0);
297 if (nArgStart!=-1)
299 sValue = sValueAndArguments.copy(0,nArgStart);
300 ++nArgStart; // ignore '?'!
301 sArguments = sValueAndArguments.copy(nArgStart);
304 rPartValue = sValue ;
305 rPartArguments = sArguments;
308 return bPartFound;
311 //________________________________
313 @short special debug method
314 @descr It's the entry point method to start a self component check for this class.
315 It's used for internal purposes only and never a part of a legal product.
316 Use it for testing and debug only!
318 #ifdef ENABLE_COMPONENT_SELF_CHECK
320 #define LOGFILE_JOBURL "joburl.log"
322 void JobURL::impldbg_checkIt()
324 // check simple URL's
325 JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent" , E_EVENT , "onMyEvent", "" , "" , NULL, NULL, NULL);
326 JobURL::impldbg_checkURL("vnd.sun.star.job:alias=myAlias" , E_ALIAS , "" , "myAlias", "" , NULL, NULL, NULL);
327 JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service", E_SERVICE, "" , "" , "css.Service", NULL, NULL, NULL);
328 JobURL::impldbg_checkURL("vnd.sun.star.job:service=;" , E_UNKNOWN, "" , "" , "" , NULL, NULL, NULL);
330 // check combinations
331 // Note: No additional spaces or tabs are allowed after a seperator occured.
332 // Tab and spaces before a seperator will be used as value!
333 JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent;alias=myAlias;service=css.Service" , E_EVENT | E_ALIAS | E_SERVICE , "onMyEvent", "myAlias", "css.Service" , NULL, NULL, NULL);
334 JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service;alias=myAlias" , E_ALIAS | E_SERVICE , "" , "myAlias", "css.Service" , NULL, NULL, NULL);
335 JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service ;alias=myAlias" , E_ALIAS | E_SERVICE , "" , "myAlias", "css.Service ", NULL, NULL, NULL);
336 JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service; alias=myAlias" , E_UNKNOWN , "" , "" , "" , NULL, NULL, NULL);
337 JobURL::impldbg_checkURL("vnd.sun.star.job : event=onMyEvent" , E_UNKNOWN , "" , "" , "" , NULL, NULL, NULL);
338 JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent;event=onMyEvent;service=css.Service", E_UNKNOWN , "" , "" , "" , NULL, NULL, NULL);
340 // check upper/lower case
341 // fix parts of the URL are case insensitive (e.g. "vnd.SUN.star.job:eVEnt=")
342 // values are case sensitive (e.g. "myAlias" )
343 JobURL::impldbg_checkURL("vnd.SUN.star.job:eVEnt=onMyEvent;aliAs=myAlias;serVice=css.Service", E_EVENT | E_ALIAS | E_SERVICE , "onMyEvent", "myAlias", "css.Service" , NULL, NULL, NULL);
344 JobURL::impldbg_checkURL("vnd.SUN.star.job:eVEnt=onMyEVENT;aliAs=myALIAS;serVice=css.SERVICE", E_EVENT | E_ALIAS | E_SERVICE , "onMyEVENT", "myALIAS", "css.SERVICE" , NULL, NULL, NULL);
346 // check stupid URLs
347 JobURL::impldbg_checkURL("vnd.sun.star.jobs:service=css.Service" , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
348 JobURL::impldbg_checkURL("vnd.sun.star.job service=css.Service" , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
349 JobURL::impldbg_checkURL("vnd.sun.star.job:service;css.Service" , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
350 JobURL::impldbg_checkURL("vnd.sun.star.job:service;" , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
351 JobURL::impldbg_checkURL("vnd.sun.star.job:;alias;service;event=" , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
352 JobURL::impldbg_checkURL("vnd.sun.star.job:alias=a;service=s;event=", E_UNKNOWN, "", "", "", NULL, NULL, NULL);
354 // check argument handling
355 JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent?eventArg1,eventArg2=3,eventArg4," , E_EVENT , "onMyEvent", "" , "" , "eventArg1,eventArg2=3,eventArg4,", NULL , NULL );
356 JobURL::impldbg_checkURL("vnd.sun.star.job:alias=myAlias?aliasArg1,aliasarg2" , E_EVENT , "" , "myAlias", "" , NULL , "aliasArg1,aliasarg2", NULL );
357 JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.myService?serviceArg1" , E_EVENT , "" , "" , "css.myService", NULL , NULL , "serviceArg1" );
358 JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.myService?serviceArg1;alias=myAlias?aliasArg=564", E_EVENT | E_ALIAS, "" , "myAlias", "css.myService", NULL , "aliasArg=564" , "serviceArg1" );
361 //________________________________
363 @short helper debug method
364 @descr It uses the given parameter to create a new instance of a JobURL.
365 They results will be compared with the exepected ones.
366 The a log will be written, which contains some detailed informations
367 for this sub test.
369 @param pURL
370 the job URL, which should be checked
372 @param eExpectedPart
373 the expected result
375 @param pExpectedEvent
376 the expected event value
378 @param pExpectedAlias
379 the expected alias value
381 @param pExpectedService
382 the expected service value
384 @param pExpectedEventArgs
385 the expected event arguments
387 @param pExpectedAliasArgs
388 the expected alias arguments
390 @param pExpectedServiceArgs
391 the expected service arguments
393 void JobURL::impldbg_checkURL( /*IN*/ const sal_Char* pURL ,
394 /*IN*/ sal_uInt32 eExpectedPart ,
395 /*IN*/ const sal_Char* pExpectedEvent ,
396 /*IN*/ const sal_Char* pExpectedAlias ,
397 /*IN*/ const sal_Char* pExpectedService ,
398 /*IN*/ const sal_Char* pExpectedEventArgs ,
399 /*IN*/ const sal_Char* pExpectedAliasArgs ,
400 /*IN*/ const sal_Char* pExpectedServiceArgs )
402 ::rtl::OUString sEvent ;
403 ::rtl::OUString sAlias ;
404 ::rtl::OUString sService ;
405 ::rtl::OUString sEventArgs ;
406 ::rtl::OUString sAliasArgs ;
407 ::rtl::OUString sServiceArgs;
408 ::rtl::OUString sURL (::rtl::OUString::createFromAscii(pURL));
409 sal_Bool bOK = sal_True;
411 JobURL aURL(sURL);
413 // check if URL is invalid
414 if (eExpectedPart==E_UNKNOWN)
415 bOK = !aURL.isValid();
417 // check if URL has the expected event part
418 if (
419 (bOK ) &&
420 ((eExpectedPart & E_EVENT) == E_EVENT)
423 bOK = (
424 (aURL.isValid() ) &&
425 (aURL.getEvent(sEvent) ) &&
426 (sEvent.getLength()>0 ) &&
427 (sEvent.compareToAscii(pExpectedEvent)==0)
430 if (bOK && pExpectedEventArgs!=NULL)
432 bOK = (
433 (aURL.getEventArgs(sEventArgs) ) &&
434 (sEventArgs.compareToAscii(pExpectedEventArgs)==0)
439 // check if URL has no event part
440 if (
441 (bOK ) &&
442 ((eExpectedPart & E_EVENT) != E_EVENT)
445 bOK = (
446 (!aURL.getEvent(sEvent) ) &&
447 (sEvent.getLength()==0 ) &&
448 (!aURL.getEventArgs(sEventArgs)) &&
449 (sEventArgs.getLength()==0 )
453 // check if URL has the expected alias part
454 if (
455 (bOK ) &&
456 ((eExpectedPart & E_ALIAS) == E_ALIAS)
459 bOK = (
460 (aURL.isValid() ) &&
461 (aURL.getAlias(sAlias) ) &&
462 (sAlias.getLength()>0 ) &&
463 (sAlias.compareToAscii(pExpectedAlias)==0)
466 if (bOK && pExpectedAliasArgs!=NULL)
468 bOK = (
469 (aURL.getAliasArgs(sAliasArgs) ) &&
470 (sAliasArgs.compareToAscii(pExpectedAliasArgs)==0)
475 // check if URL has the no alias part
476 if (
477 (bOK ) &&
478 ((eExpectedPart & E_ALIAS) != E_ALIAS)
481 bOK = (
482 (!aURL.getAlias(sAlias) ) &&
483 (sAlias.getLength()==0 ) &&
484 (!aURL.getAliasArgs(sAliasArgs)) &&
485 (sAliasArgs.getLength()==0 )
489 // check if URL has the expected service part
490 if (
491 (bOK ) &&
492 ((eExpectedPart & E_SERVICE) == E_SERVICE)
495 bOK = (
496 (aURL.isValid() ) &&
497 (aURL.getService(sService) ) &&
498 (sService.getLength()>0 ) &&
499 (sService.compareToAscii(pExpectedService)==0)
502 if (bOK && pExpectedServiceArgs!=NULL)
504 bOK = (
505 (aURL.getServiceArgs(sServiceArgs) ) &&
506 (sServiceArgs.compareToAscii(pExpectedServiceArgs)==0)
511 // check if URL has the no service part
512 if (
513 (bOK ) &&
514 ((eExpectedPart & E_SERVICE) != E_SERVICE)
517 bOK = (
518 (!aURL.getService(sService) ) &&
519 (sService.getLength()==0 ) &&
520 (!aURL.getServiceArgs(sServiceArgs)) &&
521 (sServiceArgs.getLength()==0 )
525 ::rtl::OUStringBuffer sMsg(256);
527 sMsg.appendAscii("\"" );
528 sMsg.append (sURL );
529 sMsg.appendAscii("\" ");
531 if (bOK)
533 sMsg.appendAscii("... OK\n");
535 else
537 sMsg.appendAscii("... failed\n");
538 sMsg.appendAscii("expected was: ");
539 if (eExpectedPart==E_UNKNOWN)
540 sMsg.appendAscii("E_UNKNOWN");
541 if ((eExpectedPart & E_EVENT) == E_EVENT)
543 sMsg.appendAscii("| E_EVENT e=\"");
544 sMsg.appendAscii(pExpectedEvent );
545 sMsg.appendAscii("\"" );
547 if ((eExpectedPart & E_ALIAS) == E_ALIAS)
549 sMsg.appendAscii("| E_ALIAS a=\"");
550 sMsg.appendAscii(pExpectedAlias );
551 sMsg.appendAscii("\"" );
553 if ((eExpectedPart & E_SERVICE) == E_SERVICE)
555 sMsg.appendAscii("| E_SERVICE s=\"");
556 sMsg.appendAscii(pExpectedService );
557 sMsg.appendAscii("\"" );
559 sMsg.appendAscii("\tbut it was : " );
560 sMsg.append (aURL.impldbg_toString());
561 sMsg.appendAscii("\n" );
564 WRITE_LOGFILE(LOGFILE_JOBURL, U2B(sMsg.makeStringAndClear()))
567 //________________________________
569 @short helper debug method
570 @descr It returns a representation of the internal object state
571 as string notation.
573 @returns The formated string representation.
575 ::rtl::OUString JobURL::impldbg_toString() const
577 /* SAFE { */
578 ReadGuard aReadLock(m_aLock);
580 ::rtl::OUStringBuffer sBuffer(256);
582 if (m_eRequest==E_UNKNOWN)
583 sBuffer.appendAscii("E_UNKNOWN");
584 if ((m_eRequest & E_EVENT) == E_EVENT)
585 sBuffer.appendAscii("| E_EVENT");
586 if ((m_eRequest & E_ALIAS) == E_ALIAS)
587 sBuffer.appendAscii("| E_ALIAS");
588 if ((m_eRequest & E_SERVICE) == E_SERVICE)
589 sBuffer.appendAscii("| E_SERVICE");
590 sBuffer.appendAscii("{ e=\"" );
591 sBuffer.append (m_sEvent );
592 sBuffer.appendAscii("\" - a=\"");
593 sBuffer.append (m_sAlias );
594 sBuffer.appendAscii("\" - s=\"");
595 sBuffer.append (m_sService );
596 sBuffer.appendAscii("\" }" );
598 aReadLock.unlock();
599 /* } SAFE */
601 return sBuffer.makeStringAndClear();
604 //________________________________
606 sal_Bool JobURL::getServiceArgs( /*OUT*/ ::rtl::OUString& sServiceArgs ) const
608 /* SAFE { */
609 ReadGuard aReadLock(m_aLock);
611 sServiceArgs = ::rtl::OUString();
612 sal_Bool bSet = ((m_eRequest & E_SERVICE) == E_SERVICE);
613 if (bSet)
614 sServiceArgs = m_sServiceArgs;
616 aReadLock.unlock();
617 /* } SAFE */
619 return bSet;
622 //________________________________
624 sal_Bool JobURL::getEventArgs( /*OUT*/ ::rtl::OUString& sEventArgs ) const
626 /* SAFE { */
627 ReadGuard aReadLock(m_aLock);
629 sEventArgs = ::rtl::OUString();
630 sal_Bool bSet = ((m_eRequest & E_EVENT) == E_EVENT);
631 if (bSet)
632 sEventArgs = m_sEventArgs;
634 aReadLock.unlock();
635 /* } SAFE */
637 return bSet;
640 //________________________________
642 sal_Bool JobURL::getAliasArgs( /*OUT*/ ::rtl::OUString& sAliasArgs ) const
644 /* SAFE { */
645 ReadGuard aReadLock(m_aLock);
647 sAliasArgs = ::rtl::OUString();
648 sal_Bool bSet = ((m_eRequest & E_ALIAS) == E_ALIAS);
649 if (bSet)
650 sAliasArgs = m_sAliasArgs;
652 aReadLock.unlock();
653 /* } SAFE */
655 return bSet;
658 #endif // ENABLE_COMPONENT_SELF_CHECK
660 } // namespace framework