xref: /trunk/main/framework/source/jobs/joburl.cxx (revision cfd52e18)
16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //________________________________
28cdf0e10cSrcweir //  my own includes
29cdf0e10cSrcweir #include <jobs/joburl.hxx>
30cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
31cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
32cdf0e10cSrcweir #include <general.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //________________________________
35cdf0e10cSrcweir //  interface includes
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //________________________________
38cdf0e10cSrcweir //  includes of other projects
39cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //________________________________
43cdf0e10cSrcweir //  namespace
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace framework{
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //________________________________
48cdf0e10cSrcweir //  non exported const
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //________________________________
51cdf0e10cSrcweir //  non exported definitions
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //________________________________
54cdf0e10cSrcweir //  declarations
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //________________________________
57cdf0e10cSrcweir /**
58cdf0e10cSrcweir     @short      special ctor
59cdf0e10cSrcweir     @descr      It initialize this new instance with a (hopyfully) valid job URL.
60cdf0e10cSrcweir                 This URL will be parsed. After that we set our members right,
61cdf0e10cSrcweir                 so other interface methods of this class can be used to get
62cdf0e10cSrcweir                 all items of this URL. Of course it will be possible to know,
63cdf0e10cSrcweir                 if this URL was valid too.
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     @param      sURL
66cdf0e10cSrcweir                     the job URL for parsing
67cdf0e10cSrcweir */
JobURL(const::rtl::OUString & sURL)68cdf0e10cSrcweir JobURL::JobURL( /*IN*/ const ::rtl::OUString& sURL )
69cdf0e10cSrcweir     : ThreadHelpBase( &Application::GetSolarMutex() )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     #ifdef ENABLE_COMPONENT_SELF_CHECK
72cdf0e10cSrcweir     JobURL::impldbg_checkIt();
73cdf0e10cSrcweir     #endif
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     m_eRequest = E_UNKNOWN;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     // syntax: vnd.sun.star.job:{[event=<name>],[alias=<name>],[service=<name>]}
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // check for "vnd.sun.star.job:"
80cdf0e10cSrcweir     if (sURL.matchIgnoreAsciiCaseAsciiL(JOBURL_PROTOCOL_STR,JOBURL_PROTOCOL_LEN,0))
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         sal_Int32 t = JOBURL_PROTOCOL_LEN;
83cdf0e10cSrcweir         do
84cdf0e10cSrcweir         {
8507a3d7f1SPedro Giffuni             // separate all token of "{[event=<name>],[alias=<name>],[service=<name>]}"
86cdf0e10cSrcweir             ::rtl::OUString sToken = sURL.getToken(0, JOBURL_PART_SEPERATOR, t);
87cdf0e10cSrcweir             ::rtl::OUString sPartValue    ;
88cdf0e10cSrcweir             ::rtl::OUString sPartArguments;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             // check for "event="
91cdf0e10cSrcweir             if (
92cdf0e10cSrcweir                 (JobURL::implst_split(sToken,JOBURL_EVENT_STR,JOBURL_EVENT_LEN,sPartValue,sPartArguments)) &&
93cdf0e10cSrcweir                 (sPartValue.getLength()>0                                                                )
94cdf0e10cSrcweir                )
95cdf0e10cSrcweir             {
96cdf0e10cSrcweir                 // set the part value
97cdf0e10cSrcweir                 m_sEvent     = sPartValue    ;
98cdf0e10cSrcweir                 m_sEventArgs = sPartArguments;
99cdf0e10cSrcweir                 m_eRequest  |= E_EVENT       ;
100cdf0e10cSrcweir             }
101cdf0e10cSrcweir             else
102cdf0e10cSrcweir             // check for "alias="
103cdf0e10cSrcweir             if (
104cdf0e10cSrcweir                 (JobURL::implst_split(sToken,JOBURL_ALIAS_STR,JOBURL_ALIAS_LEN,sPartValue,sPartArguments)) &&
105cdf0e10cSrcweir                 (sPartValue.getLength()>0                                                                )
106cdf0e10cSrcweir                )
107cdf0e10cSrcweir             {
108cdf0e10cSrcweir                 // set the part value
109cdf0e10cSrcweir                 m_sAlias     = sPartValue    ;
110cdf0e10cSrcweir                 m_sAliasArgs = sPartArguments;
111cdf0e10cSrcweir                 m_eRequest  |= E_ALIAS       ;
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir             else
114cdf0e10cSrcweir             // check for "service="
115cdf0e10cSrcweir             if (
116cdf0e10cSrcweir                 (JobURL::implst_split(sToken,JOBURL_SERVICE_STR,JOBURL_SERVICE_LEN,sPartValue,sPartArguments)) &&
117cdf0e10cSrcweir                 (sPartValue.getLength()>0                                                                    )
118cdf0e10cSrcweir                )
119cdf0e10cSrcweir             {
120cdf0e10cSrcweir                 // set the part value
121cdf0e10cSrcweir                 m_sService     = sPartValue    ;
122cdf0e10cSrcweir                 m_sServiceArgs = sPartArguments;
123cdf0e10cSrcweir                 m_eRequest    |= E_SERVICE     ;
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir         while(t!=-1);
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //________________________________
131cdf0e10cSrcweir /**
132cdf0e10cSrcweir     @short      knows, if this job URL object hold a valid URL inside
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     @return     <TRUE/> if it represent a valid job URL.
135cdf0e10cSrcweir */
isValid() const136cdf0e10cSrcweir sal_Bool JobURL::isValid() const
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     /* SAFE { */
139cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
140cdf0e10cSrcweir     return (m_eRequest!=E_UNKNOWN);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir //________________________________
144cdf0e10cSrcweir /**
145cdf0e10cSrcweir     @short      get the event item of this job URL
146cdf0e10cSrcweir     @descr      Because the three possible parts of such URL (event, alias, service)
147cdf0e10cSrcweir                 can't be combined, this method can(!) return a valid value - but it's
148*cfd52e18Smseidel                 not a must. That's why the return value must be used too, to detect a missing
149cdf0e10cSrcweir                 event value.
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     @param      sEvent
152cdf0e10cSrcweir                     returns the possible existing event value
153cdf0e10cSrcweir                     e.g. "vnd.sun.star.job:event=myEvent" returns "myEvent"
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     @return     <TRUE/> if an event part of the job URL exist and the out parameter
156cdf0e10cSrcweir                 sEvent was filled.
157cdf0e10cSrcweir 
15807a3d7f1SPedro Giffuni     @attention  The out parameter will be reseted every time. Don't use it if method returns <FALSE/>!
159cdf0e10cSrcweir */
getEvent(::rtl::OUString & sEvent) const160cdf0e10cSrcweir sal_Bool JobURL::getEvent( /*OUT*/ ::rtl::OUString& sEvent ) const
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     /* SAFE { */
163cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
164cdf0e10cSrcweir 
165cdf0e10cSrcweir              sEvent = ::rtl::OUString();
166cdf0e10cSrcweir     sal_Bool bSet   = ((m_eRequest & E_EVENT) == E_EVENT);
167cdf0e10cSrcweir     if (bSet)
168cdf0e10cSrcweir         sEvent = m_sEvent;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     aReadLock.unlock();
171cdf0e10cSrcweir     /* } SAFE */
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     return bSet;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //________________________________
177cdf0e10cSrcweir /**
178cdf0e10cSrcweir     @short      get the alias item of this job URL
179cdf0e10cSrcweir     @descr      Because the three possible parts of such URL (event, alias, service)
180cdf0e10cSrcweir                 can't be combined, this method can(!) return a valid value - but it's
181*cfd52e18Smseidel                 not a must. That's why the return value must be used too, to detect a missing
182cdf0e10cSrcweir                 alias value.
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     @param      sAlias
185cdf0e10cSrcweir                     returns the possible existing alias value
186cdf0e10cSrcweir                     e.g. "vnd.sun.star.job:alias=myAlias" returns "myAlias"
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     @return     <TRUE/> if an alias part of the job URL exist and the out parameter
189cdf0e10cSrcweir                 sAlias was filled.
190cdf0e10cSrcweir 
19107a3d7f1SPedro Giffuni     @attention  The out parameter will be reseted every time. Don't use it if method returns <FALSE/>!
192cdf0e10cSrcweir */
getAlias(::rtl::OUString & sAlias) const193cdf0e10cSrcweir sal_Bool JobURL::getAlias( /*OUT*/ ::rtl::OUString& sAlias ) const
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     /* SAFE { */
196cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir              sAlias = ::rtl::OUString();
199cdf0e10cSrcweir     sal_Bool bSet   = ((m_eRequest & E_ALIAS) == E_ALIAS);
200cdf0e10cSrcweir     if (bSet)
201cdf0e10cSrcweir         sAlias = m_sAlias;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     aReadLock.unlock();
204cdf0e10cSrcweir     /* } SAFE */
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     return bSet;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //________________________________
210cdf0e10cSrcweir /**
211cdf0e10cSrcweir     @short      get the service item of this job URL
212cdf0e10cSrcweir     @descr      Because the three possible parts of such URL (event, service, service)
213cdf0e10cSrcweir                 can't be combined, this method can(!) return a valid value - but it's
214*cfd52e18Smseidel                 not a must. That's why the return value must be used too, to detect a missing
215cdf0e10cSrcweir                 service value.
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     @param      sAlias
218cdf0e10cSrcweir                     returns the possible existing service value
219cdf0e10cSrcweir                     e.g. "vnd.sun.star.job:service=com.sun.star.Service" returns "com.sun.star.Service"
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     @return     <TRUE/> if an service part of the job URL exist and the out parameter
222cdf0e10cSrcweir                 sService was filled.
223cdf0e10cSrcweir 
22407a3d7f1SPedro Giffuni     @attention  The out parameter will be reseted every time. Don't use it if method returns <FALSE/>!
225cdf0e10cSrcweir */
getService(::rtl::OUString & sService) const226cdf0e10cSrcweir sal_Bool JobURL::getService( /*OUT*/ ::rtl::OUString& sService ) const
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     /* SAFE { */
229cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir              sService = ::rtl::OUString();
232cdf0e10cSrcweir     sal_Bool bSet     = ((m_eRequest & E_SERVICE) == E_SERVICE);
233cdf0e10cSrcweir     if (bSet)
234cdf0e10cSrcweir         sService = m_sService;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     aReadLock.unlock();
237cdf0e10cSrcweir     /* } SAFE */
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     return bSet;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir //________________________________
243cdf0e10cSrcweir /**
244cdf0e10cSrcweir     @short      searches for a special identifier in the given string and split it
245cdf0e10cSrcweir     @descr      If the given identifier could be found at the beginning of the given string,
246cdf0e10cSrcweir                 this method split it into different parts and return it.
247cdf0e10cSrcweir                 Following schema is used: <partidentifier>=<partvalue>[?<partarguments>]
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     @param      sPart
250cdf0e10cSrcweir                     the string, which should be analyzed
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     @param      pPartIdentifier
253cdf0e10cSrcweir                     the part identifier value, which must be found at the beginning of the
254cdf0e10cSrcweir                     parameter <var>sPart</var>
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     @param      nPartLength
257cdf0e10cSrcweir                     the length of the ascii value <var>pPartIdentifier</var>
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     @param      rPartValue
260cdf0e10cSrcweir                     returns the part value if <var>sPart</var> was splitted successfully
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     @param      rPartArguments
263cdf0e10cSrcweir                     returns the part arguments if <var>sPart</var> was splitted successfully
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     @return     <TRUE/> if the identifier could be found and the string was splitted.
26615289133Smseidel                 <FALSE/> otherwise.
267cdf0e10cSrcweir */
implst_split(const::rtl::OUString & sPart,const sal_Char * pPartIdentifier,sal_Int32 nPartLength,::rtl::OUString & rPartValue,::rtl::OUString & rPartArguments)268cdf0e10cSrcweir sal_Bool JobURL::implst_split( /*IN*/  const ::rtl::OUString& sPart           ,
269cdf0e10cSrcweir                                /*IN*/  const sal_Char*        pPartIdentifier ,
270cdf0e10cSrcweir                                /*IN*/        sal_Int32        nPartLength     ,
271cdf0e10cSrcweir                                /*OUT*/       ::rtl::OUString& rPartValue      ,
272cdf0e10cSrcweir                                /*OUT*/       ::rtl::OUString& rPartArguments  )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     // first search for the given identifier
275cdf0e10cSrcweir     sal_Bool bPartFound = (sPart.matchIgnoreAsciiCaseAsciiL(pPartIdentifier,nPartLength,0));
276cdf0e10cSrcweir 
27715289133Smseidel     // If it exists - we can split the part and return sal_True.
27815289133Smseidel     // Otherwise we do nothing and return sal_False.
279cdf0e10cSrcweir     if (bPartFound)
280cdf0e10cSrcweir     {
28107a3d7f1SPedro Giffuni         // But may the part has optional arguments - separated by a "?".
282cdf0e10cSrcweir         // Do so - we set the return value with the whole part string.
283cdf0e10cSrcweir         // Arguments will be set to an empty string as default.
284cdf0e10cSrcweir         // If we detect the right sign - we split the arguments and overwrite the default.
285cdf0e10cSrcweir         ::rtl::OUString sValueAndArguments = sPart.copy(nPartLength);
286cdf0e10cSrcweir         ::rtl::OUString sValue             = sValueAndArguments     ;
287cdf0e10cSrcweir         ::rtl::OUString sArguments;
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         sal_Int32 nArgStart = sValueAndArguments.indexOf('?',0);
290cdf0e10cSrcweir         if (nArgStart!=-1)
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             sValue     = sValueAndArguments.copy(0,nArgStart);
293cdf0e10cSrcweir             ++nArgStart; // ignore '?'!
294cdf0e10cSrcweir             sArguments = sValueAndArguments.copy(nArgStart);
295cdf0e10cSrcweir         }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         rPartValue     = sValue    ;
298cdf0e10cSrcweir         rPartArguments = sArguments;
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     return bPartFound;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir //________________________________
305cdf0e10cSrcweir /**
306cdf0e10cSrcweir     @short      special debug method
307cdf0e10cSrcweir     @descr      It's the entry point method to start a self component check for this class.
308cdf0e10cSrcweir                 It's used for internal purposes only and never a part of a legal product.
309cdf0e10cSrcweir                 Use it for testing and debug only!
310cdf0e10cSrcweir */
311cdf0e10cSrcweir #ifdef ENABLE_COMPONENT_SELF_CHECK
312cdf0e10cSrcweir 
313cdf0e10cSrcweir #define LOGFILE_JOBURL  "joburl.log"
314cdf0e10cSrcweir 
impldbg_checkIt()315cdf0e10cSrcweir void JobURL::impldbg_checkIt()
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     // check simple URL's
318cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent"    , E_EVENT  , "onMyEvent", ""       , ""           , NULL, NULL, NULL);
319cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:alias=myAlias"      , E_ALIAS  , ""         , "myAlias", ""           , NULL, NULL, NULL);
320cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service", E_SERVICE, ""         , ""       , "css.Service", NULL, NULL, NULL);
321cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service=;"          , E_UNKNOWN, ""         , ""       , ""           , NULL, NULL, NULL);
322cdf0e10cSrcweir 
323cdf0e10cSrcweir     // check combinations
32407a3d7f1SPedro Giffuni     // Note: No additional spaces or tabs are allowed after a seperator occurred.
325cdf0e10cSrcweir     // Tab and spaces before a seperator will be used as value!
326cdf0e10cSrcweir     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);
327cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service;alias=myAlias"                  , E_ALIAS | E_SERVICE           , ""         , "myAlias", "css.Service" , NULL, NULL, NULL);
328cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service ;alias=myAlias"                 , E_ALIAS | E_SERVICE           , ""         , "myAlias", "css.Service ", NULL, NULL, NULL);
329cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.Service; alias=myAlias"                 , E_UNKNOWN                     , ""         , ""       , ""            , NULL, NULL, NULL);
330cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job : event=onMyEvent"                                  , E_UNKNOWN                     , ""         , ""       , ""            , NULL, NULL, NULL);
331cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent;event=onMyEvent;service=css.Service", E_UNKNOWN                     , ""         , ""       , ""            , NULL, NULL, NULL);
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     // check upper/lower case
334cdf0e10cSrcweir     // fix parts of the URL are case insensitive (e.g. "vnd.SUN.star.job:eVEnt=")
335cdf0e10cSrcweir     // values are case sensitive                 (e.g. "myAlias"                )
336cdf0e10cSrcweir     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);
337cdf0e10cSrcweir     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);
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     // check stupid URLs
340cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.jobs:service=css.Service"    , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
341cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job service=css.Service"     , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
342cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service;css.Service"     , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
343cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service;"                , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
344cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:;alias;service;event="   , E_UNKNOWN, "", "", "", NULL, NULL, NULL);
345cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:alias=a;service=s;event=", E_UNKNOWN, "", "", "", NULL, NULL, NULL);
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     // check argument handling
348cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:event=onMyEvent?eventArg1,eventArg2=3,eventArg4,"            , E_EVENT          , "onMyEvent", ""       , ""             , "eventArg1,eventArg2=3,eventArg4,", NULL                 , NULL          );
349cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:alias=myAlias?aliasArg1,aliasarg2"                           , E_EVENT          , ""         , "myAlias", ""             , NULL                              , "aliasArg1,aliasarg2", NULL          );
350cdf0e10cSrcweir     JobURL::impldbg_checkURL("vnd.sun.star.job:service=css.myService?serviceArg1"                           , E_EVENT          , ""         , ""       , "css.myService", NULL                              , NULL                 , "serviceArg1" );
351cdf0e10cSrcweir     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" );
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir //________________________________
355cdf0e10cSrcweir /**
356cdf0e10cSrcweir     @short      helper debug method
357cdf0e10cSrcweir     @descr      It uses the given parameter to create a new instance of a JobURL.
358cdf0e10cSrcweir                 They results will be compared with the exepected ones.
359cdf0e10cSrcweir                 The a log will be written, which contains some detailed informations
360cdf0e10cSrcweir                 for this sub test.
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     @param      pURL
363cdf0e10cSrcweir                     the job URL, which should be checked
364cdf0e10cSrcweir 
365cdf0e10cSrcweir     @param      eExpectedPart
366cdf0e10cSrcweir                     the expected result
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     @param      pExpectedEvent
369cdf0e10cSrcweir                     the expected event value
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     @param      pExpectedAlias
372cdf0e10cSrcweir                     the expected alias value
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     @param      pExpectedService
375cdf0e10cSrcweir                     the expected service value
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     @param      pExpectedEventArgs
378cdf0e10cSrcweir                     the expected event arguments
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     @param      pExpectedAliasArgs
381cdf0e10cSrcweir                     the expected alias arguments
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     @param      pExpectedServiceArgs
384cdf0e10cSrcweir                     the expected service arguments
385cdf0e10cSrcweir */
impldbg_checkURL(const sal_Char * pURL,sal_uInt32 eExpectedPart,const sal_Char * pExpectedEvent,const sal_Char * pExpectedAlias,const sal_Char * pExpectedService,const sal_Char * pExpectedEventArgs,const sal_Char * pExpectedAliasArgs,const sal_Char * pExpectedServiceArgs)386cdf0e10cSrcweir void JobURL::impldbg_checkURL( /*IN*/ const sal_Char*  pURL                 ,
387cdf0e10cSrcweir                                /*IN*/       sal_uInt32 eExpectedPart        ,
388cdf0e10cSrcweir                                /*IN*/ const sal_Char*  pExpectedEvent       ,
389cdf0e10cSrcweir                                /*IN*/ const sal_Char*  pExpectedAlias       ,
390cdf0e10cSrcweir                                /*IN*/ const sal_Char*  pExpectedService     ,
391cdf0e10cSrcweir                                /*IN*/ const sal_Char*  pExpectedEventArgs   ,
392cdf0e10cSrcweir                                /*IN*/ const sal_Char*  pExpectedAliasArgs   ,
393cdf0e10cSrcweir                                /*IN*/ const sal_Char*  pExpectedServiceArgs )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir     ::rtl::OUString sEvent      ;
396cdf0e10cSrcweir     ::rtl::OUString sAlias      ;
397cdf0e10cSrcweir     ::rtl::OUString sService    ;
398cdf0e10cSrcweir     ::rtl::OUString sEventArgs  ;
399cdf0e10cSrcweir     ::rtl::OUString sAliasArgs  ;
400cdf0e10cSrcweir     ::rtl::OUString sServiceArgs;
401cdf0e10cSrcweir     ::rtl::OUString sURL    (::rtl::OUString::createFromAscii(pURL));
402cdf0e10cSrcweir     sal_Bool        bOK     = sal_True;
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     JobURL aURL(sURL);
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     // check if URL is invalid
407cdf0e10cSrcweir     if (eExpectedPart==E_UNKNOWN)
408cdf0e10cSrcweir         bOK = !aURL.isValid();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     // check if URL has the expected event part
411cdf0e10cSrcweir     if (
412cdf0e10cSrcweir         (bOK                                 ) &&
413cdf0e10cSrcweir         ((eExpectedPart & E_EVENT) == E_EVENT)
414cdf0e10cSrcweir        )
415cdf0e10cSrcweir     {
416cdf0e10cSrcweir         bOK = (
417cdf0e10cSrcweir                 (aURL.isValid()                          ) &&
418cdf0e10cSrcweir                 (aURL.getEvent(sEvent)                   ) &&
419cdf0e10cSrcweir                 (sEvent.getLength()>0                    ) &&
420cdf0e10cSrcweir                 (sEvent.compareToAscii(pExpectedEvent)==0)
421cdf0e10cSrcweir               );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         if (bOK && pExpectedEventArgs!=NULL)
424cdf0e10cSrcweir         {
425cdf0e10cSrcweir             bOK = (
426cdf0e10cSrcweir                     (aURL.getEventArgs(sEventArgs)                   ) &&
427cdf0e10cSrcweir                     (sEventArgs.compareToAscii(pExpectedEventArgs)==0)
428cdf0e10cSrcweir                   );
429cdf0e10cSrcweir         };
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     // check if URL has no event part
433cdf0e10cSrcweir     if (
434cdf0e10cSrcweir         (bOK                                 ) &&
435cdf0e10cSrcweir         ((eExpectedPart & E_EVENT) != E_EVENT)
436cdf0e10cSrcweir        )
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir         bOK = (
439cdf0e10cSrcweir                 (!aURL.getEvent(sEvent)        ) &&
440cdf0e10cSrcweir                 (sEvent.getLength()==0         ) &&
441cdf0e10cSrcweir                 (!aURL.getEventArgs(sEventArgs)) &&
442cdf0e10cSrcweir                 (sEventArgs.getLength()==0     )
443cdf0e10cSrcweir               );
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     // check if URL has the expected alias part
447cdf0e10cSrcweir     if (
448cdf0e10cSrcweir         (bOK                                 ) &&
449cdf0e10cSrcweir         ((eExpectedPart & E_ALIAS) == E_ALIAS)
450cdf0e10cSrcweir        )
451cdf0e10cSrcweir     {
452cdf0e10cSrcweir         bOK = (
453cdf0e10cSrcweir                 (aURL.isValid()                          ) &&
454cdf0e10cSrcweir                 (aURL.getAlias(sAlias)                   ) &&
455cdf0e10cSrcweir                 (sAlias.getLength()>0                    ) &&
456cdf0e10cSrcweir                 (sAlias.compareToAscii(pExpectedAlias)==0)
457cdf0e10cSrcweir               );
458cdf0e10cSrcweir 
459cdf0e10cSrcweir         if (bOK && pExpectedAliasArgs!=NULL)
460cdf0e10cSrcweir         {
461cdf0e10cSrcweir             bOK = (
462cdf0e10cSrcweir                     (aURL.getAliasArgs(sAliasArgs)                   ) &&
463cdf0e10cSrcweir                     (sAliasArgs.compareToAscii(pExpectedAliasArgs)==0)
464cdf0e10cSrcweir                   );
465cdf0e10cSrcweir         };
466cdf0e10cSrcweir     }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     // check if URL has the no alias part
469cdf0e10cSrcweir     if (
470cdf0e10cSrcweir         (bOK                                 ) &&
471cdf0e10cSrcweir         ((eExpectedPart & E_ALIAS) != E_ALIAS)
472cdf0e10cSrcweir        )
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir         bOK = (
475cdf0e10cSrcweir                 (!aURL.getAlias(sAlias)        ) &&
476cdf0e10cSrcweir                 (sAlias.getLength()==0         ) &&
477cdf0e10cSrcweir                 (!aURL.getAliasArgs(sAliasArgs)) &&
478cdf0e10cSrcweir                 (sAliasArgs.getLength()==0     )
479cdf0e10cSrcweir               );
480cdf0e10cSrcweir     }
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     // check if URL has the expected service part
483cdf0e10cSrcweir     if (
484cdf0e10cSrcweir         (bOK                                     ) &&
485cdf0e10cSrcweir         ((eExpectedPart & E_SERVICE) == E_SERVICE)
486cdf0e10cSrcweir        )
487cdf0e10cSrcweir     {
488cdf0e10cSrcweir         bOK = (
489cdf0e10cSrcweir                 (aURL.isValid()                              ) &&
490cdf0e10cSrcweir                 (aURL.getService(sService)                   ) &&
491cdf0e10cSrcweir                 (sService.getLength()>0                      ) &&
492cdf0e10cSrcweir                 (sService.compareToAscii(pExpectedService)==0)
493cdf0e10cSrcweir               );
494cdf0e10cSrcweir 
495cdf0e10cSrcweir         if (bOK && pExpectedServiceArgs!=NULL)
496cdf0e10cSrcweir         {
497cdf0e10cSrcweir             bOK = (
498cdf0e10cSrcweir                     (aURL.getServiceArgs(sServiceArgs)                   ) &&
499cdf0e10cSrcweir                     (sServiceArgs.compareToAscii(pExpectedServiceArgs)==0)
500cdf0e10cSrcweir                   );
501cdf0e10cSrcweir         };
502cdf0e10cSrcweir     }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir     // check if URL has the no service part
505cdf0e10cSrcweir     if (
506cdf0e10cSrcweir         (bOK                                     ) &&
507cdf0e10cSrcweir         ((eExpectedPart & E_SERVICE) != E_SERVICE)
508cdf0e10cSrcweir        )
509cdf0e10cSrcweir     {
510cdf0e10cSrcweir         bOK = (
511cdf0e10cSrcweir                 (!aURL.getService(sService)        ) &&
512cdf0e10cSrcweir                 (sService.getLength()==0           ) &&
513cdf0e10cSrcweir                 (!aURL.getServiceArgs(sServiceArgs)) &&
514cdf0e10cSrcweir                 (sServiceArgs.getLength()==0       )
515cdf0e10cSrcweir               );
516cdf0e10cSrcweir     }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     ::rtl::OUStringBuffer sMsg(256);
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     sMsg.appendAscii("\"" );
521cdf0e10cSrcweir     sMsg.append     (sURL );
522cdf0e10cSrcweir     sMsg.appendAscii("\" ");
523cdf0e10cSrcweir 
524cdf0e10cSrcweir     if (bOK)
525cdf0e10cSrcweir     {
526cdf0e10cSrcweir         sMsg.appendAscii("... OK\n");
527cdf0e10cSrcweir     }
528cdf0e10cSrcweir     else
529cdf0e10cSrcweir     {
530cdf0e10cSrcweir         sMsg.appendAscii("... failed\n");
531cdf0e10cSrcweir         sMsg.appendAscii("expected was: ");
532cdf0e10cSrcweir         if (eExpectedPart==E_UNKNOWN)
533cdf0e10cSrcweir             sMsg.appendAscii("E_UNKNOWN");
534cdf0e10cSrcweir         if ((eExpectedPart & E_EVENT) == E_EVENT)
535cdf0e10cSrcweir         {
536cdf0e10cSrcweir             sMsg.appendAscii("| E_EVENT e=\"");
537cdf0e10cSrcweir             sMsg.appendAscii(pExpectedEvent  );
538cdf0e10cSrcweir             sMsg.appendAscii("\""            );
539cdf0e10cSrcweir         }
540cdf0e10cSrcweir         if ((eExpectedPart & E_ALIAS) == E_ALIAS)
541cdf0e10cSrcweir         {
542cdf0e10cSrcweir             sMsg.appendAscii("| E_ALIAS a=\"");
543cdf0e10cSrcweir             sMsg.appendAscii(pExpectedAlias  );
544cdf0e10cSrcweir             sMsg.appendAscii("\""            );
545cdf0e10cSrcweir         }
546cdf0e10cSrcweir         if ((eExpectedPart & E_SERVICE) == E_SERVICE)
547cdf0e10cSrcweir         {
548cdf0e10cSrcweir             sMsg.appendAscii("| E_SERVICE s=\"");
549cdf0e10cSrcweir             sMsg.appendAscii(pExpectedService  );
550cdf0e10cSrcweir             sMsg.appendAscii("\""              );
551cdf0e10cSrcweir         }
552cdf0e10cSrcweir         sMsg.appendAscii("\tbut it was  : "     );
553cdf0e10cSrcweir         sMsg.append     (aURL.impldbg_toString());
554cdf0e10cSrcweir         sMsg.appendAscii("\n"                   );
555cdf0e10cSrcweir     }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     WRITE_LOGFILE(LOGFILE_JOBURL, U2B(sMsg.makeStringAndClear()))
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir //________________________________
561cdf0e10cSrcweir /**
562cdf0e10cSrcweir     @short      helper debug method
563cdf0e10cSrcweir     @descr      It returns a representation of the internal object state
564cdf0e10cSrcweir                 as string notation.
565cdf0e10cSrcweir 
56630acf5e8Spfg     @returns    The formatted string representation.
567cdf0e10cSrcweir */
impldbg_toString() const568cdf0e10cSrcweir ::rtl::OUString JobURL::impldbg_toString() const
569cdf0e10cSrcweir {
570cdf0e10cSrcweir     /* SAFE { */
571cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     ::rtl::OUStringBuffer sBuffer(256);
574cdf0e10cSrcweir 
575cdf0e10cSrcweir     if (m_eRequest==E_UNKNOWN)
576cdf0e10cSrcweir         sBuffer.appendAscii("E_UNKNOWN");
577cdf0e10cSrcweir     if ((m_eRequest & E_EVENT) == E_EVENT)
578cdf0e10cSrcweir         sBuffer.appendAscii("| E_EVENT");
579cdf0e10cSrcweir     if ((m_eRequest & E_ALIAS) == E_ALIAS)
580cdf0e10cSrcweir         sBuffer.appendAscii("| E_ALIAS");
581cdf0e10cSrcweir     if ((m_eRequest & E_SERVICE) == E_SERVICE)
582cdf0e10cSrcweir         sBuffer.appendAscii("| E_SERVICE");
583cdf0e10cSrcweir     sBuffer.appendAscii("{ e=\""   );
584cdf0e10cSrcweir     sBuffer.append     (m_sEvent   );
585cdf0e10cSrcweir     sBuffer.appendAscii("\" - a=\"");
586cdf0e10cSrcweir     sBuffer.append     (m_sAlias   );
587cdf0e10cSrcweir     sBuffer.appendAscii("\" - s=\"");
588cdf0e10cSrcweir     sBuffer.append     (m_sService );
589cdf0e10cSrcweir     sBuffer.appendAscii("\" }"     );
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     aReadLock.unlock();
592cdf0e10cSrcweir     /* } SAFE */
593cdf0e10cSrcweir 
594cdf0e10cSrcweir     return sBuffer.makeStringAndClear();
595cdf0e10cSrcweir }
596cdf0e10cSrcweir 
597cdf0e10cSrcweir //________________________________
598cdf0e10cSrcweir 
getServiceArgs(::rtl::OUString & sServiceArgs) const599cdf0e10cSrcweir sal_Bool JobURL::getServiceArgs( /*OUT*/ ::rtl::OUString& sServiceArgs ) const
600cdf0e10cSrcweir {
601cdf0e10cSrcweir     /* SAFE { */
602cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
603cdf0e10cSrcweir 
604cdf0e10cSrcweir              sServiceArgs = ::rtl::OUString();
605cdf0e10cSrcweir     sal_Bool bSet         = ((m_eRequest & E_SERVICE) == E_SERVICE);
606cdf0e10cSrcweir     if (bSet)
607cdf0e10cSrcweir         sServiceArgs = m_sServiceArgs;
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     aReadLock.unlock();
610cdf0e10cSrcweir     /* } SAFE */
611cdf0e10cSrcweir 
612cdf0e10cSrcweir     return bSet;
613cdf0e10cSrcweir }
614cdf0e10cSrcweir 
615cdf0e10cSrcweir //________________________________
616cdf0e10cSrcweir 
getEventArgs(::rtl::OUString & sEventArgs) const617cdf0e10cSrcweir sal_Bool JobURL::getEventArgs( /*OUT*/ ::rtl::OUString& sEventArgs ) const
618cdf0e10cSrcweir {
619cdf0e10cSrcweir     /* SAFE { */
620cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
621cdf0e10cSrcweir 
622cdf0e10cSrcweir              sEventArgs = ::rtl::OUString();
623cdf0e10cSrcweir     sal_Bool bSet       = ((m_eRequest & E_EVENT) == E_EVENT);
624cdf0e10cSrcweir     if (bSet)
625cdf0e10cSrcweir         sEventArgs = m_sEventArgs;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     aReadLock.unlock();
628cdf0e10cSrcweir     /* } SAFE */
629cdf0e10cSrcweir 
630cdf0e10cSrcweir     return bSet;
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir //________________________________
634cdf0e10cSrcweir 
getAliasArgs(::rtl::OUString & sAliasArgs) const635cdf0e10cSrcweir sal_Bool JobURL::getAliasArgs( /*OUT*/ ::rtl::OUString& sAliasArgs ) const
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     /* SAFE { */
638cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
639cdf0e10cSrcweir 
640cdf0e10cSrcweir              sAliasArgs = ::rtl::OUString();
641cdf0e10cSrcweir     sal_Bool bSet       = ((m_eRequest & E_ALIAS) == E_ALIAS);
642cdf0e10cSrcweir     if (bSet)
643cdf0e10cSrcweir         sAliasArgs = m_sAliasArgs;
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     aReadLock.unlock();
646cdf0e10cSrcweir     /* } SAFE */
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     return bSet;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir #endif // ENABLE_COMPONENT_SELF_CHECK
652cdf0e10cSrcweir 
653cdf0e10cSrcweir } // namespace framework
654