bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / calendar / calendarImpl.cxx
blob93ff9b16fa0b693c3ced01e0b11acd2577059bfd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <calendarImpl.hxx>
21 #include <localedata.hxx>
22 #include <cppuhelper/supportsservice.hxx>
24 #include <com/sun/star/uno/XComponentContext.hpp>
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::i18n;
28 using namespace ::com::sun::star::lang;
30 namespace i18npool {
32 #define ERROR RuntimeException()
34 CalendarImpl::CalendarImpl(const Reference< XComponentContext > &rxContext) : m_xContext(rxContext)
38 CalendarImpl::~CalendarImpl()
42 void SAL_CALL
43 CalendarImpl::loadDefaultCalendar( const Locale& rLocale )
45 Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
46 for (sal_Int32 i = 0; i < xC.getLength(); i++) {
47 if (xC[i].Default) {
48 loadCalendar(xC[i].Name, rLocale);
49 return;
52 throw ERROR;
55 void SAL_CALL
56 CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale )
58 Reference < XCalendar4 > xOldCalendar( xCalendar ); // backup
59 sal_Int32 i;
61 for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) {
62 lookupTableItem &listItem = lookupTable[i];
63 if (uniqueID == listItem.uniqueID) {
64 xCalendar = listItem.xCalendar;
65 break;
69 if (i >= sal::static_int_cast<sal_Int32>(lookupTable.size())) {
70 Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
71 "com.sun.star.i18n.Calendar_" + uniqueID, m_xContext);
73 if ( ! xI.is() ) {
74 // check if the calendar is defined in localedata, load gregorian calendar service.
75 Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
76 for (i = 0; i < xC.getLength(); i++) {
77 if (uniqueID == xC[i].Name) {
78 xI = m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext);
79 break;
84 if ( !xI.is() )
85 throw ERROR;
86 xCalendar.set(xI, UNO_QUERY);
88 lookupTable.emplace_back( uniqueID, xCalendar );
91 if ( !xCalendar.is() )
93 xCalendar = xOldCalendar;
94 throw ERROR;
97 try
99 xCalendar->loadCalendar(uniqueID, rLocale);
101 catch ( Exception& )
102 { // restore previous calendar and re-throw
103 xCalendar = xOldCalendar;
104 throw;
108 Calendar2 SAL_CALL
109 CalendarImpl::getLoadedCalendar2()
111 if (!xCalendar.is())
112 throw ERROR;
113 return xCalendar->getLoadedCalendar2();
116 Calendar SAL_CALL
117 CalendarImpl::getLoadedCalendar()
119 if (!xCalendar.is())
120 throw ERROR;
121 return xCalendar->getLoadedCalendar();
124 Sequence< OUString > SAL_CALL
125 CalendarImpl::getAllCalendars( const Locale& rLocale )
127 Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
128 sal_Int32 nLen = xC.getLength();
129 Sequence< OUString > xSeq( nLen );
130 for (sal_Int32 i = 0; i < nLen; i++)
131 xSeq[i] = xC[i].Name;
132 return xSeq;
135 void SAL_CALL
136 CalendarImpl::setDateTime( double fTimeInDays )
138 if (!xCalendar.is())
139 throw ERROR;
140 xCalendar->setDateTime( fTimeInDays );
143 double SAL_CALL
144 CalendarImpl::getDateTime()
146 if (!xCalendar.is())
147 throw ERROR;
148 return xCalendar->getDateTime();
151 void SAL_CALL
152 CalendarImpl::setLocalDateTime( double fTimeInDays )
154 if (!xCalendar.is())
155 throw ERROR;
156 xCalendar->setLocalDateTime( fTimeInDays );
159 double SAL_CALL
160 CalendarImpl::getLocalDateTime()
162 if (!xCalendar.is())
163 throw ERROR;
164 return xCalendar->getLocalDateTime();
167 OUString SAL_CALL
168 CalendarImpl::getUniqueID()
170 if (!xCalendar.is())
171 throw ERROR;
172 return xCalendar->getUniqueID();
175 void SAL_CALL
176 CalendarImpl::setValue( sal_Int16 fieldIndex, sal_Int16 value )
178 if (!xCalendar.is())
179 throw ERROR;
180 xCalendar->setValue( fieldIndex, value );
183 sal_Int16 SAL_CALL
184 CalendarImpl::getValue( sal_Int16 fieldIndex )
186 if (!xCalendar.is())
187 throw ERROR;
188 return xCalendar->getValue( fieldIndex );
191 void SAL_CALL
192 CalendarImpl::addValue( sal_Int16 fieldIndex, sal_Int32 amount )
194 if (!xCalendar.is())
195 throw ERROR;
196 xCalendar->addValue( fieldIndex, amount);
199 sal_Int16 SAL_CALL
200 CalendarImpl::getFirstDayOfWeek()
202 if (!xCalendar.is())
203 throw ERROR;
204 return xCalendar->getFirstDayOfWeek();
207 void SAL_CALL
208 CalendarImpl::setFirstDayOfWeek( sal_Int16 day )
210 if (!xCalendar.is())
211 throw ERROR;
212 xCalendar->setFirstDayOfWeek(day);
215 void SAL_CALL
216 CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days )
218 if (!xCalendar.is())
219 throw ERROR;
220 xCalendar->setMinimumNumberOfDaysForFirstWeek(days);
223 sal_Int16 SAL_CALL
224 CalendarImpl::getMinimumNumberOfDaysForFirstWeek()
226 if (!xCalendar.is())
227 throw ERROR;
228 return xCalendar->getMinimumNumberOfDaysForFirstWeek();
232 OUString SAL_CALL
233 CalendarImpl::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType )
235 if (!xCalendar.is())
236 throw ERROR;
237 return xCalendar->getDisplayName( displayIndex, idx, nameType );
240 sal_Int16 SAL_CALL
241 CalendarImpl::getNumberOfMonthsInYear()
243 if (!xCalendar.is())
244 throw ERROR;
245 return xCalendar->getNumberOfMonthsInYear();
249 sal_Int16 SAL_CALL
250 CalendarImpl::getNumberOfDaysInWeek()
252 if (!xCalendar.is())
253 throw ERROR;
254 return xCalendar->getNumberOfDaysInWeek();
258 Sequence< CalendarItem > SAL_CALL
259 CalendarImpl::getDays()
261 if (!xCalendar.is())
262 throw ERROR;
263 return xCalendar->getDays();
267 Sequence< CalendarItem > SAL_CALL
268 CalendarImpl::getMonths()
270 if (!xCalendar.is())
271 throw ERROR;
272 return xCalendar->getMonths();
276 Sequence< CalendarItem2 > SAL_CALL
277 CalendarImpl::getDays2()
279 if (!xCalendar.is())
280 throw ERROR;
281 return xCalendar->getDays2();
285 Sequence< CalendarItem2 > SAL_CALL
286 CalendarImpl::getMonths2()
288 if (!xCalendar.is())
289 throw ERROR;
290 return xCalendar->getMonths2();
294 Sequence< CalendarItem2 > SAL_CALL
295 CalendarImpl::getGenitiveMonths2()
297 if (!xCalendar.is())
298 throw ERROR;
299 return xCalendar->getGenitiveMonths2();
303 Sequence< CalendarItem2 > SAL_CALL
304 CalendarImpl::getPartitiveMonths2()
306 if (!xCalendar.is())
307 throw ERROR;
308 return xCalendar->getPartitiveMonths2();
312 sal_Bool SAL_CALL
313 CalendarImpl::isValid()
315 if (!xCalendar.is())
316 throw ERROR;
317 return xCalendar->isValid();
320 OUString SAL_CALL
321 CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
323 if (!xCalendar.is())
324 throw ERROR;
325 return xCalendar->getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
328 OUString SAL_CALL
329 CalendarImpl::getImplementationName()
331 return OUString("com.sun.star.i18n.CalendarImpl");
334 sal_Bool SAL_CALL
335 CalendarImpl::supportsService(const OUString& rServiceName)
337 return cppu::supportsService(this, rServiceName);
340 Sequence< OUString > SAL_CALL
341 CalendarImpl::getSupportedServiceNames()
343 Sequence< OUString > aRet(2);
344 aRet[0] = "com.sun.star.i18n.LocaleCalendar";
345 aRet[1] = "com.sun.star.i18n.LocaleCalendar2";
346 return aRet;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */