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