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 "sal/config.h"
21 :
22 : #include <cstddef>
23 : #include <cstdlib>
24 : #include <map>
25 : #include <vector>
26 :
27 : #include "boost/noncopyable.hpp"
28 : #include "com/sun/star/container/NoSuchElementException.hpp"
29 : #include "com/sun/star/registry/InvalidRegistryException.hpp"
30 : #include "com/sun/star/registry/XRegistryKey.hpp"
31 : #include "com/sun/star/uno/Reference.hxx"
32 : #include "com/sun/star/uno/XInterface.hpp"
33 : #include "cppuhelper/implbase1.hxx"
34 : #include "osl/diagnose.h"
35 : #include "rtl/malformeduriexception.hxx"
36 : #include "rtl/ref.hxx"
37 : #include "rtl/string.h"
38 : #include "rtl/uri.hxx"
39 : #include "rtl/ustrbuf.hxx"
40 : #include "rtl/ustring.h"
41 : #include "rtl/ustring.hxx"
42 : #include "salhelper/simplereferenceobject.hxx"
43 : #include "xmlreader/span.hxx"
44 : #include "xmlreader/xmlreader.hxx"
45 :
46 : #include "textualservices.hxx"
47 :
48 : namespace stoc { namespace simpleregistry {
49 :
50 : namespace {
51 :
52 60 : struct Implementation {
53 : rtl::OUString uri;
54 : rtl::OUString loader;
55 : rtl::OUString prefix;
56 : std::vector< rtl::OUString > services;
57 : std::vector< rtl::OUString > singletons;
58 : };
59 :
60 : typedef std::map< rtl::OUString, Implementation > Implementations;
61 :
62 : typedef std::map< rtl::OUString, std::vector< rtl::OUString > >
63 : ImplementationMap;
64 :
65 : }
66 :
67 2 : class Data: public salhelper::SimpleReferenceObject, private boost::noncopyable
68 : {
69 : public:
70 : Implementations implementations;
71 : ImplementationMap services;
72 : ImplementationMap singletons;
73 : };
74 :
75 : namespace {
76 :
77 2 : class Parser: private boost::noncopyable {
78 : public:
79 : Parser(rtl::OUString const & uri, rtl::Reference< Data > const & data);
80 :
81 : private:
82 : void handleComponent();
83 :
84 : void handleImplementation();
85 :
86 : void handleService();
87 :
88 : void handleSingleton();
89 :
90 : rtl::OUString getNameAttribute();
91 :
92 : xmlreader::XmlReader reader_;
93 : rtl::Reference< Data > data_;
94 : rtl::OUString attrUri_;
95 : rtl::OUString attrLoader_;
96 : rtl::OUString attrPrefix_;
97 : rtl::OUString attrImplementation_;
98 : };
99 :
100 2 : Parser::Parser(rtl::OUString const & uri, rtl::Reference< Data > const & data):
101 2 : reader_(uri), data_(data)
102 : {
103 : OSL_ASSERT(data.is());
104 : int ucNsId = reader_.registerNamespaceIri(
105 : xmlreader::Span(
106 : RTL_CONSTASCII_STRINGPARAM(
107 2 : "http://openoffice.org/2010/uno-components")));
108 : enum State {
109 : STATE_BEGIN, STATE_END, STATE_COMPONENTS, STATE_COMPONENT_INITIAL,
110 : STATE_COMPONENT, STATE_IMPLEMENTATION, STATE_SERVICE, STATE_SINGLETON };
111 70 : for (State state = STATE_BEGIN;;) {
112 70 : xmlreader::Span name;
113 : int nsId;
114 : xmlreader::XmlReader::Result res = reader_.nextItem(
115 70 : xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
116 70 : switch (state) {
117 : case STATE_BEGIN:
118 4 : if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
119 2 : name.equals(RTL_CONSTASCII_STRINGPARAM("components")))
120 : {
121 2 : state = STATE_COMPONENTS;
122 2 : break;
123 : }
124 : throw css::registry::InvalidRegistryException(
125 : (reader_.getUrl() +
126 : rtl::OUString(
127 : RTL_CONSTASCII_USTRINGPARAM(
128 0 : ": unexpected item in outer level"))),
129 0 : css::uno::Reference< css::uno::XInterface >());
130 : case STATE_END:
131 2 : if (res == xmlreader::XmlReader::RESULT_DONE) {
132 2 : return;
133 : }
134 : throw css::registry::InvalidRegistryException(
135 : (reader_.getUrl() +
136 : rtl::OUString(
137 : RTL_CONSTASCII_USTRINGPARAM(
138 0 : ": unexpected item in outer level"))),
139 0 : css::uno::Reference< css::uno::XInterface >());
140 : case STATE_COMPONENTS:
141 10 : if (res == xmlreader::XmlReader::RESULT_END) {
142 2 : state = STATE_END;
143 2 : break;
144 : }
145 16 : if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
146 8 : name.equals(RTL_CONSTASCII_STRINGPARAM("component")))
147 : {
148 8 : handleComponent();
149 8 : state = STATE_COMPONENT_INITIAL;
150 8 : break;
151 : }
152 : throw css::registry::InvalidRegistryException(
153 : (reader_.getUrl() +
154 : rtl::OUString(
155 : RTL_CONSTASCII_USTRINGPARAM(
156 0 : ": unexpected item in <components>"))),
157 0 : css::uno::Reference< css::uno::XInterface >());
158 : case STATE_COMPONENT:
159 12 : if (res == xmlreader::XmlReader::RESULT_END) {
160 8 : state = STATE_COMPONENTS;
161 8 : break;
162 : }
163 : // fall through
164 : case STATE_COMPONENT_INITIAL:
165 24 : if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
166 12 : name.equals(RTL_CONSTASCII_STRINGPARAM("implementation")))
167 : {
168 12 : handleImplementation();
169 12 : state = STATE_IMPLEMENTATION;
170 12 : break;
171 : }
172 : throw css::registry::InvalidRegistryException(
173 : (reader_.getUrl() +
174 : rtl::OUString(
175 : RTL_CONSTASCII_USTRINGPARAM(
176 0 : ": unexpected item in <component>"))),
177 0 : css::uno::Reference< css::uno::XInterface >());
178 : case STATE_IMPLEMENTATION:
179 24 : if (res == xmlreader::XmlReader::RESULT_END) {
180 12 : state = STATE_COMPONENT;
181 12 : break;
182 : }
183 24 : if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
184 12 : name.equals(RTL_CONSTASCII_STRINGPARAM("service")))
185 : {
186 12 : handleService();
187 12 : state = STATE_SERVICE;
188 12 : break;
189 : }
190 0 : if (res == xmlreader::XmlReader::RESULT_BEGIN && nsId == ucNsId &&
191 0 : name.equals(RTL_CONSTASCII_STRINGPARAM("singleton")))
192 : {
193 0 : handleSingleton();
194 0 : state = STATE_SINGLETON;
195 0 : break;
196 : }
197 : throw css::registry::InvalidRegistryException(
198 : (reader_.getUrl() +
199 : rtl::OUString(
200 : RTL_CONSTASCII_USTRINGPARAM(
201 0 : ": unexpected item in <implementation>"))),
202 0 : css::uno::Reference< css::uno::XInterface >());
203 : case STATE_SERVICE:
204 12 : if (res == xmlreader::XmlReader::RESULT_END) {
205 12 : state = STATE_IMPLEMENTATION;
206 12 : break;
207 : }
208 : throw css::registry::InvalidRegistryException(
209 : (reader_.getUrl() +
210 : rtl::OUString(
211 : RTL_CONSTASCII_USTRINGPARAM(
212 0 : ": unexpected item in <service>"))),
213 0 : css::uno::Reference< css::uno::XInterface >());
214 : case STATE_SINGLETON:
215 0 : if (res == xmlreader::XmlReader::RESULT_END) {
216 0 : state = STATE_IMPLEMENTATION;
217 0 : break;
218 : }
219 : throw css::registry::InvalidRegistryException(
220 : (reader_.getUrl() +
221 : rtl::OUString(
222 : RTL_CONSTASCII_USTRINGPARAM(
223 0 : ": unexpected item in <service>"))),
224 0 : css::uno::Reference< css::uno::XInterface >());
225 : }
226 : }
227 : }
228 :
229 8 : void Parser::handleComponent() {
230 8 : attrUri_ = rtl::OUString();
231 8 : attrLoader_ = rtl::OUString();
232 8 : attrPrefix_ = rtl::OUString();
233 8 : xmlreader::Span name;
234 : int nsId;
235 8 : while (reader_.nextAttribute(&nsId, &name)) {
236 32 : if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
237 16 : name.equals(RTL_CONSTASCII_STRINGPARAM("uri")))
238 : {
239 8 : if (!attrUri_.isEmpty()) {
240 : throw css::registry::InvalidRegistryException(
241 : (reader_.getUrl() +
242 : rtl::OUString(
243 : RTL_CONSTASCII_USTRINGPARAM(
244 0 : ": <component> has multiple \"uri\" attributes"))),
245 0 : css::uno::Reference< css::uno::XInterface >());
246 : }
247 8 : attrUri_ = reader_.getAttributeValue(false).convertFromUtf8();
248 8 : if (attrUri_.isEmpty()) {
249 : throw css::registry::InvalidRegistryException(
250 : (reader_.getUrl() +
251 : rtl::OUString(
252 : RTL_CONSTASCII_USTRINGPARAM(
253 0 : ": <component> has empty \"uri\" attribute"))),
254 0 : css::uno::Reference< css::uno::XInterface >());
255 : }
256 16 : } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
257 8 : name.equals(RTL_CONSTASCII_STRINGPARAM("loader")))
258 : {
259 8 : if (!attrLoader_.isEmpty()) {
260 : throw css::registry::InvalidRegistryException(
261 : (reader_.getUrl() +
262 : rtl::OUString(
263 : RTL_CONSTASCII_USTRINGPARAM(
264 : ": <component> has multiple \"loader\""
265 0 : " attributes"))),
266 0 : css::uno::Reference< css::uno::XInterface >());
267 : }
268 8 : attrLoader_ = reader_.getAttributeValue(false).convertFromUtf8();
269 8 : if (attrLoader_.isEmpty()) {
270 : throw css::registry::InvalidRegistryException(
271 : (reader_.getUrl() +
272 : rtl::OUString(
273 : RTL_CONSTASCII_USTRINGPARAM(
274 0 : ": <component> has empty \"loader\" attribute"))),
275 0 : css::uno::Reference< css::uno::XInterface >());
276 : }
277 0 : } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
278 0 : name.equals(RTL_CONSTASCII_STRINGPARAM("prefix")))
279 : {
280 0 : if (!attrPrefix_.isEmpty()) {
281 : throw css::registry::InvalidRegistryException(
282 : (reader_.getUrl() +
283 : rtl::OUString(
284 : RTL_CONSTASCII_USTRINGPARAM(
285 : ": <component> has multiple \"prefix\""
286 0 : " attributes"))),
287 0 : css::uno::Reference< css::uno::XInterface >());
288 : }
289 0 : attrPrefix_ = reader_.getAttributeValue(false).convertFromUtf8();
290 0 : if (attrPrefix_.isEmpty()) {
291 : throw css::registry::InvalidRegistryException(
292 : (reader_.getUrl() +
293 : rtl::OUString(
294 : RTL_CONSTASCII_USTRINGPARAM(
295 0 : ": <component> has empty \"prefix\" attribute"))),
296 0 : css::uno::Reference< css::uno::XInterface >());
297 : }
298 : } else {
299 : OSL_FAIL ("unexpected component attribute, expected 'uri' or 'loader' or 'prefix'");
300 : }
301 : }
302 8 : if (attrUri_.isEmpty()) {
303 : throw css::registry::InvalidRegistryException(
304 : (reader_.getUrl() +
305 : rtl::OUString(
306 : RTL_CONSTASCII_USTRINGPARAM(
307 0 : ": <component> is missing \"uri\" attribute"))),
308 0 : css::uno::Reference< css::uno::XInterface >());
309 : }
310 8 : if (attrLoader_.isEmpty()) {
311 : throw css::registry::InvalidRegistryException(
312 : (reader_.getUrl() +
313 : rtl::OUString(
314 : RTL_CONSTASCII_USTRINGPARAM(
315 0 : ": <component> is missing \"loader\" attribute"))),
316 0 : css::uno::Reference< css::uno::XInterface >());
317 : }
318 : #ifndef DISABLE_DYNLOADING
319 : try {
320 8 : attrUri_ = rtl::Uri::convertRelToAbs(reader_.getUrl(), attrUri_);
321 0 : } catch (const rtl::MalformedUriException & e) {
322 : throw css::registry::InvalidRegistryException(
323 : (reader_.getUrl() +
324 : rtl::OUString(
325 0 : RTL_CONSTASCII_USTRINGPARAM(": bad \"uri\" attribute: ")) +
326 0 : e.getMessage()),
327 0 : css::uno::Reference< css::uno::XInterface >());
328 : }
329 : #endif
330 8 : }
331 :
332 12 : void Parser::handleImplementation() {
333 12 : attrImplementation_ = getNameAttribute();
334 36 : if (data_->implementations.find(attrImplementation_) !=
335 36 : data_->implementations.end())
336 : {
337 : throw css::registry::InvalidRegistryException(
338 : (reader_.getUrl() +
339 : rtl::OUString(
340 : RTL_CONSTASCII_USTRINGPARAM(
341 0 : ": duplicate <implementation name=\"")) +
342 0 : attrImplementation_ +
343 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\">"))),
344 0 : css::uno::Reference< css::uno::XInterface >());
345 : }
346 12 : data_->implementations[attrImplementation_].uri = attrUri_;
347 12 : data_->implementations[attrImplementation_].loader = attrLoader_;
348 12 : data_->implementations[attrImplementation_].prefix = attrPrefix_;
349 12 : }
350 :
351 12 : void Parser::handleService() {
352 12 : rtl::OUString name = getNameAttribute();
353 12 : data_->implementations[attrImplementation_].services.push_back(name);
354 12 : data_->services[name].push_back(attrImplementation_);
355 12 : }
356 :
357 0 : void Parser::handleSingleton() {
358 0 : rtl::OUString name = getNameAttribute();
359 0 : data_->implementations[attrImplementation_].singletons.push_back(name);
360 0 : data_->singletons[name].push_back(attrImplementation_);
361 0 : }
362 :
363 24 : rtl::OUString Parser::getNameAttribute() {
364 24 : rtl::OUString attrName;
365 24 : xmlreader::Span name;
366 : int nsId;
367 24 : while (reader_.nextAttribute(&nsId, &name)) {
368 48 : if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
369 24 : name.equals(RTL_CONSTASCII_STRINGPARAM("name")))
370 : {
371 24 : if (!attrName.isEmpty()) {
372 : throw css::registry::InvalidRegistryException(
373 : (reader_.getUrl() +
374 : rtl::OUString(
375 : RTL_CONSTASCII_USTRINGPARAM(
376 0 : ": element has multiple \"name\" attributes"))),
377 0 : css::uno::Reference< css::uno::XInterface >());
378 : }
379 24 : attrName = reader_.getAttributeValue(false).convertFromUtf8();
380 24 : if (attrName.isEmpty()) {
381 : throw css::registry::InvalidRegistryException(
382 : (reader_.getUrl() +
383 : rtl::OUString(
384 : RTL_CONSTASCII_USTRINGPARAM(
385 0 : ": element has empty \"name\" attribute"))),
386 0 : css::uno::Reference< css::uno::XInterface >());
387 : }
388 : } else {
389 : throw css::registry::InvalidRegistryException(
390 : (reader_.getUrl() +
391 : rtl::OUString(
392 : RTL_CONSTASCII_USTRINGPARAM(
393 0 : ": expected element attribute \"name\""))),
394 0 : css::uno::Reference< css::uno::XInterface >());
395 : }
396 : }
397 24 : if (attrName.isEmpty()) {
398 : throw css::registry::InvalidRegistryException(
399 : (reader_.getUrl() +
400 : rtl::OUString(
401 : RTL_CONSTASCII_USTRINGPARAM(
402 0 : ": element is missing \"name\" attribute"))),
403 0 : css::uno::Reference< css::uno::XInterface >());
404 : }
405 24 : return attrName;
406 : }
407 :
408 304 : rtl::OUString pathToString(std::vector< rtl::OUString > const & path) {
409 304 : rtl::OUStringBuffer buf;
410 4776 : for (std::vector< rtl::OUString >::const_iterator i(path.begin());
411 3184 : i != path.end(); ++i)
412 : {
413 1288 : buf.append(sal_Unicode('/'));
414 1288 : buf.append(*i);
415 : }
416 304 : if (buf.getLength() == 0) {
417 0 : buf.append(sal_Unicode('/'));
418 : }
419 304 : return buf.makeStringAndClear();
420 : }
421 :
422 1204 : class Key: public cppu::WeakImplHelper1< css::registry::XRegistryKey > {
423 : public:
424 602 : Key(
425 : rtl::Reference< Data > const & data,
426 : std::vector< rtl::OUString > const & path):
427 602 : data_(data), path_(path) { OSL_ASSERT(data.is());
428 602 : }
429 :
430 : private:
431 : /*
432 : /
433 : IMPLEMENTATIONS
434 : <implementation>
435 : UNO
436 : LOCATION utf-8
437 : ACTIVATOR utf-8
438 : PREFIX utf-8
439 : SERVICES
440 : <service>
441 : ...
442 : SINGLETONS
443 : <singleton> utf-16
444 : ...
445 : ...
446 : SERVICES
447 : <service> utf-8-list
448 : ...
449 : SINGLETONS
450 : <singleton> utf-16
451 : REGISTERED_BY utf-8-list
452 : ...
453 : */
454 : enum State {
455 : STATE_ROOT, STATE_IMPLEMENTATIONS, STATE_IMPLEMENTATION, STATE_UNO,
456 : STATE_LOCATION, STATE_ACTIVATOR, STATE_PREFIX, STATE_IMPLEMENTATION_SERVICES,
457 : STATE_IMPLEMENTATION_SERVICE, STATE_IMPLEMENTATION_SINGLETONS,
458 : STATE_IMPLEMENTATION_SINGLETON, STATE_SERVICES, STATE_SERVICE,
459 : STATE_SINGLETONS, STATE_SINGLETON, STATE_REGISTEREDBY };
460 :
461 : virtual rtl::OUString SAL_CALL getKeyName()
462 : throw (css::uno::RuntimeException);
463 :
464 : virtual sal_Bool SAL_CALL isReadOnly() throw (
465 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
466 :
467 : virtual sal_Bool SAL_CALL isValid() throw(css::uno::RuntimeException);
468 :
469 : virtual css::registry::RegistryKeyType SAL_CALL getKeyType(
470 : rtl::OUString const & rKeyName)
471 : throw (
472 : css::registry::InvalidRegistryException,
473 : css::uno::RuntimeException);
474 :
475 : virtual css::registry::RegistryValueType SAL_CALL getValueType() throw(
476 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
477 :
478 : virtual sal_Int32 SAL_CALL getLongValue() throw (
479 : css::registry::InvalidRegistryException,
480 : css::registry::InvalidValueException, css::uno::RuntimeException);
481 :
482 : virtual void SAL_CALL setLongValue(sal_Int32 value) throw (
483 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
484 :
485 : virtual css::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue() throw(
486 : css::registry::InvalidRegistryException,
487 : css::registry::InvalidValueException, css::uno::RuntimeException);
488 :
489 : virtual void SAL_CALL setLongListValue(
490 : com::sun::star::uno::Sequence< sal_Int32 > const & seqValue)
491 : throw (
492 : css::registry::InvalidRegistryException,
493 : css::uno::RuntimeException);
494 :
495 : virtual rtl::OUString SAL_CALL getAsciiValue() throw (
496 : css::registry::InvalidRegistryException,
497 : css::registry::InvalidValueException, css::uno::RuntimeException);
498 :
499 : virtual void SAL_CALL setAsciiValue(rtl::OUString const & value) throw (
500 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
501 :
502 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue()
503 : throw (
504 : css::registry::InvalidRegistryException,
505 : css::registry::InvalidValueException, css::uno::RuntimeException);
506 :
507 : virtual void SAL_CALL setAsciiListValue(
508 : css::uno::Sequence< rtl::OUString > const & seqValue)
509 : throw (
510 : css::registry::InvalidRegistryException,
511 : css::uno::RuntimeException);
512 :
513 : virtual rtl::OUString SAL_CALL getStringValue() throw(
514 : css::registry::InvalidRegistryException,
515 : css::registry::InvalidValueException, css::uno::RuntimeException);
516 :
517 : virtual void SAL_CALL setStringValue(rtl::OUString const & value) throw (
518 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
519 :
520 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL getStringListValue()
521 : throw (
522 : css::registry::InvalidRegistryException,
523 : css::registry::InvalidValueException, css::uno::RuntimeException);
524 :
525 : virtual void SAL_CALL setStringListValue(
526 : css::uno::Sequence< rtl::OUString > const & seqValue)
527 : throw (
528 : css::registry::InvalidRegistryException,
529 : css::uno::RuntimeException);
530 :
531 : virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue() throw (
532 : css::registry::InvalidRegistryException,
533 : css::registry::InvalidValueException, css::uno::RuntimeException);
534 :
535 : virtual void SAL_CALL setBinaryValue(
536 : css::uno::Sequence< sal_Int8 > const & value)
537 : throw (
538 : css::registry::InvalidRegistryException,
539 : css::uno::RuntimeException);
540 :
541 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL openKey(
542 : rtl::OUString const & aKeyName)
543 : throw (
544 : css::registry::InvalidRegistryException,
545 : css::uno::RuntimeException);
546 :
547 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
548 : createKey(rtl::OUString const & aKeyName) throw (
549 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
550 :
551 : virtual void SAL_CALL closeKey() throw (
552 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
553 :
554 : virtual void SAL_CALL deleteKey(rtl::OUString const & rKeyName) throw (
555 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
556 :
557 : virtual
558 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
559 : SAL_CALL openKeys() throw (
560 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
561 :
562 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL getKeyNames() throw (
563 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
564 :
565 : virtual sal_Bool SAL_CALL createLink(
566 : rtl::OUString const & aLinkName, rtl::OUString const & aLinkTarget)
567 : throw (
568 : css::registry::InvalidRegistryException,
569 : css::uno::RuntimeException);
570 :
571 : virtual void SAL_CALL deleteLink(rtl::OUString const & rLinkName) throw (
572 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
573 :
574 : virtual rtl::OUString SAL_CALL getLinkTarget(
575 : rtl::OUString const & rLinkName)
576 : throw (
577 : css::registry::InvalidRegistryException,
578 : css::uno::RuntimeException);
579 :
580 : virtual rtl::OUString SAL_CALL getResolvedName(
581 : rtl::OUString const & aKeyName)
582 : throw (
583 : css::registry::InvalidRegistryException,
584 : css::uno::RuntimeException);
585 :
586 : bool find(
587 : rtl::OUString const & relative, std::vector< rtl::OUString > * path,
588 : State * state, css::registry::RegistryValueType * type) const;
589 :
590 : css::uno::Sequence< rtl::OUString > getChildren();
591 :
592 : rtl::Reference< Data > data_;
593 : std::vector< rtl::OUString > path_;
594 : };
595 :
596 50 : rtl::OUString Key::getKeyName() throw (css::uno::RuntimeException) {
597 50 : return pathToString(path_);
598 : }
599 :
600 0 : sal_Bool Key::isReadOnly()
601 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
602 : {
603 0 : return true;
604 : }
605 :
606 374 : sal_Bool Key::isValid() throw(css::uno::RuntimeException) {
607 374 : return true;
608 : }
609 :
610 0 : css::registry::RegistryKeyType Key::getKeyType(rtl::OUString const & rKeyName)
611 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
612 : {
613 0 : if (!find(rtl::OUString(), 0, 0, 0)) {
614 : throw css::registry::InvalidRegistryException(
615 : (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("unknown key ")) +
616 0 : rKeyName),
617 0 : static_cast< cppu::OWeakObject * >(this));
618 : }
619 0 : return css::registry::RegistryKeyType_KEY;
620 : }
621 :
622 32 : css::registry::RegistryValueType Key::getValueType()
623 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
624 : {
625 : css::registry::RegistryValueType type =
626 32 : css::registry::RegistryValueType_NOT_DEFINED;
627 32 : OSL_VERIFY(find(rtl::OUString(), 0, 0, &type));
628 32 : return type;
629 : }
630 :
631 0 : sal_Int32 Key::getLongValue() throw (
632 : css::registry::InvalidRegistryException,
633 : css::registry::InvalidValueException, css::uno::RuntimeException)
634 : {
635 : throw css::registry::InvalidValueException(
636 : rtl::OUString(
637 : RTL_CONSTASCII_USTRINGPARAM(
638 : "com.sun.star.registry.SimpleRegistry textual services key"
639 : " getLongValue not supported")),
640 0 : static_cast< OWeakObject * >(this));
641 : }
642 :
643 0 : void Key::setLongValue(sal_Int32)
644 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
645 : {
646 : throw css::registry::InvalidRegistryException(
647 : rtl::OUString(
648 : RTL_CONSTASCII_USTRINGPARAM(
649 : "com.sun.star.registry.SimpleRegistry textual services key"
650 : " setLongValue not supported")),
651 0 : static_cast< OWeakObject * >(this));
652 : }
653 :
654 0 : css::uno::Sequence< sal_Int32 > Key::getLongListValue() throw (
655 : css::registry::InvalidRegistryException,
656 : css::registry::InvalidValueException, css::uno::RuntimeException)
657 : {
658 : throw css::registry::InvalidValueException(
659 : rtl::OUString(
660 : RTL_CONSTASCII_USTRINGPARAM(
661 : "com.sun.star.registry.SimpleRegistry textual services key"
662 : " getLongListValue not supported")),
663 0 : static_cast< OWeakObject * >(this));
664 : }
665 :
666 0 : void Key::setLongListValue(css::uno::Sequence< sal_Int32 > const &)
667 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
668 : {
669 : throw css::registry::InvalidRegistryException(
670 : rtl::OUString(
671 : RTL_CONSTASCII_USTRINGPARAM(
672 : "com.sun.star.registry.SimpleRegistry textual services key"
673 : " setLongListValue not supported")),
674 0 : static_cast< OWeakObject * >(this));
675 : }
676 :
677 24 : rtl::OUString Key::getAsciiValue() throw (
678 : css::registry::InvalidRegistryException,
679 : css::registry::InvalidValueException, css::uno::RuntimeException)
680 : {
681 24 : State state = STATE_ROOT;
682 24 : OSL_VERIFY(find(rtl::OUString(), 0, &state, 0));
683 24 : switch (state) {
684 : case STATE_LOCATION:
685 8 : return data_->implementations[path_[1]].uri;
686 : case STATE_ACTIVATOR:
687 8 : return data_->implementations[path_[1]].loader;
688 : case STATE_PREFIX:
689 8 : return data_->implementations[path_[1]].prefix;
690 : default:
691 : throw css::registry::InvalidValueException(
692 : rtl::OUString(
693 : RTL_CONSTASCII_USTRINGPARAM(
694 : "com.sun.star.registry.SimpleRegistry textual services key"
695 : " getAsciiValue: wrong type")),
696 0 : static_cast< OWeakObject * >(this));
697 : }
698 : }
699 :
700 0 : void Key::setAsciiValue(rtl::OUString const &)
701 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
702 : {
703 : throw css::registry::InvalidRegistryException(
704 : rtl::OUString(
705 : RTL_CONSTASCII_USTRINGPARAM(
706 : "com.sun.star.registry.SimpleRegistry textual services key"
707 : " setAsciiValue not supported")),
708 0 : static_cast< OWeakObject * >(this));
709 : }
710 :
711 8 : css::uno::Sequence< rtl::OUString > Key::getAsciiListValue() throw (
712 : css::registry::InvalidRegistryException,
713 : css::registry::InvalidValueException, css::uno::RuntimeException)
714 : {
715 8 : State state = STATE_ROOT;
716 8 : OSL_VERIFY(find(rtl::OUString(), 0, &state, 0));
717 : std::vector< rtl::OUString > const * list;
718 8 : switch (state) {
719 : case STATE_SERVICE:
720 8 : list = &data_->services[path_[1]];
721 8 : break;
722 : case STATE_REGISTEREDBY:
723 0 : list = &data_->singletons[path_[1]];
724 0 : break;
725 : default:
726 : throw css::registry::InvalidValueException(
727 : rtl::OUString(
728 : RTL_CONSTASCII_USTRINGPARAM(
729 : "com.sun.star.registry.SimpleRegistry textual services key"
730 : " getAsciiListValue: wrong type")),
731 0 : static_cast< OWeakObject * >(this));
732 : }
733 8 : if (list->size() > SAL_MAX_INT32) {
734 : throw css::registry::InvalidValueException(
735 : rtl::OUString(
736 : RTL_CONSTASCII_USTRINGPARAM(
737 : "com.sun.star.registry.SimpleRegistry textual services key"
738 : " getAsciiListValue: too large")),
739 0 : static_cast< OWeakObject * >(this));
740 : }
741 : css::uno::Sequence< rtl::OUString > seq(
742 8 : static_cast< sal_Int32 >(list->size()));
743 8 : sal_Int32 i = 0;
744 48 : for (std::vector< rtl::OUString >::const_iterator j(list->begin());
745 32 : j != list->end(); ++j)
746 : {
747 8 : seq[i++] = *j;
748 : }
749 8 : return seq;
750 : }
751 :
752 0 : void Key::setAsciiListValue(css::uno::Sequence< rtl::OUString > const &)
753 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
754 : {
755 : throw css::registry::InvalidRegistryException(
756 : rtl::OUString(
757 : RTL_CONSTASCII_USTRINGPARAM(
758 : "com.sun.star.registry.SimpleRegistry textual services key"
759 : " setAsciiListValue not supported")),
760 0 : static_cast< OWeakObject * >(this));
761 : }
762 :
763 0 : rtl::OUString Key::getStringValue() throw (
764 : css::registry::InvalidRegistryException,
765 : css::registry::InvalidValueException, css::uno::RuntimeException)
766 : {
767 0 : State state = STATE_ROOT;
768 0 : OSL_VERIFY(find(rtl::OUString(), 0, &state, 0));
769 0 : switch (state) {
770 : case STATE_IMPLEMENTATION_SINGLETON:
771 : case STATE_SINGLETON:
772 : throw css::registry::InvalidRegistryException(
773 : rtl::OUString(
774 : RTL_CONSTASCII_USTRINGPARAM(
775 : "com.sun.star.registry.SimpleRegistry textual services key"
776 : " getStringValue: does not associate singletons with"
777 : " services")),
778 0 : static_cast< OWeakObject * >(this));
779 : default:
780 0 : break;
781 : }
782 : // default case extracted from switch to avoid erroneous compiler warnings
783 : // on Solaris:
784 : throw css::registry::InvalidValueException(
785 : rtl::OUString(
786 : RTL_CONSTASCII_USTRINGPARAM(
787 : "com.sun.star.registry.SimpleRegistry textual services key"
788 : " getStringValue: wrong type")),
789 0 : static_cast< OWeakObject * >(this));
790 : }
791 :
792 0 : void Key::setStringValue(rtl::OUString const &)
793 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
794 : {
795 : throw css::registry::InvalidRegistryException(
796 : rtl::OUString(
797 : RTL_CONSTASCII_USTRINGPARAM(
798 : "com.sun.star.registry.SimpleRegistry textual services key"
799 : " setStringValue not supported")),
800 0 : static_cast< OWeakObject * >(this));
801 : }
802 :
803 0 : css::uno::Sequence< rtl::OUString > Key::getStringListValue() throw (
804 : css::registry::InvalidRegistryException,
805 : css::registry::InvalidValueException, css::uno::RuntimeException)
806 : {
807 : throw css::registry::InvalidValueException(
808 : rtl::OUString(
809 : RTL_CONSTASCII_USTRINGPARAM(
810 : "com.sun.star.registry.SimpleRegistry textual services key"
811 : " getStringListValue not supported")),
812 0 : static_cast< OWeakObject * >(this));
813 : }
814 :
815 0 : void Key::setStringListValue(css::uno::Sequence< rtl::OUString > const &)
816 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
817 : {
818 : throw css::registry::InvalidRegistryException(
819 : rtl::OUString(
820 : RTL_CONSTASCII_USTRINGPARAM(
821 : "com.sun.star.registry.SimpleRegistry textual services key"
822 : " setStringListValue not supported")),
823 0 : static_cast< OWeakObject * >(this));
824 : }
825 :
826 0 : css::uno::Sequence< sal_Int8 > Key::getBinaryValue()
827 : throw (
828 : css::registry::InvalidRegistryException,
829 : css::registry::InvalidValueException, css::uno::RuntimeException)
830 : {
831 : throw css::registry::InvalidValueException(
832 : rtl::OUString(
833 : RTL_CONSTASCII_USTRINGPARAM(
834 : "com.sun.star.registry.SimpleRegistry textual services key"
835 : " getBinarValue not supported")),
836 0 : static_cast< OWeakObject * >(this));
837 : }
838 :
839 0 : void Key::setBinaryValue(css::uno::Sequence< sal_Int8 > const &)
840 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
841 : {
842 : throw css::registry::InvalidRegistryException(
843 : rtl::OUString(
844 : RTL_CONSTASCII_USTRINGPARAM(
845 : "com.sun.star.registry.SimpleRegistry textual services key"
846 : " setBinaryValue not supported")),
847 0 : static_cast< OWeakObject * >(this));
848 : }
849 :
850 130 : css::uno::Reference< css::registry::XRegistryKey > Key::openKey(
851 : rtl::OUString const & aKeyName)
852 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
853 : {
854 130 : std::vector< rtl::OUString > path;
855 130 : if (!find(aKeyName, &path, 0, 0)) {
856 72 : return css::uno::Reference< css::registry::XRegistryKey >();
857 : }
858 58 : return new Key(data_, path);
859 : }
860 :
861 0 : css::uno::Reference< css::registry::XRegistryKey > Key::createKey(
862 : rtl::OUString const &)
863 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
864 : {
865 : throw css::registry::InvalidRegistryException(
866 : rtl::OUString(
867 : RTL_CONSTASCII_USTRINGPARAM(
868 : "com.sun.star.registry.SimpleRegistry textual services key"
869 : " createKey not supported")),
870 0 : static_cast< OWeakObject * >(this));
871 : }
872 :
873 0 : void Key::closeKey()
874 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
875 0 : {}
876 :
877 0 : void Key::deleteKey(rtl::OUString const &)
878 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
879 : {
880 : throw css::registry::InvalidRegistryException(
881 : rtl::OUString(
882 : RTL_CONSTASCII_USTRINGPARAM(
883 : "com.sun.star.registry.SimpleRegistry textual services key"
884 : " deleteKey not supported")),
885 0 : static_cast< OWeakObject * >(this));
886 : }
887 :
888 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
889 0 : Key::openKeys()
890 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
891 : {
892 0 : css::uno::Sequence< rtl::OUString > names(getChildren());
893 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
894 0 : keys(names.getLength());
895 0 : for (sal_Int32 i = 0; i < keys.getLength(); ++i) {
896 0 : keys[i] = openKey(names[i]);
897 : OSL_ASSERT(keys[i].is());
898 : }
899 0 : return keys;
900 : }
901 :
902 10 : css::uno::Sequence< rtl::OUString > Key::getKeyNames()
903 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
904 : {
905 10 : css::uno::Sequence< rtl::OUString > names(getChildren());
906 10 : rtl::OUString prefix(pathToString(path_));
907 10 : prefix += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
908 18 : for (sal_Int32 i = 0; i < names.getLength(); ++i) {
909 8 : names[i] = prefix + names[i];
910 : }
911 10 : return names;
912 : }
913 :
914 0 : sal_Bool Key::createLink(rtl::OUString const &, rtl::OUString const &)
915 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
916 : {
917 : throw css::registry::InvalidRegistryException(
918 : rtl::OUString(
919 : RTL_CONSTASCII_USTRINGPARAM(
920 : "com.sun.star.registry.SimpleRegistry textual services key"
921 : " createLink not supported")),
922 0 : static_cast< OWeakObject * >(this));
923 : }
924 :
925 0 : void Key::deleteLink(rtl::OUString const &)
926 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
927 : {
928 : throw css::registry::InvalidRegistryException(
929 : rtl::OUString(
930 : RTL_CONSTASCII_USTRINGPARAM(
931 : "com.sun.star.registry.SimpleRegistry textual services key"
932 : " deleteLink not supported")),
933 0 : static_cast< OWeakObject * >(this));
934 : }
935 :
936 0 : rtl::OUString Key::getLinkTarget(rtl::OUString const &)
937 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
938 : {
939 : throw css::registry::InvalidRegistryException(
940 : rtl::OUString(
941 : RTL_CONSTASCII_USTRINGPARAM(
942 : "com.sun.star.registry.SimpleRegistry textual services key"
943 : " getLinkTarget not supported")),
944 0 : static_cast< OWeakObject * >(this));
945 : }
946 :
947 244 : rtl::OUString Key::getResolvedName(rtl::OUString const & aKeyName)
948 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
949 : {
950 244 : std::vector< rtl::OUString > path;
951 244 : find(aKeyName, &path, 0, 0);
952 244 : return pathToString(path);
953 : }
954 :
955 448 : bool Key::find(
956 : rtl::OUString const & relative, std::vector< rtl::OUString > * path,
957 : State * state, css::registry::RegistryValueType * type) const
958 : {
959 448 : std::vector< rtl::OUString > p(path_);
960 448 : sal_Int32 i = 0;
961 1990 : do {
962 1990 : rtl::OUString seg(relative.getToken(0, '/', i));
963 1990 : if (!seg.isEmpty()) {
964 1550 : p.push_back(seg);
965 1990 : }
966 : } while (i >= 0);
967 448 : if (path != 0) {
968 374 : *path = p;
969 : }
970 448 : std::size_t const MAX_TRANSITIONS = 5;
971 : struct StateInfo {
972 : css::registry::RegistryValueType type;
973 : std::size_t count;
974 : struct { char const * segment; State state; }
975 : transitions[MAX_TRANSITIONS];
976 : };
977 : static StateInfo const info[] = {
978 : // STATE_ROOT:
979 : { css::registry::RegistryValueType_NOT_DEFINED, 3,
980 : { { "IMPLEMENTATIONS", STATE_IMPLEMENTATIONS },
981 : { "SERVICES", STATE_SERVICES },
982 : { "SINGLETONS", STATE_SINGLETONS } } },
983 : // STATE_IMPLEMENTATIONS:
984 : { css::registry::RegistryValueType_NOT_DEFINED, 1,
985 : { { 0, STATE_IMPLEMENTATION } } },
986 : // STATE_IMPLEMENTATION:
987 : { css::registry::RegistryValueType_NOT_DEFINED, 1,
988 : { { "UNO", STATE_UNO } } },
989 : // STATE_UNO:
990 : { css::registry::RegistryValueType_NOT_DEFINED, 5,
991 : { { "LOCATION", STATE_LOCATION },
992 : { "ACTIVATOR", STATE_ACTIVATOR },
993 : { "PREFIX", STATE_PREFIX },
994 : { "SERVICES", STATE_IMPLEMENTATION_SERVICES },
995 : { "SINGLETONS", STATE_IMPLEMENTATION_SINGLETONS } } },
996 : // STATE_LOCATION:
997 : { css::registry::RegistryValueType_ASCII, 0, {} },
998 : // STATE_ACTIVATOR:
999 : { css::registry::RegistryValueType_ASCII, 0, {} },
1000 : // STATE_PREFIX:
1001 : { css::registry::RegistryValueType_ASCII, 0, {} },
1002 : // STATE_IMPLEMENTATION_SERVICES:
1003 : { css::registry::RegistryValueType_NOT_DEFINED, 1,
1004 : { { 0, STATE_IMPLEMENTATION_SERVICE } } },
1005 : // STATE_IMPLEMENTATION_SERVICE:
1006 : { css::registry::RegistryValueType_NOT_DEFINED, 0, {} },
1007 : // STATE_IMPLEMENTATION_SINGLETONS:
1008 : { css::registry::RegistryValueType_NOT_DEFINED, 1,
1009 : { { 0, STATE_IMPLEMENTATION_SINGLETON } } },
1010 : // STATE_IMPLEMENTATION_SINGLETON:
1011 : { css::registry::RegistryValueType_STRING, 0, {} },
1012 : // STATE_SERVICES:
1013 : { css::registry::RegistryValueType_NOT_DEFINED, 1,
1014 : { { 0, STATE_SERVICE } } },
1015 : // STATE_SERVICE:
1016 : { css::registry::RegistryValueType_ASCIILIST, 0, {} },
1017 : // STATE_SINGLETONS:
1018 : { css::registry::RegistryValueType_NOT_DEFINED, 1,
1019 : { { 0, STATE_SINGLETON } } },
1020 : // STATE_SINGLETON:
1021 : { css::registry::RegistryValueType_STRING, 1,
1022 : { { "REGISTERED_BY", STATE_REGISTEREDBY } } },
1023 : // STATE_REGISTEREDBY:
1024 : { css::registry::RegistryValueType_ASCIILIST, 0, {} } };
1025 448 : State s = STATE_ROOT;
1026 1272 : for (std::vector< rtl::OUString >::iterator j(p.begin()); j != p.end(); ++j)
1027 : {
1028 1040 : bool found = false;
1029 1968 : for (std::size_t k = 0; k < info[s].count; ++k) {
1030 1752 : if (info[s].transitions[k].segment == 0) {
1031 224 : switch (info[s].transitions[k].state) {
1032 : case STATE_IMPLEMENTATION:
1033 208 : found = data_->implementations.find(*j) !=
1034 416 : data_->implementations.end();
1035 208 : break;
1036 : case STATE_IMPLEMENTATION_SERVICE:
1037 : case STATE_IMPLEMENTATION_SINGLETON:
1038 0 : found = true; //TODO
1039 0 : break;
1040 : case STATE_SERVICE:
1041 16 : found = data_->services.find(*j) != data_->services.end();
1042 16 : break;
1043 : case STATE_SINGLETON:
1044 0 : found = data_->singletons.find(*j) !=
1045 0 : data_->singletons.end();
1046 0 : break;
1047 : default:
1048 0 : std::abort(); // this cannot happen
1049 : }
1050 : } else {
1051 1528 : found = j->equalsAscii(info[s].transitions[k].segment);
1052 : }
1053 1752 : if (found) {
1054 824 : s = info[s].transitions[k].state;
1055 824 : break;
1056 : }
1057 : }
1058 1040 : if (!found) {
1059 216 : return false;
1060 : }
1061 : }
1062 232 : if (state != 0) {
1063 42 : *state = s;
1064 : }
1065 232 : if (type != 0) {
1066 32 : *type = info[s].type;
1067 : }
1068 232 : return true;
1069 : }
1070 :
1071 10 : css::uno::Sequence< rtl::OUString > Key::getChildren() {
1072 10 : State state = STATE_ROOT;
1073 10 : OSL_VERIFY(find(rtl::OUString(), 0, &state, 0));
1074 10 : switch (state) {
1075 : default:
1076 0 : std::abort(); // this cannot happen
1077 : // pseudo-fall-through to avoid warnings on MSC
1078 : case STATE_ROOT:
1079 : {
1080 0 : css::uno::Sequence< rtl::OUString > seq(3);
1081 0 : seq[0] = rtl::OUString(
1082 0 : RTL_CONSTASCII_USTRINGPARAM("IMPLEMENTATIONS"));
1083 0 : seq[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SERVICES"));
1084 0 : seq[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SINGLETONS"));
1085 0 : return seq;
1086 : }
1087 : case STATE_IMPLEMENTATIONS:
1088 : {
1089 0 : if (data_->implementations.size() > SAL_MAX_INT32) {
1090 : throw css::registry::InvalidValueException(
1091 : rtl::OUString(
1092 : RTL_CONSTASCII_USTRINGPARAM(
1093 : "com.sun.star.registry.SimpleRegistry textual"
1094 : " services key openKeys: too large")),
1095 0 : static_cast< OWeakObject * >(this));
1096 : }
1097 : css::uno::Sequence< rtl::OUString > seq(
1098 0 : static_cast< sal_Int32 >(data_->implementations.size()));
1099 0 : sal_Int32 i = 0;
1100 0 : for (Implementations::iterator j(data_->implementations.begin());
1101 0 : j != data_->implementations.end(); ++j)
1102 : {
1103 0 : seq[i++] = j->first;
1104 : }
1105 0 : return seq;
1106 : }
1107 : case STATE_UNO:
1108 : {
1109 0 : css::uno::Sequence< rtl::OUString > seq(5);
1110 0 : seq[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOCATION"));
1111 0 : seq[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ACTIVATOR"));
1112 0 : seq[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PREFIX"));
1113 0 : seq[3] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SERVICES"));
1114 0 : seq[4] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SINGLETONS"));
1115 0 : return seq;
1116 : }
1117 : case STATE_LOCATION:
1118 : case STATE_ACTIVATOR:
1119 : case STATE_PREFIX:
1120 : case STATE_IMPLEMENTATION_SERVICE:
1121 : case STATE_IMPLEMENTATION_SINGLETON:
1122 : case STATE_SERVICE:
1123 : case STATE_REGISTEREDBY:
1124 0 : return css::uno::Sequence< rtl::OUString >();
1125 : case STATE_IMPLEMENTATION_SERVICES:
1126 : {
1127 8 : if (data_->implementations[path_[1]].services.size() >
1128 : SAL_MAX_INT32)
1129 : {
1130 : throw css::registry::InvalidValueException(
1131 : rtl::OUString(
1132 : RTL_CONSTASCII_USTRINGPARAM(
1133 : "com.sun.star.registry.SimpleRegistry textual"
1134 : " services key openKeys: too large")),
1135 0 : static_cast< OWeakObject * >(this));
1136 : }
1137 : css::uno::Sequence< rtl::OUString > seq(
1138 : static_cast< sal_Int32 >(
1139 8 : data_->implementations[path_[1]].services.size()));
1140 8 : sal_Int32 i = 0;
1141 48 : for (std::vector< rtl::OUString >::iterator j(
1142 8 : data_->implementations[path_[1]].services.begin());
1143 32 : j != data_->implementations[path_[1]].services.end(); ++j)
1144 : {
1145 8 : seq[i++] = *j;
1146 : }
1147 8 : return seq;
1148 : }
1149 : case STATE_IMPLEMENTATION_SINGLETONS:
1150 : {
1151 0 : if (data_->implementations[path_[1]].singletons.size() >
1152 : SAL_MAX_INT32)
1153 : {
1154 : throw css::registry::InvalidValueException(
1155 : rtl::OUString(
1156 : RTL_CONSTASCII_USTRINGPARAM(
1157 : "com.sun.star.registry.SimpleRegistry textual"
1158 : " services key openKeys: too large")),
1159 0 : static_cast< OWeakObject * >(this));
1160 : }
1161 : css::uno::Sequence< rtl::OUString > seq(
1162 : static_cast< sal_Int32 >(
1163 0 : data_->implementations[path_[1]].singletons.size()));
1164 0 : sal_Int32 i = 0;
1165 0 : for (std::vector< rtl::OUString >::iterator j(
1166 0 : data_->implementations[path_[1]].singletons.begin());
1167 0 : j != data_->implementations[path_[1]].singletons.end(); ++j)
1168 : {
1169 0 : seq[i++] = *j;
1170 : }
1171 0 : return seq;
1172 : }
1173 : case STATE_SERVICES:
1174 : {
1175 0 : if (data_->services.size() > SAL_MAX_INT32) {
1176 : throw css::registry::InvalidValueException(
1177 : rtl::OUString(
1178 : RTL_CONSTASCII_USTRINGPARAM(
1179 : "com.sun.star.registry.SimpleRegistry textual"
1180 : " services key openKeys: too large")),
1181 0 : static_cast< OWeakObject * >(this));
1182 : }
1183 : css::uno::Sequence< rtl::OUString > seq(
1184 0 : static_cast< sal_Int32 >(data_->services.size()));
1185 0 : sal_Int32 i = 0;
1186 0 : for (ImplementationMap::iterator j(data_->services.begin());
1187 0 : j != data_->services.end(); ++j)
1188 : {
1189 0 : seq[i++] = j->first;
1190 : }
1191 0 : return seq;
1192 : }
1193 : case STATE_SINGLETONS:
1194 : {
1195 2 : if (data_->singletons.size() > SAL_MAX_INT32) {
1196 : throw css::registry::InvalidValueException(
1197 : rtl::OUString(
1198 : RTL_CONSTASCII_USTRINGPARAM(
1199 : "com.sun.star.registry.SimpleRegistry textual"
1200 : " services key openKeys: too large")),
1201 0 : static_cast< OWeakObject * >(this));
1202 : }
1203 : css::uno::Sequence< rtl::OUString > seq(
1204 2 : static_cast< sal_Int32 >(data_->singletons.size()));
1205 2 : sal_Int32 i = 0;
1206 6 : for (ImplementationMap::iterator j(data_->singletons.begin());
1207 4 : j != data_->singletons.end(); ++j)
1208 : {
1209 0 : seq[i++] = j->first;
1210 : }
1211 2 : return seq;
1212 : }
1213 : case STATE_SINGLETON:
1214 : {
1215 0 : css::uno::Sequence< rtl::OUString > seq(1);
1216 0 : seq[0] = rtl::OUString(
1217 0 : RTL_CONSTASCII_USTRINGPARAM("REGISTERED_BY"));
1218 0 : return seq;
1219 : }
1220 : }
1221 : }
1222 :
1223 : }
1224 :
1225 2 : TextualServices::TextualServices(rtl::OUString const & uri):
1226 2 : uri_(uri), data_(new Data)
1227 : {
1228 : try {
1229 2 : Parser(uri, data_);
1230 0 : } catch (css::container::NoSuchElementException &) {
1231 : throw css::registry::InvalidRegistryException(
1232 : (uri +
1233 : rtl::OUString(
1234 0 : RTL_CONSTASCII_USTRINGPARAM(": no such file"))),
1235 0 : css::uno::Reference< css::uno::XInterface >());
1236 : }
1237 2 : }
1238 :
1239 0 : TextualServices::~TextualServices() {}
1240 :
1241 544 : css::uno::Reference< css::registry::XRegistryKey > TextualServices::getRootKey()
1242 : {
1243 544 : return new Key(data_, std::vector< rtl::OUString >());
1244 : }
1245 :
1246 : } }
1247 :
1248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|