1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: calendarImpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 #include "calendarImpl.hxx"
35 #include "localedata.hxx"
36 #include <comphelper/processfactory.hxx>
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::i18n
;
41 using namespace ::rtl
;
43 #define ERROR RuntimeException()
45 CalendarImpl::CalendarImpl(const Reference
< XMultiServiceFactory
> &rxMSF
) : xMSF(rxMSF
)
49 CalendarImpl::~CalendarImpl()
52 for (size_t l
= 0; l
< lookupTable
.size(); l
++)
53 delete lookupTable
[l
];
59 CalendarImpl::loadDefaultCalendar( const Locale
& rLocale
) throw(RuntimeException
)
61 Sequence
< Calendar
> xC
= LocaleData().getAllCalendars(rLocale
);
62 for (sal_Int32 i
= 0; i
< xC
.getLength(); i
++) {
64 loadCalendar(xC
[i
].Name
, rLocale
);
72 CalendarImpl::loadCalendar(const OUString
& uniqueID
, const Locale
& rLocale
) throw (RuntimeException
)
74 Reference
< XExtendedCalendar
> xOldCalendar( xCalendar
); // backup
77 for (i
= 0; i
< sal::static_int_cast
<sal_Int32
>(lookupTable
.size()); i
++) {
78 lookupTableItem
*listItem
= lookupTable
[i
];
79 if (uniqueID
== listItem
->uniqueID
) {
80 xCalendar
= listItem
->xCalendar
;
85 if (i
>= sal::static_int_cast
<sal_Int32
>(lookupTable
.size())) {
86 Reference
< XInterface
> xI
= xMSF
->createInstance(
87 OUString::createFromAscii("com.sun.star.i18n.Calendar_") + uniqueID
);
90 // check if the calendar is defined in localedata, load gregorian calendar service.
91 Sequence
< Calendar
> xC
= LocaleData().getAllCalendars(rLocale
);
92 for (i
= 0; i
< xC
.getLength(); i
++) {
93 if (uniqueID
== xC
[i
].Name
) {
94 xI
= xMSF
->createInstance(
95 OUString::createFromAscii("com.sun.star.i18n.Calendar_gregorian"));
102 xI
->queryInterface(::getCppuType((const Reference
< XExtendedCalendar
>*)0)) >>= xCalendar
;
106 lookupTable
.push_back( new lookupTableItem(uniqueID
, xCalendar
) );
109 if ( !xCalendar
.is() )
111 xCalendar
= xOldCalendar
;
117 xCalendar
->loadCalendar(uniqueID
, rLocale
);
120 { // restore previous calendar and re-throw
121 xCalendar
= xOldCalendar
;
127 CalendarImpl::getLoadedCalendar() throw(RuntimeException
)
130 return xCalendar
->getLoadedCalendar();
135 Sequence
< OUString
> SAL_CALL
136 CalendarImpl::getAllCalendars( const Locale
& rLocale
) throw(RuntimeException
)
138 Sequence
< Calendar
> xC
= LocaleData().getAllCalendars(rLocale
);
139 sal_Int32 nLen
= xC
.getLength();
140 Sequence
< OUString
> xSeq( nLen
);
141 for (sal_Int32 i
= 0; i
< nLen
; i
++)
142 xSeq
[i
] = xC
[i
].Name
;
147 CalendarImpl::setDateTime( double timeInDays
) throw(RuntimeException
)
150 xCalendar
->setDateTime( timeInDays
);
156 CalendarImpl::getDateTime() throw(RuntimeException
)
159 return xCalendar
->getDateTime();
165 CalendarImpl::getUniqueID() throw(RuntimeException
)
168 return xCalendar
->getUniqueID();
174 CalendarImpl::setValue( sal_Int16 fieldIndex
, sal_Int16 value
) throw(RuntimeException
)
177 xCalendar
->setValue( fieldIndex
, value
);
183 CalendarImpl::getValue( sal_Int16 fieldIndex
) throw(RuntimeException
)
186 return xCalendar
->getValue( fieldIndex
);
192 CalendarImpl::addValue( sal_Int16 fieldIndex
, sal_Int32 amount
) throw(RuntimeException
)
195 xCalendar
->addValue( fieldIndex
, amount
);
201 CalendarImpl::getFirstDayOfWeek() throw(RuntimeException
)
204 return xCalendar
->getFirstDayOfWeek();
210 CalendarImpl::setFirstDayOfWeek( sal_Int16 day
)
211 throw(RuntimeException
)
214 xCalendar
->setFirstDayOfWeek(day
);
220 CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days
) throw(RuntimeException
)
223 xCalendar
->setMinimumNumberOfDaysForFirstWeek(days
);
229 CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException
)
232 return xCalendar
->getMinimumNumberOfDaysForFirstWeek();
239 CalendarImpl::getDisplayName( sal_Int16 displayIndex
, sal_Int16 idx
, sal_Int16 nameType
) throw(RuntimeException
)
242 return xCalendar
->getDisplayName( displayIndex
, idx
, nameType
);
248 CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException
)
251 return xCalendar
->getNumberOfMonthsInYear();
258 CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException
)
261 return xCalendar
->getNumberOfDaysInWeek();
267 Sequence
< CalendarItem
> SAL_CALL
268 CalendarImpl::getMonths() throw(RuntimeException
)
271 return xCalendar
->getMonths();
277 Sequence
< CalendarItem
> SAL_CALL
278 CalendarImpl::getDays() throw(RuntimeException
)
281 return xCalendar
->getDays();
288 CalendarImpl::isValid() throw(RuntimeException
)
291 return xCalendar
->isValid();
297 CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
)
298 throw (RuntimeException
)
301 return xCalendar
->getDisplayString(nCalendarDisplayCode
, nNativeNumberMode
);
307 CalendarImpl::getImplementationName(void) throw( RuntimeException
)
309 return OUString::createFromAscii("com.sun.star.i18n.CalendarImpl");
312 const sal_Char cCalendar
[] = "com.sun.star.i18n.LocaleCalendar";
315 CalendarImpl::supportsService(const OUString
& rServiceName
) throw( RuntimeException
)
317 return !rServiceName
.compareToAscii(cCalendar
);
320 Sequence
< OUString
> SAL_CALL
321 CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException
)
323 Sequence
< OUString
> aRet(1);
324 aRet
[0] = OUString::createFromAscii(cCalendar
);