LCOV - code coverage report
Current view: top level - libreoffice/framework/source/jobs - jobdata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 124 251 49.4 %
Date: 2012-12-27 Functions: 10 25 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <jobs/jobdata.hxx>
      21             : #include <threadhelp/readguard.hxx>
      22             : #include <threadhelp/writeguard.hxx>
      23             : #include <classes/converter.hxx>
      24             : #include <general.h>
      25             : #include <services.h>
      26             : 
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/beans/XMultiHierarchicalPropertySet.hpp>
      29             : #include <com/sun/star/container/XNameAccess.hpp>
      30             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      31             : 
      32             : #include <tools/wldcrd.hxx>
      33             : #include <unotools/configpaths.hxx>
      34             : #include <rtl/ustrbuf.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : 
      37             : 
      38             : namespace framework{
      39             : 
      40             : 
      41             : const sal_Char* JobData::JOBCFG_ROOT              = "/org.openoffice.Office.Jobs/Jobs/"   ;
      42             : const sal_Char* JobData::JOBCFG_PROP_SERVICE      = "Service"                             ;
      43             : const sal_Char* JobData::JOBCFG_PROP_CONTEXT      = "Context"                             ;
      44             : const sal_Char* JobData::JOBCFG_PROP_ARGUMENTS    = "Arguments"                           ;
      45             : 
      46             : const sal_Char* JobData::EVENTCFG_ROOT            = "/org.openoffice.Office.Jobs/Events/" ;
      47             : const sal_Char* JobData::EVENTCFG_PATH_JOBLIST    = "/JobList"                            ;
      48             : const sal_Char* JobData::EVENTCFG_PROP_ADMINTIME  = "AdminTime"                           ;
      49             : const sal_Char* JobData::EVENTCFG_PROP_USERTIME   = "UserTime"                            ;
      50             : 
      51             : const sal_Char* JobData::PROPSET_CONFIG           = "Config"                              ;
      52             : const sal_Char* JobData::PROPSET_OWNCONFIG        = "JobConfig"                           ;
      53             : const sal_Char* JobData::PROPSET_ENVIRONMENT      = "Environment"                         ;
      54             : const sal_Char* JobData::PROPSET_DYNAMICDATA      = "DynamicData"                         ;
      55             : 
      56             : const sal_Char* JobData::PROP_ALIAS               = "Alias"                               ;
      57             : const sal_Char* JobData::PROP_EVENTNAME           = "EventName"                           ;
      58             : const sal_Char* JobData::PROP_ENVTYPE             = "EnvType"                             ;
      59             : const sal_Char* JobData::PROP_FRAME               = "Frame"                               ;
      60             : const sal_Char* JobData::PROP_MODEL               = "Model"                               ;
      61             : const sal_Char* JobData::PROP_SERVICE             = "Service"                             ;
      62             : const sal_Char* JobData::PROP_CONTEXT             = "Context"                             ;
      63             : 
      64             : 
      65             : 
      66             : //________________________________
      67             : /**
      68             :     @short      standard ctor
      69             :     @descr      It initialize this new instance.
      70             :                 But for real working it's neccessary to call setAlias() or setService() later.
      71             :                 Because we need the job data ...
      72             : 
      73             :     @param      rxContext
      74             :                     reference to the uno service manager
      75             : */
      76         124 : JobData::JobData( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
      77         124 :     : ThreadHelpBase(&Application::GetSolarMutex())
      78         124 :     , m_xContext    (rxContext                    )
      79             : {
      80             :     // share code for member initialization with defaults!
      81         124 :     impl_reset();
      82         124 : }
      83             : 
      84             : //________________________________
      85             : /**
      86             :     @short  copy ctor
      87             :     @descr  Sometimes such job data container must be moved from one using place
      88             :             to another one. Then a copy ctor and copy operator must be available.
      89             : 
      90             :     @param  rCopy
      91             :                 the original instance, from which we must copy all data
      92             : */
      93           0 : JobData::JobData( const JobData& rCopy )
      94           0 :     : ThreadHelpBase(&Application::GetSolarMutex())
      95             : {
      96             :     // use the copy operator to share the same code
      97           0 :     *this = rCopy;
      98           0 : }
      99             : 
     100             : //________________________________
     101             : /**
     102             :     @short  operator for coping JobData instances
     103             :     @descr  Sometimes such job data container must be moved from one using place
     104             :             to another one. Then a copy ctor and copy operator must be available.
     105             : 
     106             :     @param  rCopy
     107             :                 the original instance, from which we must copy all data
     108             : */
     109           0 : void JobData::operator=( const JobData& rCopy )
     110             : {
     111             :     /* SAFE { */
     112           0 :     WriteGuard aWriteLock(m_aLock);
     113             :     // Please don't copy the uno service manager reference.
     114             :     // That can change the uno context, which isn't a good idea!
     115           0 :     m_eMode                = rCopy.m_eMode               ;
     116           0 :     m_eEnvironment         = rCopy.m_eEnvironment        ;
     117           0 :     m_sAlias               = rCopy.m_sAlias              ;
     118           0 :     m_sService             = rCopy.m_sService            ;
     119           0 :     m_sContext             = rCopy.m_sContext            ;
     120           0 :     m_sEvent               = rCopy.m_sEvent              ;
     121           0 :     m_lArguments           = rCopy.m_lArguments          ;
     122           0 :     m_aLastExecutionResult = rCopy.m_aLastExecutionResult;
     123           0 :     aWriteLock.unlock();
     124             :     /* } SAFE */
     125           0 : }
     126             : 
     127             : //________________________________
     128             : /**
     129             :     @short  let this instance die
     130             :     @descr  There is no chance any longer to work. We have to
     131             :             release all used resources and free used memory.
     132             : */
     133         248 : JobData::~JobData()
     134             : {
     135         124 :     impl_reset();
     136         124 : }
     137             : 
     138             : //________________________________
     139             : /**
     140             :     @short      initalize this instance as a job with configuration
     141             :     @descr      They given alias can be used to address some configuraton data.
     142             :                 We read it and fill our internal structures. Of course old informations
     143             :                 will be lost doing so.
     144             : 
     145             :     @param      sAlias
     146             :                     the alias name of this job, used to locate job properties inside cfg
     147             : */
     148         124 : void JobData::setAlias( const ::rtl::OUString& sAlias )
     149             : {
     150             :     /* SAFE { */
     151         124 :     WriteGuard aWriteLock(m_aLock);
     152             :     // delete all old informations! Otherwhise we mix it with the new one ...
     153         124 :     impl_reset();
     154             : 
     155             :     // take over the new informations
     156         124 :     m_sAlias   = sAlias;
     157         124 :     m_eMode    = E_ALIAS;
     158             : 
     159             :     // try to open the configuration set of this job directly and get a property access to it
     160             :     // We open it readonly here
     161         124 :     ::rtl::OUString sKey(::rtl::OUString::createFromAscii(JOBCFG_ROOT));
     162         124 :     sKey += ::utl::wrapConfigurationElementName(m_sAlias);
     163             : 
     164         124 :     ConfigAccess aConfig(m_xContext, sKey);
     165         124 :     aConfig.open(ConfigAccess::E_READONLY);
     166         124 :     if (aConfig.getMode()==ConfigAccess::E_CLOSED)
     167             :     {
     168           0 :         impl_reset();
     169         124 :         return;
     170             :     }
     171             : 
     172         124 :     css::uno::Reference< css::beans::XPropertySet > xJobProperties(aConfig.cfg(), css::uno::UNO_QUERY);
     173         124 :     if (xJobProperties.is())
     174             :     {
     175         124 :         css::uno::Any aValue;
     176             : 
     177             :         // read uno implementation name
     178         124 :         aValue   = xJobProperties->getPropertyValue(::rtl::OUString::createFromAscii(JOBCFG_PROP_SERVICE));
     179         124 :         aValue >>= m_sService;
     180             : 
     181             :         // read module context list
     182         124 :         aValue   = xJobProperties->getPropertyValue(::rtl::OUString::createFromAscii(JOBCFG_PROP_CONTEXT));
     183         124 :         aValue >>= m_sContext;
     184             : 
     185             :         // read whole argument list
     186         124 :         aValue = xJobProperties->getPropertyValue(::rtl::OUString::createFromAscii(JOBCFG_PROP_ARGUMENTS));
     187         124 :         css::uno::Reference< css::container::XNameAccess > xArgumentList;
     188         248 :         if (
     189         124 :             (aValue >>= xArgumentList)  &&
     190         124 :             (xArgumentList.is()      )
     191             :            )
     192             :         {
     193         124 :             css::uno::Sequence< ::rtl::OUString > lArgumentNames = xArgumentList->getElementNames();
     194         124 :             sal_Int32                             nCount         = lArgumentNames.getLength();
     195         124 :             m_lArguments.realloc(nCount);
     196         124 :             for (sal_Int32 i=0; i<nCount; ++i)
     197             :             {
     198           0 :                 m_lArguments[i].Name  = lArgumentNames[i];
     199           0 :                 m_lArguments[i].Value = xArgumentList->getByName(m_lArguments[i].Name);
     200         124 :             }
     201         124 :         }
     202             :     }
     203             : 
     204         124 :     aConfig.close();
     205         124 :     aWriteLock.unlock();
     206             :     /* } SAFE */
     207             : }
     208             : 
     209             : //________________________________
     210             : /**
     211             :     @short      initalize this instance as a job without configuration
     212             :     @descr      This job has no configuration data. We have to forget all old informations
     213             :                 and set only some of them new, so this instance can work.
     214             : 
     215             :     @param      sService
     216             :                     the uno service name of this "non configured" job
     217             : */
     218           0 : void JobData::setService( const ::rtl::OUString& sService )
     219             : {
     220             :     /* SAFE { */
     221           0 :     WriteGuard aWriteLock(m_aLock);
     222             : 
     223             :     // delete all old informations! Otherwhise we mix it with the new one ...
     224           0 :     impl_reset();
     225             :     // take over the new informations
     226           0 :     m_sService = sService;
     227           0 :     m_eMode    = E_SERVICE;
     228             : 
     229           0 :     aWriteLock.unlock();
     230             :     /* } SAFE */
     231           0 : }
     232             : 
     233             : //________________________________
     234             : /**
     235             :     @short      initialize this instance with new job values.
     236             :     @descr      It reads automaticly all properties of the specified
     237             :                 job (using it's alias name) and "register it" for the
     238             :                 given event. This registration will not be validated against
     239             :                 the underlying configuration! (That must be done from outside.
     240             :                 Because the caller must have the configuration already open to
     241             :                 get the values for sEvent and sAlias! And doing so it can perform
     242             :                 only, if the time stanp values are readed outside too.
     243             :                 Further it make no sense to initialize and start a disabled job.
     244             :                 So this initialization method will be called for enabled jobs only.)
     245             : 
     246             :     @param      sEvent
     247             :                     the triggered event, for which this job should be started
     248             : 
     249             :     @param      sAlias
     250             :                     mark the required job inside event registration list
     251             : */
     252         124 : void JobData::setEvent( const ::rtl::OUString& sEvent ,
     253             :                         const ::rtl::OUString& sAlias )
     254             : {
     255             :     // share code to read all job properties!
     256         124 :     setAlias(sAlias);
     257             : 
     258             :     /* SAFE { */
     259         124 :     WriteGuard aWriteLock(m_aLock);
     260             : 
     261             :     // take over the new informations - which differ against set on of method setAlias()!
     262         124 :     m_sEvent = sEvent;
     263         124 :     m_eMode  = E_EVENT;
     264             : 
     265         124 :     aWriteLock.unlock();
     266             :     /* } SAFE */
     267         124 : }
     268             : 
     269             : //________________________________
     270             : /**
     271             :     @short      set the new job specific arguments
     272             :     @descr      If a job finish his work, it can give us a new list of arguments (which
     273             :                 will not interpreted by us). We write it back to the configuration only
     274             :                 (if this job has it's own configuration!).
     275             :                 So a job can have persistent data without implementing anything
     276             :                 or define own config areas for that.
     277             : 
     278             :     @param      lArguments
     279             :                     list of arguments, which should be set for this job
     280             :  */
     281           0 : void JobData::setJobConfig( const css::uno::Sequence< css::beans::NamedValue >& lArguments )
     282             : {
     283             :     /* SAFE { */
     284           0 :     WriteGuard aWriteLock(m_aLock);
     285             : 
     286             :     // update member
     287           0 :     m_lArguments = lArguments;
     288             : 
     289             :     // update the configuration ... if possible!
     290           0 :     if (m_eMode==E_ALIAS)
     291             :     {
     292             :         // It doesn't matter if this config object was already opened before.
     293             :         // It doesn nothing here then ... or it change the mode automaticly, if
     294             :         // it was opened using another one before.
     295           0 :         ::rtl::OUString sKey(::rtl::OUString::createFromAscii(JOBCFG_ROOT));
     296           0 :         sKey += ::utl::wrapConfigurationElementName(m_sAlias);
     297             : 
     298           0 :         ConfigAccess aConfig(m_xContext, sKey);
     299           0 :         aConfig.open(ConfigAccess::E_READWRITE);
     300           0 :         if (aConfig.getMode()==ConfigAccess::E_CLOSED)
     301           0 :             return;
     302             : 
     303           0 :         css::uno::Reference< css::beans::XMultiHierarchicalPropertySet > xArgumentList(aConfig.cfg(), css::uno::UNO_QUERY);
     304           0 :         if (xArgumentList.is())
     305             :         {
     306           0 :             sal_Int32                             nCount = m_lArguments.getLength();
     307           0 :             css::uno::Sequence< ::rtl::OUString > lNames (nCount);
     308           0 :             css::uno::Sequence< css::uno::Any >   lValues(nCount);
     309             : 
     310           0 :             for (sal_Int32 i=0; i<nCount; ++i)
     311             :             {
     312           0 :                 lNames [i] = m_lArguments[i].Name ;
     313           0 :                 lValues[i] = m_lArguments[i].Value;
     314             :             }
     315             : 
     316           0 :             xArgumentList->setHierarchicalPropertyValues(lNames, lValues);
     317             :         }
     318           0 :         aConfig.close();
     319             :     }
     320             : 
     321           0 :     aWriteLock.unlock();
     322             :     /* } SAFE */
     323             : }
     324             : 
     325             : //________________________________
     326             : /**
     327             :     @short      set a new excution result
     328             :     @descr      Every executed job can have returned a result.
     329             :                 We set it here, so our user can use it may be later.
     330             :                 But the outside code can use it too, to analyze it and
     331             :                 adopt the configuration of this job too. Because the
     332             :                 result uses a protocol, which allow that. And we provide
     333             :                 right functionality to save it.
     334             : 
     335             :     @param      aResult
     336             :                     the result of last execution
     337             :  */
     338           0 : void JobData::setResult( const JobResult& aResult )
     339             : {
     340             :     /* SAFE { */
     341           0 :     WriteGuard aWriteLock(m_aLock);
     342             : 
     343             :     // overwrite the last saved result
     344           0 :     m_aLastExecutionResult = aResult;
     345             : 
     346             :     // Don't use his informations to update
     347             :     // e.g. the arguments of this job. It must be done
     348             :     // from outside! Here we save this information only.
     349             : 
     350           0 :     aWriteLock.unlock();
     351             :     /* } SAFE */
     352           0 : }
     353             : 
     354             : //________________________________
     355             : /**
     356             :     @short  set a new environment descriptor for this job
     357             :     @descr  It must(!) be done everytime this container is initialized
     358             :             with new job datas e.g.: setAlias()/setEvent()/setService() ...
     359             :             Otherwhise the environment will be unknown!
     360             :  */
     361         124 : void JobData::setEnvironment( EEnvironment eEnvironment )
     362             : {
     363             :     /* SAFE { */
     364         124 :     WriteGuard aWriteLock(m_aLock);
     365         124 :     m_eEnvironment = eEnvironment;
     366         124 :     aWriteLock.unlock();
     367             :     /* } SAFE */
     368         124 : }
     369             : 
     370             : //________________________________
     371             : /**
     372             :     @short      these functions provides access to our internal members
     373             :     @descr      These member represent any information about the job
     374             :                 and can be used from outside to e.g. start a job.
     375             :  */
     376           0 : JobData::EMode JobData::getMode() const
     377             : {
     378             :     /* SAFE { */
     379           0 :     ReadGuard aReadLock(m_aLock);
     380           0 :     return m_eMode;
     381             :     /* } SAFE */
     382             : }
     383             : 
     384             : //________________________________
     385             : 
     386           0 : JobData::EEnvironment JobData::getEnvironment() const
     387             : {
     388             :     /* SAFE { */
     389           0 :     ReadGuard aReadLock(m_aLock);
     390           0 :     return m_eEnvironment;
     391             :     /* } SAFE */
     392             : }
     393             : 
     394             : //________________________________
     395             : 
     396           0 : ::rtl::OUString JobData::getEnvironmentDescriptor() const
     397             : {
     398           0 :     ::rtl::OUString sDescriptor;
     399             :     /* SAFE { */
     400           0 :     ReadGuard aReadLock(m_aLock);
     401           0 :     switch(m_eEnvironment)
     402             :     {
     403             :         case E_EXECUTION :
     404           0 :             sDescriptor = ::rtl::OUString("EXECUTOR");
     405           0 :             break;
     406             : 
     407             :         case E_DISPATCH :
     408           0 :             sDescriptor = ::rtl::OUString("DISPATCH");
     409           0 :             break;
     410             : 
     411             :         case E_DOCUMENTEVENT :
     412           0 :             sDescriptor = ::rtl::OUString("DOCUMENTEVENT");
     413           0 :             break;
     414             :         default:
     415           0 :             break;
     416             :     }
     417             :     /* } SAFE */
     418           0 :     return sDescriptor;
     419             : }
     420             : 
     421             : //________________________________
     422             : 
     423           0 : ::rtl::OUString JobData::getService() const
     424             : {
     425             :     /* SAFE { */
     426           0 :     ReadGuard aReadLock(m_aLock);
     427           0 :     return m_sService;
     428             :     /* } SAFE */
     429             : }
     430             : 
     431             : //________________________________
     432             : 
     433           0 : ::rtl::OUString JobData::getEvent() const
     434             : {
     435             :     /* SAFE { */
     436           0 :     ReadGuard aReadLock(m_aLock);
     437           0 :     return m_sEvent;
     438             :     /* } SAFE */
     439             : }
     440             : 
     441             : //________________________________
     442             : 
     443           0 : css::uno::Sequence< css::beans::NamedValue > JobData::getJobConfig() const
     444             : {
     445             :     /* SAFE { */
     446           0 :     ReadGuard aReadLock(m_aLock);
     447           0 :     return m_lArguments;
     448             :     /* } SAFE */
     449             : }
     450             : 
     451             : //________________________________
     452             : 
     453           0 : css::uno::Sequence< css::beans::NamedValue > JobData::getConfig() const
     454             : {
     455             :     /* SAFE { */
     456           0 :     ReadGuard aReadLock(m_aLock);
     457           0 :     css::uno::Sequence< css::beans::NamedValue > lConfig;
     458           0 :     if (m_eMode==E_ALIAS)
     459             :     {
     460           0 :         lConfig.realloc(3);
     461           0 :         sal_Int32 i = 0;
     462             : 
     463           0 :         lConfig[i].Name = ::rtl::OUString::createFromAscii(PROP_ALIAS);
     464           0 :         lConfig[i].Value <<= m_sAlias;
     465           0 :         ++i;
     466             : 
     467           0 :         lConfig[i].Name = ::rtl::OUString::createFromAscii(PROP_SERVICE);
     468           0 :         lConfig[i].Value <<= m_sService;
     469           0 :         ++i;
     470             : 
     471           0 :         lConfig[i].Name = ::rtl::OUString::createFromAscii(PROP_CONTEXT);
     472           0 :         lConfig[i].Value <<= m_sContext;
     473           0 :         ++i;
     474             :     }
     475           0 :     aReadLock.unlock();
     476             :     /* } SAFE */
     477           0 :     return lConfig;
     478             : }
     479             : 
     480             : //________________________________
     481             : /**
     482             :     @short  return information, if this job is part of the global configuration package
     483             :             org.openoffice.Office.Jobs
     484             :     @descr  Because jobs can be executed by the dispatch framework using an uno service name
     485             :             directly - an executed job must not have any configuration realy. Such jobs
     486             :             must provide the right interfaces only! But after finishing jobs can return
     487             :             some informations (e.g. for updating her configuration ...). We must know
     488             :             if such request is valid or not then.
     489             : 
     490             :     @return sal_True if the represented job is part of the underlying configuration package.
     491             :  */
     492           0 : sal_Bool JobData::hasConfig() const
     493             : {
     494             :     /* SAFE { */
     495           0 :     ReadGuard aReadLock(m_aLock);
     496           0 :     return (m_eMode==E_ALIAS || m_eMode==E_EVENT);
     497             :     /* } SAFE */
     498             : }
     499             : 
     500             : //________________________________
     501             : /**
     502             :     @short      mark a job as non startable for further requests
     503             :     @descr      We don't remove the configuration entry! We set a timestamp value only.
     504             :                 And there exist two of them: one for an administrator ... and one for the
     505             :                 current user. We change it for the user layer only. So this JobDispatch can't be
     506             :                 started any more ... till the administrator change his timestamp.
     507             :                 That can be usefull for post setup scenarios, which must run one time only.
     508             : 
     509             :                 Note: This method don't do anything, if ths represented job doesn't have a configuration!
     510             :  */
     511           0 : void JobData::disableJob()
     512             : {
     513             :     /* SAFE { */
     514           0 :     WriteGuard aWriteLock(m_aLock);
     515             : 
     516             :     // No configuration - not used from EXECUTOR and not triggered from an event => no chance!
     517           0 :     if (m_eMode!=E_EVENT)
     518             :         return;
     519             : 
     520             :     // update the configuration
     521             :     // It doesn't matter if this config object was already opened before.
     522             :     // It doesn nothing here then ... or it change the mode automaticly, if
     523             :     // it was opened using another one before.
     524           0 :     ::rtl::OUStringBuffer sKey(256);
     525           0 :     sKey.appendAscii(JobData::EVENTCFG_ROOT                       );
     526           0 :     sKey.append     (::utl::wrapConfigurationElementName(m_sEvent));
     527           0 :     sKey.appendAscii(JobData::EVENTCFG_PATH_JOBLIST               );
     528           0 :     sKey.appendAscii("/"                                          );
     529           0 :     sKey.append     (::utl::wrapConfigurationElementName(m_sAlias));
     530             : 
     531           0 :     ConfigAccess aConfig(m_xContext, sKey.makeStringAndClear());
     532           0 :     aConfig.open(ConfigAccess::E_READWRITE);
     533           0 :     if (aConfig.getMode()==ConfigAccess::E_CLOSED)
     534             :         return;
     535             : 
     536           0 :     css::uno::Reference< css::beans::XPropertySet > xPropSet(aConfig.cfg(), css::uno::UNO_QUERY);
     537           0 :     if (xPropSet.is())
     538             :     {
     539             :         // Convert and write the user timestamp to the configuration.
     540           0 :         css::uno::Any aValue;
     541           0 :         aValue <<= Converter::convert_DateTime2ISO8601(DateTime( DateTime::SYSTEM));
     542           0 :         xPropSet->setPropertyValue(::rtl::OUString::createFromAscii(EVENTCFG_PROP_USERTIME), aValue);
     543             :     }
     544             : 
     545           0 :     aConfig.close();
     546             : 
     547           0 :     aWriteLock.unlock();
     548             :     /* } SAFE */
     549             : }
     550             : 
     551             : //________________________________
     552             : /**
     553             :  */
     554         124 : sal_Bool isEnabled( const ::rtl::OUString& sAdminTime ,
     555             :                     const ::rtl::OUString& sUserTime  )
     556             : {
     557             :     /*Attention!
     558             :         To prevent interpreting of TriGraphs inside next const string value,
     559             :         we have to encode all '?' signs. Otherwhise e.g. "??-" will be translated
     560             :         to "~" ...
     561             :      */
     562         124 :     static ::rtl::OUString PATTERN_ISO8601("\?\?\?\?-\?\?-\?\?*");
     563         124 :     WildCard aISOPattern(PATTERN_ISO8601);
     564             : 
     565         124 :     sal_Bool bValidAdmin = aISOPattern.Matches(sAdminTime);
     566         124 :     sal_Bool bValidUser  = aISOPattern.Matches(sUserTime );
     567             : 
     568             :     // We check for "isEnabled()" here only.
     569             :     // Note further: ISO8601 formated strings can be compared as strings directly!
     570             :     return (
     571             :             (!bValidAdmin && !bValidUser                         ) ||
     572         124 :             ( bValidAdmin &&  bValidUser && sAdminTime>=sUserTime)
     573         248 :            );
     574             : }
     575             : 
     576             : //________________________________
     577             : /**
     578             :  */
     579         124 : void JobData::appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >&              rxContext,
     580             :                                          const ::rtl::OUString&                                                 sEvent ,
     581             :                                                ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs  )
     582             : {
     583         124 :     css::uno::Sequence< ::rtl::OUString > lAdditionalJobs = JobData::getEnabledJobsForEvent(rxContext, sEvent);
     584         124 :     sal_Int32                             c               = lAdditionalJobs.getLength();
     585         124 :     sal_Int32                             i               = 0;
     586             : 
     587         248 :     for (i=0; i<c; ++i)
     588             :     {
     589         124 :         JobData::TJob2DocEventBinding aBinding(lAdditionalJobs[i], sEvent);
     590         124 :         lJobs.push_back(aBinding);
     591         248 :     }
     592         124 : }
     593             : 
     594             : //________________________________
     595             : /**
     596             :  */
     597         124 : sal_Bool JobData::hasCorrectContext(const ::rtl::OUString& rModuleIdent) const
     598             : {
     599         124 :     sal_Int32 nContextLen  = m_sContext.getLength();
     600         124 :     sal_Int32 nModuleIdLen = rModuleIdent.getLength();
     601             : 
     602         124 :     if ( nContextLen == 0 )
     603           0 :         return sal_True;
     604             : 
     605         124 :     if ( nModuleIdLen > 0 )
     606             :     {
     607         124 :         sal_Int32 nIndex = m_sContext.indexOf( rModuleIdent );
     608         124 :         if ( nIndex >= 0 && ( nIndex+nModuleIdLen <= nContextLen ))
     609             :     {
     610           0 :         ::rtl::OUString sContextModule = m_sContext.copy( nIndex, nModuleIdLen );
     611           0 :         return sContextModule.equals( rModuleIdent );
     612             :     }
     613             :     }
     614             : 
     615         124 :     return sal_False;
     616             : }
     617             : 
     618             : //________________________________
     619             : /**
     620             :  */
     621         124 : css::uno::Sequence< ::rtl::OUString > JobData::getEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
     622             :                                                                        const ::rtl::OUString&                                    sEvent )
     623             : {
     624             :     // these static values may perform following loop for reading time stamp values ...
     625         124 :     static ::rtl::OUString ADMINTIME = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_PROP_ADMINTIME);
     626         124 :     static ::rtl::OUString USERTIME  = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_PROP_USERTIME );
     627         124 :     static ::rtl::OUString ROOT      = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_ROOT          );
     628         124 :     static ::rtl::OUString JOBLIST   = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_PATH_JOBLIST  );
     629             : 
     630             :     // create a config access to "/org.openoffice.Office.Jobs/Events"
     631         124 :     ConfigAccess aConfig(rxContext,ROOT);
     632         124 :     aConfig.open(ConfigAccess::E_READONLY);
     633         124 :     if (aConfig.getMode()==ConfigAccess::E_CLOSED)
     634           0 :         return css::uno::Sequence< ::rtl::OUString >();
     635             : 
     636         124 :     css::uno::Reference< css::container::XHierarchicalNameAccess > xEventRegistry(aConfig.cfg(), css::uno::UNO_QUERY);
     637         124 :     if (!xEventRegistry.is())
     638           0 :         return css::uno::Sequence< ::rtl::OUString >();
     639             : 
     640             :     // check if the given event exist inside list of registered ones
     641         124 :     ::rtl::OUString sPath(sEvent);
     642         124 :     sPath += JOBLIST;
     643         124 :     if (!xEventRegistry->hasByHierarchicalName(sPath))
     644           0 :         return css::uno::Sequence< ::rtl::OUString >();
     645             : 
     646             :     // step to the job list, which is a child of the event node inside cfg
     647             :     // e.g. "/org.openoffice.Office.Jobs/Events/<event name>/JobList"
     648         124 :     css::uno::Any aJobList = xEventRegistry->getByHierarchicalName(sPath);
     649         124 :     css::uno::Reference< css::container::XNameAccess > xJobList;
     650         124 :     if (!(aJobList >>= xJobList) || !xJobList.is())
     651           0 :         return css::uno::Sequence< ::rtl::OUString >();
     652             : 
     653             :     // get all alias names of jobs, which are part of this job list
     654             :     // But Some of them can be disabled by it's time stamp values.
     655             :     // We create an additional job name list iwth the same size, then the original list ...
     656             :     // step over all job entries ... check her time stamps ... and put only job names to the
     657             :     // destination list, which represent an enabled job.
     658         124 :     css::uno::Sequence< ::rtl::OUString > lAllJobs = xJobList->getElementNames();
     659         124 :     ::rtl::OUString* pAllJobs = lAllJobs.getArray();
     660         124 :     sal_Int32 c = lAllJobs.getLength();
     661             : 
     662         124 :     css::uno::Sequence< ::rtl::OUString > lEnabledJobs(c);
     663         124 :     ::rtl::OUString* pEnabledJobs = lEnabledJobs.getArray();
     664         124 :     sal_Int32 d = 0;
     665             : 
     666         248 :     for (sal_Int32 s=0; s<c; ++s)
     667             :     {
     668         124 :         css::uno::Reference< css::beans::XPropertySet > xJob;
     669         620 :         if (
     670         372 :             !(xJobList->getByName(pAllJobs[s]) >>= xJob) ||
     671         124 :             !(xJob.is()     )
     672             :            )
     673             :         {
     674           0 :            continue;
     675             :         }
     676             : 
     677         124 :         ::rtl::OUString sAdminTime;
     678         124 :         xJob->getPropertyValue(ADMINTIME) >>= sAdminTime;
     679             : 
     680         124 :         ::rtl::OUString sUserTime;
     681         124 :         xJob->getPropertyValue(USERTIME) >>= sUserTime;
     682             : 
     683         124 :         if (!isEnabled(sAdminTime, sUserTime))
     684           0 :             continue;
     685             : 
     686         124 :         pEnabledJobs[d] = pAllJobs[s];
     687         124 :         ++d;
     688         124 :     }
     689         124 :     lEnabledJobs.realloc(d);
     690             : 
     691         124 :     aConfig.close();
     692             : 
     693         124 :     return lEnabledJobs;
     694             : }
     695             : 
     696             : //________________________________
     697             : /**
     698             :     @short      reset all internal structures
     699             :     @descr      If somehwere recycle this instance, he can switch from one
     700             :                 using mode to another one. But then we have to reset all currently
     701             :                 used informations. Otherwhise we mix it and they can make trouble.
     702             : 
     703             :                 But note: that does not set defaults for internal used members, which
     704             :                 does not relate to any job property! e.g. the reference to the global
     705             :                 uno service manager. Such informations are used for internal processes only
     706             :                 and are neccessary for our work.
     707             :  */
     708         372 : void JobData::impl_reset()
     709             : {
     710             :     /* SAFE { */
     711         372 :     WriteGuard aWriteLock(m_aLock);
     712         372 :     m_eMode        = E_UNKNOWN_MODE;
     713         372 :     m_eEnvironment = E_UNKNOWN_ENVIRONMENT;
     714         372 :     m_sAlias       = ::rtl::OUString();
     715         372 :     m_sService     = ::rtl::OUString();
     716         372 :     m_sContext     = ::rtl::OUString();
     717         372 :     m_sEvent       = ::rtl::OUString();
     718         372 :     m_lArguments   = css::uno::Sequence< css::beans::NamedValue >();
     719         372 :     aWriteLock.unlock();
     720             :     /* } SAFE */
     721         372 : }
     722             : 
     723             : } // namespace framework
     724             : 
     725             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10