LCOV - code coverage report
Current view: top level - i18npool/source/calendar - calendarImpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 96 166 57.8 %
Date: 2015-06-13 12:38:46 Functions: 24 34 70.6 %
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 "calendarImpl.hxx"
      21             : #include "localedata.hxx"
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : 
      25             : using namespace ::com::sun::star::uno;
      26             : using namespace ::com::sun::star::lang;
      27             : 
      28             : namespace com { namespace sun { namespace star { namespace i18n {
      29             : 
      30             : #define ERROR RuntimeException()
      31             : 
      32         230 : CalendarImpl::CalendarImpl(const Reference< XComponentContext > &rxContext) : m_xContext(rxContext)
      33             : {
      34         230 : }
      35             : 
      36         940 : CalendarImpl::~CalendarImpl()
      37             : {
      38             :     // Clear lookuptable
      39         564 :     for (size_t l = 0; l < lookupTable.size(); l++)
      40         188 :         delete lookupTable[l];
      41         376 :     lookupTable.clear();
      42         564 : }
      43             : 
      44             : void SAL_CALL
      45         714 : CalendarImpl::loadDefaultCalendar( const Locale& rLocale ) throw(RuntimeException, std::exception)
      46             : {
      47         714 :     Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
      48         714 :     for (sal_Int32 i = 0; i < xC.getLength(); i++) {
      49         714 :         if (xC[i].Default) {
      50         714 :             loadCalendar(xC[i].Name, rLocale);
      51        1428 :             return;
      52             :         }
      53             :     }
      54           0 :     throw ERROR;
      55             : }
      56             : 
      57             : void SAL_CALL
      58         726 : CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) throw (RuntimeException, std::exception)
      59             : {
      60         726 :     Reference < XCalendar4 > xOldCalendar( xCalendar );  // backup
      61             :     sal_Int32 i;
      62             : 
      63         732 :     for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) {
      64         502 :         lookupTableItem *listItem = lookupTable[i];
      65         502 :         if (uniqueID == listItem->uniqueID) {
      66         496 :             xCalendar = listItem->xCalendar;
      67         496 :             break;
      68             :         }
      69             :     }
      70             : 
      71         726 :     if (i >= sal::static_int_cast<sal_Int32>(lookupTable.size())) {
      72         460 :         Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
      73         230 :                   "com.sun.star.i18n.Calendar_" + uniqueID, m_xContext);
      74             : 
      75         230 :         if ( ! xI.is() ) {
      76             :             // check if the calendar is defined in localedata, load gregorian calendar service.
      77           0 :             Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
      78           0 :             for (i = 0; i < xC.getLength(); i++) {
      79           0 :                 if (uniqueID == xC[i].Name) {
      80           0 :                     xI = m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext);
      81           0 :                     break;
      82             :                 }
      83           0 :             }
      84             :         }
      85             : 
      86         230 :         if ( xI.is() )
      87         230 :             xCalendar.set(xI, UNO_QUERY);
      88             :         else
      89           0 :             throw ERROR;
      90             : 
      91         230 :         lookupTable.push_back( new lookupTableItem(uniqueID, xCalendar) );
      92             :     }
      93             : 
      94         726 :     if ( !xCalendar.is() )
      95             :     {
      96           0 :         xCalendar = xOldCalendar;
      97           0 :         throw ERROR;
      98             :     }
      99             : 
     100             :     try
     101             :     {
     102         726 :         xCalendar->loadCalendar(uniqueID, rLocale);
     103             :     }
     104           0 :     catch ( Exception& )
     105             :     {   // restore previous calendar and re-throw
     106           0 :         xCalendar = xOldCalendar;
     107           0 :         throw;
     108         726 :     }
     109         726 : }
     110             : 
     111             : Calendar2 SAL_CALL
     112           0 : CalendarImpl::getLoadedCalendar2() throw(RuntimeException, std::exception)
     113             : {
     114           0 :     if (xCalendar.is())
     115           0 :         return xCalendar->getLoadedCalendar2();
     116             :     else
     117           0 :         throw ERROR ;
     118             : }
     119             : 
     120             : Calendar SAL_CALL
     121           0 : CalendarImpl::getLoadedCalendar() throw(RuntimeException, std::exception)
     122             : {
     123           0 :     if (xCalendar.is())
     124           0 :         return xCalendar->getLoadedCalendar();
     125             :     else
     126           0 :         throw ERROR ;
     127             : }
     128             : 
     129             : Sequence< OUString > SAL_CALL
     130           2 : CalendarImpl::getAllCalendars( const Locale& rLocale ) throw(RuntimeException, std::exception)
     131             : {
     132           2 :     Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
     133           2 :     sal_Int32 nLen = xC.getLength();
     134           2 :     Sequence< OUString > xSeq( nLen );
     135           6 :     for (sal_Int32 i = 0; i < nLen; i++)
     136           4 :         xSeq[i] = xC[i].Name;
     137           2 :     return xSeq;
     138             : }
     139             : 
     140             : void SAL_CALL
     141           6 : CalendarImpl::setDateTime( double fTimeInDays ) throw(RuntimeException, std::exception)
     142             : {
     143           6 :     if (xCalendar.is())
     144           6 :         xCalendar->setDateTime( fTimeInDays );
     145             :     else
     146           0 :         throw ERROR ;
     147           6 : }
     148             : 
     149             : double SAL_CALL
     150           6 : CalendarImpl::getDateTime() throw(RuntimeException, std::exception)
     151             : {
     152           6 :     if (xCalendar.is())
     153          12 :         return xCalendar->getDateTime();
     154             :     else
     155           0 :         throw ERROR ;
     156             : }
     157             : 
     158             : void SAL_CALL
     159        2542 : CalendarImpl::setLocalDateTime( double fTimeInDays ) throw(RuntimeException, std::exception)
     160             : {
     161        2542 :     if (xCalendar.is())
     162        2542 :         xCalendar->setLocalDateTime( fTimeInDays );
     163             :     else
     164           0 :         throw ERROR ;
     165        2542 : }
     166             : 
     167             : double SAL_CALL
     168         656 : CalendarImpl::getLocalDateTime() throw(RuntimeException, std::exception)
     169             : {
     170         656 :     if (xCalendar.is())
     171        1312 :         return xCalendar->getLocalDateTime();
     172             :     else
     173           0 :         throw ERROR ;
     174             : }
     175             : 
     176             : OUString SAL_CALL
     177        3414 : CalendarImpl::getUniqueID() throw(RuntimeException, std::exception)
     178             : {
     179        3414 :     if (xCalendar.is())
     180        6828 :         return xCalendar->getUniqueID();
     181             :     else
     182           0 :         throw ERROR ;
     183             : }
     184             : 
     185             : void SAL_CALL
     186        2623 : CalendarImpl::setValue( sal_Int16 fieldIndex, sal_Int16 value ) throw(RuntimeException, std::exception)
     187             : {
     188        2623 :     if (xCalendar.is())
     189        2623 :         xCalendar->setValue( fieldIndex, value );
     190             :     else
     191           0 :         throw ERROR ;
     192        2623 : }
     193             : 
     194             : sal_Int16 SAL_CALL
     195         146 : CalendarImpl::getValue( sal_Int16 fieldIndex ) throw(RuntimeException, std::exception)
     196             : {
     197         146 :     if (xCalendar.is())
     198         292 :         return xCalendar->getValue( fieldIndex );
     199             :     else
     200           0 :         throw ERROR ;
     201             : }
     202             : 
     203             : void SAL_CALL
     204           0 : CalendarImpl::addValue( sal_Int16 fieldIndex, sal_Int32 amount ) throw(RuntimeException, std::exception)
     205             : {
     206           0 :     if (xCalendar.is())
     207           0 :         xCalendar->addValue( fieldIndex, amount);
     208             :     else
     209           0 :         throw ERROR ;
     210           0 : }
     211             : 
     212             : sal_Int16 SAL_CALL
     213           0 : CalendarImpl::getFirstDayOfWeek() throw(RuntimeException, std::exception)
     214             : {
     215           0 :     if (xCalendar.is())
     216           0 :         return xCalendar->getFirstDayOfWeek();
     217             :     else
     218           0 :         throw ERROR ;
     219             : }
     220             : 
     221             : void SAL_CALL
     222           0 : CalendarImpl::setFirstDayOfWeek( sal_Int16 day )
     223             : throw(RuntimeException, std::exception)
     224             : {
     225           0 :     if (xCalendar.is())
     226           0 :         xCalendar->setFirstDayOfWeek(day);
     227             :     else
     228           0 :         throw ERROR ;
     229           0 : }
     230             : 
     231             : void SAL_CALL
     232           0 : CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days ) throw(RuntimeException, std::exception)
     233             : {
     234           0 :     if (xCalendar.is())
     235           0 :         xCalendar->setMinimumNumberOfDaysForFirstWeek(days);
     236             :     else
     237           0 :         throw ERROR ;
     238           0 : }
     239             : 
     240             : sal_Int16 SAL_CALL
     241           0 : CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException, std::exception)
     242             : {
     243           0 :     if (xCalendar.is())
     244           0 :         return xCalendar->getMinimumNumberOfDaysForFirstWeek();
     245             :     else
     246           0 :         throw ERROR ;
     247             : }
     248             : 
     249             : 
     250             : OUString SAL_CALL
     251         265 : CalendarImpl::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType ) throw(RuntimeException, std::exception)
     252             : {
     253         265 :     if (xCalendar.is())
     254         530 :         return xCalendar->getDisplayName( displayIndex, idx, nameType );
     255             :     else
     256           0 :         throw ERROR ;
     257             : }
     258             : 
     259             : sal_Int16 SAL_CALL
     260        4986 : CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException, std::exception)
     261             : {
     262        4986 :     if (xCalendar.is())
     263        9972 :         return xCalendar->getNumberOfMonthsInYear();
     264             :     else
     265           0 :         throw ERROR ;
     266             : }
     267             : 
     268             : 
     269             : sal_Int16 SAL_CALL
     270        1978 : CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException, std::exception)
     271             : {
     272        1978 :     if (xCalendar.is())
     273        3956 :         return xCalendar->getNumberOfDaysInWeek();
     274             :     else
     275           0 :         throw ERROR ;
     276             : }
     277             : 
     278             : 
     279             : Sequence< CalendarItem > SAL_CALL
     280           0 : CalendarImpl::getDays() throw(RuntimeException, std::exception)
     281             : {
     282           0 :     if (xCalendar.is())
     283           0 :         return xCalendar->getDays();
     284             :     else
     285           0 :         throw ERROR ;
     286             : }
     287             : 
     288             : 
     289             : Sequence< CalendarItem > SAL_CALL
     290           0 : CalendarImpl::getMonths() throw(RuntimeException, std::exception)
     291             : {
     292           0 :     if (xCalendar.is())
     293           0 :         return xCalendar->getMonths();
     294             :     else
     295           0 :         throw ERROR ;
     296             : }
     297             : 
     298             : 
     299             : Sequence< CalendarItem2 > SAL_CALL
     300         561 : CalendarImpl::getDays2() throw(RuntimeException, std::exception)
     301             : {
     302         561 :     if (xCalendar.is())
     303        1122 :         return xCalendar->getDays2();
     304             :     else
     305           0 :         throw ERROR ;
     306             : }
     307             : 
     308             : 
     309             : Sequence< CalendarItem2 > SAL_CALL
     310        1349 : CalendarImpl::getMonths2() throw(RuntimeException, std::exception)
     311             : {
     312        1349 :     if (xCalendar.is())
     313        2698 :         return xCalendar->getMonths2();
     314             :     else
     315           0 :         throw ERROR ;
     316             : }
     317             : 
     318             : 
     319             : Sequence< CalendarItem2 > SAL_CALL
     320         561 : CalendarImpl::getGenitiveMonths2() throw(RuntimeException, std::exception)
     321             : {
     322         561 :     if (xCalendar.is())
     323        1122 :         return xCalendar->getGenitiveMonths2();
     324             :     else
     325           0 :         throw ERROR ;
     326             : }
     327             : 
     328             : 
     329             : Sequence< CalendarItem2 > SAL_CALL
     330         561 : CalendarImpl::getPartitiveMonths2() throw(RuntimeException, std::exception)
     331             : {
     332         561 :     if (xCalendar.is())
     333        1122 :         return xCalendar->getPartitiveMonths2();
     334             :     else
     335           0 :         throw ERROR ;
     336             : }
     337             : 
     338             : 
     339             : sal_Bool SAL_CALL
     340         656 : CalendarImpl::isValid() throw(RuntimeException, std::exception)
     341             : {
     342         656 :     if (xCalendar.is())
     343        1312 :         return xCalendar->isValid();
     344             :     else
     345           0 :         throw ERROR ;
     346             : }
     347             : 
     348             : OUString SAL_CALL
     349        4376 : CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
     350             :     throw (RuntimeException, std::exception)
     351             : {
     352        4376 :     if (xCalendar.is())
     353        8752 :         return xCalendar->getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
     354             :     else
     355           0 :         throw ERROR ;
     356             : }
     357             : 
     358             : OUString SAL_CALL
     359           2 : CalendarImpl::getImplementationName() throw( RuntimeException, std::exception )
     360             : {
     361           2 :     return OUString("com.sun.star.i18n.CalendarImpl");
     362             : }
     363             : 
     364             : sal_Bool SAL_CALL
     365           0 : CalendarImpl::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
     366             : {
     367           0 :     return cppu::supportsService(this, rServiceName);
     368             : }
     369             : 
     370             : Sequence< OUString > SAL_CALL
     371           2 : CalendarImpl::getSupportedServiceNames() throw( RuntimeException, std::exception )
     372             : {
     373           2 :     Sequence< OUString > aRet(2);
     374           2 :     aRet[0] = "com.sun.star.i18n.LocaleCalendar";
     375           2 :     aRet[1] = "com.sun.star.i18n.LocaleCalendar2";
     376           2 :     return aRet;
     377             : }
     378             : 
     379             : }}}}
     380             : 
     381             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11