LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/source/jobs - jobdata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 171 255 67.1 %
Date: 2013-07-09 Functions: 21 27 77.8 %
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         654 : JobData::JobData( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
      77         654 :     : ThreadHelpBase(&Application::GetSolarMutex())
      78         654 :     , m_xContext    (rxContext                    )
      79             : {
      80             :     // share code for member initialization with defaults!
      81         654 :     impl_reset();
      82         654 : }
      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          13 : void JobData::operator=( const JobData& rCopy )
     110             : {
     111             :     /* SAFE { */
     112          13 :     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          13 :     m_eMode                = rCopy.m_eMode               ;
     116          13 :     m_eEnvironment         = rCopy.m_eEnvironment        ;
     117          13 :     m_sAlias               = rCopy.m_sAlias              ;
     118          13 :     m_sService             = rCopy.m_sService            ;
     119          13 :     m_sContext             = rCopy.m_sContext            ;
     120          13 :     m_sEvent               = rCopy.m_sEvent              ;
     121          13 :     m_lArguments           = rCopy.m_lArguments          ;
     122          13 :     m_aLastExecutionResult = rCopy.m_aLastExecutionResult;
     123          13 :     aWriteLock.unlock();
     124             :     /* } SAFE */
     125          13 : }
     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        1308 : JobData::~JobData()
     134             : {
     135         654 :     impl_reset();
     136         654 : }
     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 information
     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         641 : void JobData::setAlias( const OUString& sAlias )
     149             : {
     150             :     /* SAFE { */
     151         641 :     WriteGuard aWriteLock(m_aLock);
     152             :     // delete all old information! Otherwhise we mix it with the new one ...
     153         641 :     impl_reset();
     154             : 
     155             :     // take over the new information
     156         641 :     m_sAlias   = sAlias;
     157         641 :     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        1282 :     OUString sKey(OUString::createFromAscii(JOBCFG_ROOT));
     162         641 :     sKey += ::utl::wrapConfigurationElementName(m_sAlias);
     163             : 
     164        1282 :     ConfigAccess aConfig(m_xContext, sKey);
     165         641 :     aConfig.open(ConfigAccess::E_READONLY);
     166         641 :     if (aConfig.getMode()==ConfigAccess::E_CLOSED)
     167             :     {
     168           0 :         impl_reset();
     169         641 :         return;
     170             :     }
     171             : 
     172        1282 :     css::uno::Reference< css::beans::XPropertySet > xJobProperties(aConfig.cfg(), css::uno::UNO_QUERY);
     173         641 :     if (xJobProperties.is())
     174             :     {
     175         641 :         css::uno::Any aValue;
     176             : 
     177             :         // read uno implementation name
     178         641 :         aValue   = xJobProperties->getPropertyValue(OUString::createFromAscii(JOBCFG_PROP_SERVICE));
     179         641 :         aValue >>= m_sService;
     180             : 
     181             :         // read module context list
     182         641 :         aValue   = xJobProperties->getPropertyValue(OUString::createFromAscii(JOBCFG_PROP_CONTEXT));
     183         641 :         aValue >>= m_sContext;
     184             : 
     185             :         // read whole argument list
     186         641 :         aValue = xJobProperties->getPropertyValue(OUString::createFromAscii(JOBCFG_PROP_ARGUMENTS));
     187        1282 :         css::uno::Reference< css::container::XNameAccess > xArgumentList;
     188         641 :         if (
     189        1282 :             (aValue >>= xArgumentList)  &&
     190         641 :             (xArgumentList.is()      )
     191             :            )
     192             :         {
     193         641 :             css::uno::Sequence< OUString > lArgumentNames = xArgumentList->getElementNames();
     194         641 :             sal_Int32                             nCount         = lArgumentNames.getLength();
     195         641 :             m_lArguments.realloc(nCount);
     196         641 :             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         641 :             }
     201         641 :         }
     202             :     }
     203             : 
     204         641 :     aConfig.close();
     205        1282 :     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 information
     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 OUString& sService )
     219             : {
     220             :     /* SAFE { */
     221           0 :     WriteGuard aWriteLock(m_aLock);
     222             : 
     223             :     // delete all old information! Otherwhise we mix it with the new one ...
     224           0 :     impl_reset();
     225             :     // take over the new information
     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         641 : void JobData::setEvent( const OUString& sEvent ,
     253             :                         const OUString& sAlias )
     254             : {
     255             :     // share code to read all job properties!
     256         641 :     setAlias(sAlias);
     257             : 
     258             :     /* SAFE { */
     259         641 :     WriteGuard aWriteLock(m_aLock);
     260             : 
     261             :     // take over the new information - which differ against set on of method setAlias()!
     262         641 :     m_sEvent = sEvent;
     263         641 :     m_eMode  = E_EVENT;
     264             : 
     265         641 :     aWriteLock.unlock();
     266             :     /* } SAFE */
     267         641 : }
     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 :         OUString sKey(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< 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 information 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         641 : void JobData::setEnvironment( EEnvironment eEnvironment )
     362             : {
     363             :     /* SAFE { */
     364         641 :     WriteGuard aWriteLock(m_aLock);
     365         641 :     m_eEnvironment = eEnvironment;
     366         641 :     aWriteLock.unlock();
     367             :     /* } SAFE */
     368         641 : }
     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          13 : JobData::EMode JobData::getMode() const
     377             : {
     378             :     /* SAFE { */
     379          13 :     ReadGuard aReadLock(m_aLock);
     380          13 :     return m_eMode;
     381             :     /* } SAFE */
     382             : }
     383             : 
     384             : //________________________________
     385             : 
     386          13 : JobData::EEnvironment JobData::getEnvironment() const
     387             : {
     388             :     /* SAFE { */
     389          13 :     ReadGuard aReadLock(m_aLock);
     390          13 :     return m_eEnvironment;
     391             :     /* } SAFE */
     392             : }
     393             : 
     394             : //________________________________
     395             : 
     396          13 : OUString JobData::getEnvironmentDescriptor() const
     397             : {
     398          13 :     OUString sDescriptor;
     399             :     /* SAFE { */
     400          26 :     ReadGuard aReadLock(m_aLock);
     401          13 :     switch(m_eEnvironment)
     402             :     {
     403             :         case E_EXECUTION :
     404           0 :             sDescriptor = OUString("EXECUTOR");
     405           0 :             break;
     406             : 
     407             :         case E_DISPATCH :
     408           0 :             sDescriptor = OUString("DISPATCH");
     409           0 :             break;
     410             : 
     411             :         case E_DOCUMENTEVENT :
     412          13 :             sDescriptor = OUString("DOCUMENTEVENT");
     413          13 :             break;
     414             :         default:
     415           0 :             break;
     416             :     }
     417             :     /* } SAFE */
     418          26 :     return sDescriptor;
     419             : }
     420             : 
     421             : //________________________________
     422             : 
     423          13 : OUString JobData::getService() const
     424             : {
     425             :     /* SAFE { */
     426          13 :     ReadGuard aReadLock(m_aLock);
     427          13 :     return m_sService;
     428             :     /* } SAFE */
     429             : }
     430             : 
     431             : //________________________________
     432             : 
     433          13 : OUString JobData::getEvent() const
     434             : {
     435             :     /* SAFE { */
     436          13 :     ReadGuard aReadLock(m_aLock);
     437          13 :     return m_sEvent;
     438             :     /* } SAFE */
     439             : }
     440             : 
     441             : //________________________________
     442             : 
     443          13 : css::uno::Sequence< css::beans::NamedValue > JobData::getJobConfig() const
     444             : {
     445             :     /* SAFE { */
     446          13 :     ReadGuard aReadLock(m_aLock);
     447          13 :     return m_lArguments;
     448             :     /* } SAFE */
     449             : }
     450             : 
     451             : //________________________________
     452             : 
     453          13 : css::uno::Sequence< css::beans::NamedValue > JobData::getConfig() const
     454             : {
     455             :     /* SAFE { */
     456          13 :     ReadGuard aReadLock(m_aLock);
     457          13 :     css::uno::Sequence< css::beans::NamedValue > lConfig;
     458          13 :     if (m_eMode==E_ALIAS)
     459             :     {
     460           0 :         lConfig.realloc(3);
     461           0 :         sal_Int32 i = 0;
     462             : 
     463           0 :         lConfig[i].Name = OUString::createFromAscii(PROP_ALIAS);
     464           0 :         lConfig[i].Value <<= m_sAlias;
     465           0 :         ++i;
     466             : 
     467           0 :         lConfig[i].Name = OUString::createFromAscii(PROP_SERVICE);
     468           0 :         lConfig[i].Value <<= m_sService;
     469           0 :         ++i;
     470             : 
     471           0 :         lConfig[i].Name = OUString::createFromAscii(PROP_CONTEXT);
     472           0 :         lConfig[i].Value <<= m_sContext;
     473           0 :         ++i;
     474             :     }
     475          13 :     aReadLock.unlock();
     476             :     /* } SAFE */
     477          13 :     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 information (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          26 : sal_Bool JobData::hasConfig() const
     493             : {
     494             :     /* SAFE { */
     495          26 :     ReadGuard aReadLock(m_aLock);
     496          26 :     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 useful 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           0 :         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 :     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           0 :         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(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         641 : sal_Bool isEnabled( const OUString& sAdminTime ,
     555             :                     const 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         641 :     static OUString PATTERN_ISO8601("\?\?\?\?-\?\?-\?\?*");
     563         641 :     WildCard aISOPattern(PATTERN_ISO8601);
     564             : 
     565         641 :     sal_Bool bValidAdmin = aISOPattern.Matches(sAdminTime);
     566         641 :     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             :     //               FIXME: this is not true! "T1215" is the same time as "T12:15" or "T121500"
     571             :     return (
     572        1282 :             (!bValidAdmin && !bValidUser                         ) ||
     573         641 :             ( bValidAdmin &&  bValidUser && sAdminTime>=sUserTime)
     574         641 :            );
     575             : }
     576             : 
     577             : //________________________________
     578             : /**
     579             :  */
     580         641 : void JobData::appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >&              rxContext,
     581             :                                          const OUString&                                                 sEvent ,
     582             :                                                ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs  )
     583             : {
     584         641 :     css::uno::Sequence< OUString > lAdditionalJobs = JobData::getEnabledJobsForEvent(rxContext, sEvent);
     585         641 :     sal_Int32                             c               = lAdditionalJobs.getLength();
     586         641 :     sal_Int32                             i               = 0;
     587             : 
     588        1282 :     for (i=0; i<c; ++i)
     589             :     {
     590         641 :         JobData::TJob2DocEventBinding aBinding(lAdditionalJobs[i], sEvent);
     591         641 :         lJobs.push_back(aBinding);
     592        1282 :     }
     593         641 : }
     594             : 
     595             : //________________________________
     596             : /**
     597             :  */
     598         641 : sal_Bool JobData::hasCorrectContext(const OUString& rModuleIdent) const
     599             : {
     600         641 :     sal_Int32 nContextLen  = m_sContext.getLength();
     601         641 :     sal_Int32 nModuleIdLen = rModuleIdent.getLength();
     602             : 
     603         641 :     if ( nContextLen == 0 )
     604           0 :         return sal_True;
     605             : 
     606         641 :     if ( nModuleIdLen > 0 )
     607             :     {
     608         641 :         sal_Int32 nIndex = m_sContext.indexOf( rModuleIdent );
     609         641 :         if ( nIndex >= 0 && ( nIndex+nModuleIdLen <= nContextLen ))
     610             :     {
     611          13 :         OUString sContextModule = m_sContext.copy( nIndex, nModuleIdLen );
     612          13 :         return sContextModule.equals( rModuleIdent );
     613             :     }
     614             :     }
     615             : 
     616         628 :     return sal_False;
     617             : }
     618             : 
     619             : //________________________________
     620             : /**
     621             :  */
     622         641 : css::uno::Sequence< OUString > JobData::getEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
     623             :                                                                        const OUString&                                    sEvent )
     624             : {
     625             :     // these static values may perform following loop for reading time stamp values ...
     626         641 :     static OUString ADMINTIME = OUString::createFromAscii(JobData::EVENTCFG_PROP_ADMINTIME);
     627         641 :     static OUString USERTIME  = OUString::createFromAscii(JobData::EVENTCFG_PROP_USERTIME );
     628         641 :     static OUString ROOT      = OUString::createFromAscii(JobData::EVENTCFG_ROOT          );
     629         641 :     static OUString JOBLIST   = OUString::createFromAscii(JobData::EVENTCFG_PATH_JOBLIST  );
     630             : 
     631             :     // create a config access to "/org.openoffice.Office.Jobs/Events"
     632         641 :     ConfigAccess aConfig(rxContext,ROOT);
     633         641 :     aConfig.open(ConfigAccess::E_READONLY);
     634         641 :     if (aConfig.getMode()==ConfigAccess::E_CLOSED)
     635           0 :         return css::uno::Sequence< OUString >();
     636             : 
     637        1282 :     css::uno::Reference< css::container::XHierarchicalNameAccess > xEventRegistry(aConfig.cfg(), css::uno::UNO_QUERY);
     638         641 :     if (!xEventRegistry.is())
     639           0 :         return css::uno::Sequence< OUString >();
     640             : 
     641             :     // check if the given event exist inside list of registered ones
     642        1282 :     OUString sPath(sEvent);
     643         641 :     sPath += JOBLIST;
     644         641 :     if (!xEventRegistry->hasByHierarchicalName(sPath))
     645           0 :         return css::uno::Sequence< OUString >();
     646             : 
     647             :     // step to the job list, which is a child of the event node inside cfg
     648             :     // e.g. "/org.openoffice.Office.Jobs/Events/<event name>/JobList"
     649        1282 :     css::uno::Any aJobList = xEventRegistry->getByHierarchicalName(sPath);
     650        1282 :     css::uno::Reference< css::container::XNameAccess > xJobList;
     651         641 :     if (!(aJobList >>= xJobList) || !xJobList.is())
     652           0 :         return css::uno::Sequence< OUString >();
     653             : 
     654             :     // get all alias names of jobs, which are part of this job list
     655             :     // But Some of them can be disabled by it's time stamp values.
     656             :     // We create an additional job name list with the same size, then the original list ...
     657             :     // step over all job entries ... check her time stamps ... and put only job names to the
     658             :     // destination list, which represent an enabled job.
     659        1282 :     css::uno::Sequence< OUString > lAllJobs = xJobList->getElementNames();
     660         641 :     OUString* pAllJobs = lAllJobs.getArray();
     661         641 :     sal_Int32 c = lAllJobs.getLength();
     662             : 
     663        1282 :     css::uno::Sequence< OUString > lEnabledJobs(c);
     664         641 :     OUString* pEnabledJobs = lEnabledJobs.getArray();
     665         641 :     sal_Int32 d = 0;
     666             : 
     667        1282 :     for (sal_Int32 s=0; s<c; ++s)
     668             :     {
     669         641 :         css::uno::Reference< css::beans::XPropertySet > xJob;
     670        1282 :         if (
     671        2564 :             !(xJobList->getByName(pAllJobs[s]) >>= xJob) ||
     672         641 :             !(xJob.is()     )
     673             :            )
     674             :         {
     675           0 :            continue;
     676             :         }
     677             : 
     678        1282 :         OUString sAdminTime;
     679         641 :         xJob->getPropertyValue(ADMINTIME) >>= sAdminTime;
     680             : 
     681        1282 :         OUString sUserTime;
     682         641 :         xJob->getPropertyValue(USERTIME) >>= sUserTime;
     683             : 
     684         641 :         if (!isEnabled(sAdminTime, sUserTime))
     685           0 :             continue;
     686             : 
     687         641 :         pEnabledJobs[d] = pAllJobs[s];
     688         641 :         ++d;
     689         641 :     }
     690         641 :     lEnabledJobs.realloc(d);
     691             : 
     692         641 :     aConfig.close();
     693             : 
     694        1282 :     return lEnabledJobs;
     695             : }
     696             : 
     697             : //________________________________
     698             : /**
     699             :     @short      reset all internal structures
     700             :     @descr      If somehwere recycle this instance, he can switch from one
     701             :                 using mode to another one. But then we have to reset all currently
     702             :                 used information. Otherwhise we mix it and they can make trouble.
     703             : 
     704             :                 But note: that does not set defaults for internal used members, which
     705             :                 does not relate to any job property! e.g. the reference to the global
     706             :                 uno service manager. Such information is used for internal processes only
     707             :                 and are neccessary for our work.
     708             :  */
     709        1949 : void JobData::impl_reset()
     710             : {
     711             :     /* SAFE { */
     712        1949 :     WriteGuard aWriteLock(m_aLock);
     713        1949 :     m_eMode        = E_UNKNOWN_MODE;
     714        1949 :     m_eEnvironment = E_UNKNOWN_ENVIRONMENT;
     715        1949 :     m_sAlias       = OUString();
     716        1949 :     m_sService     = OUString();
     717        1949 :     m_sContext     = OUString();
     718        1949 :     m_sEvent       = OUString();
     719        1949 :     m_lArguments   = css::uno::Sequence< css::beans::NamedValue >();
     720        1949 :     aWriteLock.unlock();
     721             :     /* } SAFE */
     722        1949 : }
     723             : 
     724         402 : } // namespace framework
     725             : 
     726             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10