LCOV - code coverage report
Current view: top level - i18npool/source/calendar - calendarImpl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 82 156 52.6 %
Date: 2014-11-03 Functions: 20 32 62.5 %
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         402 : CalendarImpl::CalendarImpl(const Reference< XComponentContext > &rxContext) : m_xContext(rxContext)
      33             : {
      34         402 : }
      35             : 
      36        1964 : CalendarImpl::~CalendarImpl()
      37             : {
      38             :     // Clear lookuptable
      39        1180 :     for (size_t l = 0; l < lookupTable.size(); l++)
      40         394 :         delete lookupTable[l];
      41         786 :     lookupTable.clear();
      42        1178 : }
      43             : 
      44             : void SAL_CALL
      45        1358 : CalendarImpl::loadDefaultCalendar( const Locale& rLocale ) throw(RuntimeException, std::exception)
      46             : {
      47        1358 :     Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
      48        1358 :     for (sal_Int32 i = 0; i < xC.getLength(); i++) {
      49        1358 :         if (xC[i].Default) {
      50        1358 :             loadCalendar(xC[i].Name, rLocale);
      51        2716 :             return;
      52             :         }
      53             :     }
      54           0 :     throw ERROR;
      55             : }
      56             : 
      57             : void SAL_CALL
      58        1382 : CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) throw (RuntimeException, std::exception)
      59             : {
      60        1382 :     Reference < XCalendar3 > xOldCalendar( xCalendar );  // backup
      61             :     sal_Int32 i;
      62             : 
      63        1394 :     for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) {
      64         990 :         lookupTableItem *listItem = lookupTable[i];
      65         990 :         if (uniqueID == listItem->uniqueID) {
      66         978 :             xCalendar = listItem->xCalendar;
      67         978 :             break;
      68             :         }
      69             :     }
      70             : 
      71        1382 :     if (i >= sal::static_int_cast<sal_Int32>(lookupTable.size())) {
      72         808 :         Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
      73         404 :                   OUString("com.sun.star.i18n.Calendar_") + uniqueID, m_xContext);
      74             : 
      75         404 :         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         404 :         if ( xI.is() )
      87         404 :             xCalendar.set(xI, UNO_QUERY);
      88             :         else
      89           0 :             throw ERROR;
      90             : 
      91         404 :         lookupTable.push_back( new lookupTableItem(uniqueID, xCalendar) );
      92             :     }
      93             : 
      94        1382 :     if ( !xCalendar.is() )
      95             :     {
      96           0 :         xCalendar = xOldCalendar;
      97           0 :         throw ERROR;
      98             :     }
      99             : 
     100             :     try
     101             :     {
     102        1382 :         xCalendar->loadCalendar(uniqueID, rLocale);
     103             :     }
     104           0 :     catch ( Exception& )
     105             :     {   // restore previous calendar and re-throw
     106           0 :         xCalendar = xOldCalendar;
     107           0 :         throw;
     108        1382 :     }
     109        1382 : }
     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           4 : CalendarImpl::getAllCalendars( const Locale& rLocale ) throw(RuntimeException, std::exception)
     131             : {
     132           4 :     Sequence< Calendar2 > xC = LocaleDataImpl().getAllCalendars2(rLocale);
     133           4 :     sal_Int32 nLen = xC.getLength();
     134           4 :     Sequence< OUString > xSeq( nLen );
     135          12 :     for (sal_Int32 i = 0; i < nLen; i++)
     136           8 :         xSeq[i] = xC[i].Name;
     137           4 :     return xSeq;
     138             : }
     139             : 
     140             : void SAL_CALL
     141        5688 : CalendarImpl::setDateTime( double fTimeInDays ) throw(RuntimeException, std::exception)
     142             : {
     143        5688 :     if (xCalendar.is())
     144        5688 :         xCalendar->setDateTime( fTimeInDays );
     145             :     else
     146           0 :         throw ERROR ;
     147        5688 : }
     148             : 
     149             : double SAL_CALL
     150         260 : CalendarImpl::getDateTime() throw(RuntimeException, std::exception)
     151             : {
     152         260 :     if (xCalendar.is())
     153         520 :         return xCalendar->getDateTime();
     154             :     else
     155           0 :         throw ERROR ;
     156             : }
     157             : 
     158             : OUString SAL_CALL
     159        4508 : CalendarImpl::getUniqueID() throw(RuntimeException, std::exception)
     160             : {
     161        4508 :     if (xCalendar.is())
     162        9016 :         return xCalendar->getUniqueID();
     163             :     else
     164           0 :         throw ERROR ;
     165             : }
     166             : 
     167             : void SAL_CALL
     168         992 : CalendarImpl::setValue( sal_Int16 fieldIndex, sal_Int16 value ) throw(RuntimeException, std::exception)
     169             : {
     170         992 :     if (xCalendar.is())
     171         992 :         xCalendar->setValue( fieldIndex, value );
     172             :     else
     173           0 :         throw ERROR ;
     174         992 : }
     175             : 
     176             : sal_Int16 SAL_CALL
     177       23988 : CalendarImpl::getValue( sal_Int16 fieldIndex ) throw(RuntimeException, std::exception)
     178             : {
     179       23988 :     if (xCalendar.is())
     180       47976 :         return xCalendar->getValue( fieldIndex );
     181             :     else
     182           0 :         throw ERROR ;
     183             : }
     184             : 
     185             : void SAL_CALL
     186           0 : CalendarImpl::addValue( sal_Int16 fieldIndex, sal_Int32 amount ) throw(RuntimeException, std::exception)
     187             : {
     188           0 :     if (xCalendar.is())
     189           0 :         xCalendar->addValue( fieldIndex, amount);
     190             :     else
     191           0 :         throw ERROR ;
     192           0 : }
     193             : 
     194             : sal_Int16 SAL_CALL
     195           0 : CalendarImpl::getFirstDayOfWeek() throw(RuntimeException, std::exception)
     196             : {
     197           0 :     if (xCalendar.is())
     198           0 :         return xCalendar->getFirstDayOfWeek();
     199             :     else
     200           0 :         throw ERROR ;
     201             : }
     202             : 
     203             : void SAL_CALL
     204           0 : CalendarImpl::setFirstDayOfWeek( sal_Int16 day )
     205             : throw(RuntimeException, std::exception)
     206             : {
     207           0 :     if (xCalendar.is())
     208           0 :         xCalendar->setFirstDayOfWeek(day);
     209             :     else
     210           0 :         throw ERROR ;
     211           0 : }
     212             : 
     213             : void SAL_CALL
     214           0 : CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days ) throw(RuntimeException, std::exception)
     215             : {
     216           0 :     if (xCalendar.is())
     217           0 :         xCalendar->setMinimumNumberOfDaysForFirstWeek(days);
     218             :     else
     219           0 :         throw ERROR ;
     220           0 : }
     221             : 
     222             : sal_Int16 SAL_CALL
     223           0 : CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException, std::exception)
     224             : {
     225           0 :     if (xCalendar.is())
     226           0 :         return xCalendar->getMinimumNumberOfDaysForFirstWeek();
     227             :     else
     228           0 :         throw ERROR ;
     229             : }
     230             : 
     231             : 
     232             : OUString SAL_CALL
     233         508 : CalendarImpl::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType ) throw(RuntimeException, std::exception)
     234             : {
     235         508 :     if (xCalendar.is())
     236        1016 :         return xCalendar->getDisplayName( displayIndex, idx, nameType );
     237             :     else
     238           0 :         throw ERROR ;
     239             : }
     240             : 
     241             : sal_Int16 SAL_CALL
     242        7398 : CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException, std::exception)
     243             : {
     244        7398 :     if (xCalendar.is())
     245       14796 :         return xCalendar->getNumberOfMonthsInYear();
     246             :     else
     247           0 :         throw ERROR ;
     248             : }
     249             : 
     250             : 
     251             : sal_Int16 SAL_CALL
     252        3864 : CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException, std::exception)
     253             : {
     254        3864 :     if (xCalendar.is())
     255        7728 :         return xCalendar->getNumberOfDaysInWeek();
     256             :     else
     257           0 :         throw ERROR ;
     258             : }
     259             : 
     260             : 
     261             : Sequence< CalendarItem > SAL_CALL
     262           0 : CalendarImpl::getDays() throw(RuntimeException, std::exception)
     263             : {
     264           0 :     if (xCalendar.is())
     265           0 :         return xCalendar->getDays();
     266             :     else
     267           0 :         throw ERROR ;
     268             : }
     269             : 
     270             : 
     271             : Sequence< CalendarItem > SAL_CALL
     272           0 : CalendarImpl::getMonths() throw(RuntimeException, std::exception)
     273             : {
     274           0 :     if (xCalendar.is())
     275           0 :         return xCalendar->getMonths();
     276             :     else
     277           0 :         throw ERROR ;
     278             : }
     279             : 
     280             : 
     281             : Sequence< CalendarItem2 > SAL_CALL
     282        1106 : CalendarImpl::getDays2() throw(RuntimeException, std::exception)
     283             : {
     284        1106 :     if (xCalendar.is())
     285        2212 :         return xCalendar->getDays2();
     286             :     else
     287           0 :         throw ERROR ;
     288             : }
     289             : 
     290             : 
     291             : Sequence< CalendarItem2 > SAL_CALL
     292        2842 : CalendarImpl::getMonths2() throw(RuntimeException, std::exception)
     293             : {
     294        2842 :     if (xCalendar.is())
     295        5684 :         return xCalendar->getMonths2();
     296             :     else
     297           0 :         throw ERROR ;
     298             : }
     299             : 
     300             : 
     301             : Sequence< CalendarItem2 > SAL_CALL
     302        1106 : CalendarImpl::getGenitiveMonths2() throw(RuntimeException, std::exception)
     303             : {
     304        1106 :     if (xCalendar.is())
     305        2212 :         return xCalendar->getGenitiveMonths2();
     306             :     else
     307           0 :         throw ERROR ;
     308             : }
     309             : 
     310             : 
     311             : Sequence< CalendarItem2 > SAL_CALL
     312        1106 : CalendarImpl::getPartitiveMonths2() throw(RuntimeException, std::exception)
     313             : {
     314        1106 :     if (xCalendar.is())
     315        2212 :         return xCalendar->getPartitiveMonths2();
     316             :     else
     317           0 :         throw ERROR ;
     318             : }
     319             : 
     320             : 
     321             : sal_Bool SAL_CALL
     322         248 : CalendarImpl::isValid() throw(RuntimeException, std::exception)
     323             : {
     324         248 :     if (xCalendar.is())
     325         496 :         return xCalendar->isValid();
     326             :     else
     327           0 :         throw ERROR ;
     328             : }
     329             : 
     330             : OUString SAL_CALL
     331        5250 : CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
     332             :     throw (RuntimeException, std::exception)
     333             : {
     334        5250 :     if (xCalendar.is())
     335       10500 :         return xCalendar->getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
     336             :     else
     337           0 :         throw ERROR ;
     338             : }
     339             : 
     340             : OUString SAL_CALL
     341           0 : CalendarImpl::getImplementationName(void) throw( RuntimeException, std::exception )
     342             : {
     343           0 :     return OUString("com.sun.star.i18n.CalendarImpl");
     344             : }
     345             : 
     346             : sal_Bool SAL_CALL
     347           0 : CalendarImpl::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
     348             : {
     349           0 :     return cppu::supportsService(this, rServiceName);
     350             : }
     351             : 
     352             : Sequence< OUString > SAL_CALL
     353           0 : CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException, std::exception )
     354             : {
     355           0 :     Sequence< OUString > aRet(1);
     356           0 :     aRet[0] = "com.sun.star.i18n.LocaleCalendar";
     357           0 :     return aRet;
     358             : }
     359             : 
     360             : }}}}
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10