1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
31 #include <libxslt/security.h>
35 #include <com/sun/star/container/ElementExistException.hpp>
36 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <com/sun/star/io/XSeekable.hpp>
42 #include <com/sun/star/text/XTextRange.hpp>
43 #include <com/sun/star/rdf/ParseException.hpp>
44 #include <com/sun/star/rdf/QueryException.hpp>
45 #include <com/sun/star/rdf/RepositoryException.hpp>
46 #include <com/sun/star/rdf/XDocumentRepository.hpp>
47 #include <com/sun/star/rdf/XLiteral.hpp>
48 #include <com/sun/star/rdf/FileFormat.hpp>
49 #include <com/sun/star/rdf/BlankNode.hpp>
50 #include <com/sun/star/rdf/URI.hpp>
51 #include <com/sun/star/rdf/Literal.hpp>
53 #include <rtl/ref.hxx>
54 #include <rtl/strbuf.hxx>
55 #include <rtl/ustrbuf.hxx>
56 #include <rtl/ustring.hxx>
57 #include <osl/diagnose.h>
58 #include <cppuhelper/exc_hlp.hxx>
59 #include <cppuhelper/implbase.hxx>
60 #include <cppuhelper/supportsservice.hxx>
61 #include <cppuhelper/weakref.hxx>
63 #include <comphelper/sequence.hxx>
64 #include <comphelper/xmltools.hxx>
66 #include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
69 Implementation of the service com.sun.star.rdf.Repository.
71 This implementation uses the Redland RDF library (librdf).
73 There are several classes involved:
74 librdf_TypeConverter: helper class to convert data types redland <-> uno
75 librdf_Repository: the main repository, does almost all the work
76 librdf_NamedGraph: the XNamedGraph, forwards everything to repository
77 librdf_GraphResult: an XEnumeration<Statement>
78 librdf_QuerySelectResult: an XEnumeration<sequence<XNode>>
82 /// anonymous implementation namespace
85 class librdf_NamedGraph
;
86 class librdf_Repository
;
88 using namespace ::com::sun::star
;
90 typedef std::map
< OUString
, ::rtl::Reference
<librdf_NamedGraph
> >
93 const char s_sparql
[] = "sparql";
94 const char s_nsOOo
[] = "http://openoffice.org/2004/office/rdfa/";
97 //FIXME: this approach is not ideal. can we use blank nodes instead?
98 bool isInternalContext(librdf_node
*i_pNode
) throw ()
100 OSL_ENSURE(i_pNode
, "isInternalContext: context null");
101 OSL_ENSURE(librdf_node_is_resource(i_pNode
),
102 "isInternalContext: context not resource");
104 librdf_uri
*pURI(librdf_node_get_uri(i_pNode
));
105 OSL_ENSURE(pURI
, "isInternalContext: URI null");
107 unsigned char *pContextURI(librdf_uri_as_string(pURI
));
108 assert(pContextURI
&& "isInternalContext: URI string null");
109 // if prefix matches reserved uri, it is RDFa context
110 if (!strncmp(reinterpret_cast<char *>(pContextURI
),
111 s_nsOOo
, sizeof(s_nsOOo
)-1)) {
121 // n.b.: librdf destructor functions dereference null pointers!
122 // so they need to be wrapped to be usable with std::shared_ptr.
123 void safe_librdf_free_world(librdf_world
*const world
)
125 if (world
) { librdf_free_world(world
); }
127 void safe_librdf_free_model(librdf_model
*const model
)
129 if (model
) { librdf_free_model(model
); }
131 void safe_librdf_free_node(librdf_node
* node
)
133 if (node
) { librdf_free_node(node
); }
135 void safe_librdf_free_parser(librdf_parser
*const parser
)
137 if (parser
) { librdf_free_parser(parser
); }
139 void safe_librdf_free_query(librdf_query
*const query
)
141 if (query
) { librdf_free_query(query
); }
144 safe_librdf_free_query_results(librdf_query_results
*const query_results
)
146 if (query_results
) { librdf_free_query_results(query_results
); }
148 void safe_librdf_free_serializer(librdf_serializer
*const serializer
)
150 if (serializer
) { librdf_free_serializer(serializer
); }
152 void safe_librdf_free_statement(librdf_statement
*const statement
)
154 if (statement
) { librdf_free_statement(statement
); }
156 void safe_librdf_free_storage(librdf_storage
*const storage
)
158 if (storage
) { librdf_free_storage(storage
); }
160 void safe_librdf_free_stream(librdf_stream
*const stream
)
162 if (stream
) { librdf_free_stream(stream
); }
164 void safe_librdf_free_uri(librdf_uri
*const uri
)
166 if (uri
) { librdf_free_uri(uri
); }
170 /** converts between librdf types and UNO API types.
172 class librdf_TypeConverter
176 // some wrapper classes to temporarily hold values of UNO XNodes
181 struct Resource
: public Node
{ };
182 struct URI
: public Resource
185 explicit URI(OString
const& i_rValue
)
189 struct BlankNode
: public Resource
192 explicit BlankNode(OString
const& i_rValue
)
196 struct Literal
: public Node
199 OString
const language
;
200 ::std::optional
<OString
> const type
;
201 Literal(OString
const& i_rValue
, OString
const& i_rLanguage
,
202 ::std::optional
<OString
> const& i_rType
)
204 , language(i_rLanguage
)
210 std::shared_ptr
<Resource
> const pSubject
;
211 std::shared_ptr
<URI
> const pPredicate
;
212 std::shared_ptr
<Node
> const pObject
;
213 Statement(std::shared_ptr
<Resource
> const& i_pSubject
,
214 std::shared_ptr
<URI
> const& i_pPredicate
,
215 std::shared_ptr
<Node
> const& i_pObject
)
216 : pSubject(i_pSubject
)
217 , pPredicate(i_pPredicate
)
222 librdf_TypeConverter(
223 uno::Reference
< uno::XComponentContext
> const & i_xContext
,
224 librdf_Repository
&i_rRep
)
225 : m_xContext(i_xContext
)
229 librdf_world
*createWorld_Lock() const;
230 librdf_storage
*createStorage_Lock(librdf_world
*i_pWorld
) const;
231 librdf_model
*createModel_Lock(librdf_world
*i_pWorld
,
232 librdf_storage
* i_pStorage
) const;
233 static librdf_uri
* mkURI_Lock(librdf_world
* i_pWorld
,
234 const OString
& i_rURI
);
235 static librdf_node
* mkResource_Lock(librdf_world
* i_pWorld
,
236 const Resource
* i_pResource
);
237 static librdf_node
* mkNode_Lock(librdf_world
* i_pWorld
,
238 const Node
* i_pNode
);
239 static librdf_statement
* mkStatement_Lock(librdf_world
* i_pWorld
,
240 Statement
const& i_rStatement
);
241 static std::shared_ptr
<Resource
> extractResource_NoLock(
242 const uno::Reference
< rdf::XResource
> & i_xResource
);
243 static void extractResourceToCacheKey_NoLock(
244 const uno::Reference
< rdf::XResource
> & i_xResource
,
245 OUStringBuffer
& rBuf
);
246 static std::shared_ptr
<Node
> extractNode_NoLock(
247 const uno::Reference
< rdf::XNode
> & i_xNode
);
248 static void extractNodeToCacheKey_NoLock(
249 const uno::Reference
< rdf::XNode
> & i_xNode
,
250 OUStringBuffer
& rBuffer
);
251 static Statement
extractStatement_NoLock(
252 const uno::Reference
< rdf::XResource
> & i_xSubject
,
253 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
254 const uno::Reference
< rdf::XNode
> & i_xObject
);
255 uno::Reference
<rdf::XURI
> convertToXURI(librdf_uri
* i_pURI
) const;
256 uno::Reference
<rdf::XURI
> convertToXURI(librdf_node
* i_pURI
) const;
257 uno::Reference
<rdf::XResource
>
258 convertToXResource(librdf_node
* i_pNode
) const;
259 uno::Reference
<rdf::XNode
> convertToXNode(librdf_node
* i_pNode
) const;
261 convertToStatement(librdf_statement
* i_pStmt
, librdf_node
* i_pContext
)
265 uno::Reference
< uno::XComponentContext
> const m_xContext
;
266 librdf_Repository
& m_rRep
;
270 /** implements the repository service.
272 class librdf_Repository
:
273 // private ::cppu::BaseMutex,
274 public ::cppu::WeakImplHelper
<
276 rdf::XDocumentRepository
,
277 lang::XInitialization
>
281 explicit librdf_Repository(
282 uno::Reference
< uno::XComponentContext
> const & i_xContext
);
283 virtual ~librdf_Repository() override
;
285 // css::lang::XServiceInfo:
286 virtual OUString SAL_CALL
getImplementationName() override
;
287 virtual sal_Bool SAL_CALL
supportsService(
288 const OUString
& ServiceName
) override
;
289 virtual uno::Sequence
< OUString
> SAL_CALL
290 getSupportedServiceNames() override
;
292 // css::rdf::XRepository:
293 virtual uno::Reference
< rdf::XBlankNode
> SAL_CALL
createBlankNode() override
;
294 virtual uno::Reference
<rdf::XNamedGraph
> SAL_CALL
importGraph(
295 ::sal_Int16 i_Format
,
296 const uno::Reference
< io::XInputStream
> & i_xInStream
,
297 const uno::Reference
< rdf::XURI
> & i_xGraphName
,
298 const uno::Reference
< rdf::XURI
> & i_xBaseURI
) override
;
299 virtual void SAL_CALL
exportGraph(::sal_Int16 i_Format
,
300 const uno::Reference
< io::XOutputStream
> & i_xOutStream
,
301 const uno::Reference
< rdf::XURI
> & i_xGraphName
,
302 const uno::Reference
< rdf::XURI
> & i_xBaseURI
) override
;
303 virtual uno::Sequence
< uno::Reference
< rdf::XURI
> > SAL_CALL
304 getGraphNames() override
;
305 virtual uno::Reference
< rdf::XNamedGraph
> SAL_CALL
getGraph(
306 const uno::Reference
< rdf::XURI
> & i_xGraphName
) override
;
307 virtual uno::Reference
< rdf::XNamedGraph
> SAL_CALL
createGraph(
308 const uno::Reference
< rdf::XURI
> & i_xGraphName
) override
;
309 virtual void SAL_CALL
destroyGraph(
310 const uno::Reference
< rdf::XURI
> & i_xGraphName
) override
;
311 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
getStatements(
312 const uno::Reference
< rdf::XResource
> & i_xSubject
,
313 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
314 const uno::Reference
< rdf::XNode
> & i_xObject
) override
;
315 virtual uno::Reference
< rdf::XQuerySelectResult
> SAL_CALL
316 querySelect(const OUString
& i_rQuery
) override
;
317 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
318 queryConstruct(const OUString
& i_rQuery
) override
;
319 virtual sal_Bool SAL_CALL
queryAsk(const OUString
& i_rQuery
) override
;
321 // css::rdf::XDocumentRepository:
322 virtual void SAL_CALL
setStatementRDFa(
323 const uno::Reference
< rdf::XResource
> & i_xSubject
,
324 const uno::Sequence
< uno::Reference
< rdf::XURI
> > & i_rPredicates
,
325 const uno::Reference
< rdf::XMetadatable
> & i_xObject
,
326 const OUString
& i_rRDFaContent
,
327 const uno::Reference
< rdf::XURI
> & i_xRDFaDatatype
) override
;
328 virtual void SAL_CALL
removeStatementRDFa(
329 const uno::Reference
< rdf::XMetadatable
> & i_xElement
) override
;
330 virtual beans::Pair
< uno::Sequence
<rdf::Statement
>, sal_Bool
> SAL_CALL
331 getStatementRDFa(uno::Reference
< rdf::XMetadatable
> const& i_xElement
) override
;
332 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
334 const uno::Reference
< rdf::XResource
> & i_xSubject
,
335 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
336 const uno::Reference
< rdf::XNode
> & i_xObject
) override
;
338 // css::lang::XInitialization:
339 virtual void SAL_CALL
initialize(
340 const uno::Sequence
< css::uno::Any
> & i_rArguments
) override
;
342 // XNamedGraph forwards ---------------------------------------------
343 NamedGraphMap_t::iterator
clearGraph_NoLock(
344 const OUString
& i_rGraphName
,
345 bool i_Internal
= false );
346 NamedGraphMap_t::iterator
clearGraph_Lock(
347 const OUString
& i_rGraphName
,
349 void addStatementGraph_NoLock(
350 const uno::Reference
< rdf::XResource
> & i_xSubject
,
351 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
352 const uno::Reference
< rdf::XNode
> & i_xObject
,
353 const uno::Reference
< rdf::XURI
> & i_xName
);
354 // throw (uno::RuntimeException, lang::IllegalArgumentException,
355 // container::NoSuchElementException, rdf::RepositoryException);
356 void addStatementGraph_Lock(
357 librdf_TypeConverter::Statement
const& i_rStatement
,
358 OUString
const& i_rGraphName
,
360 void removeStatementsGraph_NoLock(
361 const uno::Reference
< rdf::XResource
> & i_xSubject
,
362 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
363 const uno::Reference
< rdf::XNode
> & i_xObject
,
364 const uno::Reference
< rdf::XURI
> & i_xName
);
365 // throw (uno::RuntimeException, lang::IllegalArgumentException,
366 // container::NoSuchElementException, rdf::RepositoryException);
367 std::vector
<rdf::Statement
> getStatementsGraph_NoLock(
368 const uno::Reference
< rdf::XResource
> & i_xSubject
,
369 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
370 const uno::Reference
< rdf::XNode
> & i_xObject
,
371 const uno::Reference
< rdf::XURI
> & i_xName
,
372 bool i_Internal
= false );
373 // throw (uno::RuntimeException, lang::IllegalArgumentException,
374 // container::NoSuchElementException, rdf::RepositoryException);
376 const librdf_TypeConverter
& getTypeConverter() const { return m_TypeConverter
; };
380 librdf_Repository(librdf_Repository
const&) = delete;
381 librdf_Repository
& operator=(librdf_Repository
const&) = delete;
383 /// this is const, no need to lock m_aMutex to access it
384 uno::Reference
< uno::XComponentContext
> const m_xContext
;
386 /// librdf global data
387 /** N.B.: The redland documentation gives the impression that you can have
388 as many librdf_worlds as you like. This is true in the same sense
389 that you can physically be in as many places as you like.
390 Well, you can, just not at the same time.
391 The ugly truth is that destroying a librdf_world kills a bunch
392 of static variables; other librdf_worlds become very unhappy
393 when they access these.
394 And of course this is not documented anywhere that I could find.
395 So we allocate a single world, and refcount that.
397 static std::shared_ptr
<librdf_world
> m_pWorld
;
399 static sal_uInt32 m_NumInstances
;
400 /// mutex for m_pWorld - redland is not as threadsafe as is often claimed
401 static osl::Mutex m_aMutex
;
403 // NB: sequence of the shared pointers is important!
404 /// librdf repository storage
405 std::shared_ptr
<librdf_storage
> m_pStorage
;
406 /// librdf repository model
407 std::shared_ptr
<librdf_model
> m_pModel
;
410 NamedGraphMap_t m_NamedGraphs
;
412 /// type conversion helper - stateless
413 librdf_TypeConverter m_TypeConverter
;
415 /// set of xml:ids of elements with xhtml:content
416 ::std::set
< OUString
> m_RDFaXHTMLContentSet
;
420 /** result of operations that return a graph, i.e.,
421 an XEnumeration of statements.
423 class librdf_GraphResult
:
424 public ::cppu::WeakImplHelper
<
425 container::XEnumeration
>
429 librdf_GraphResult(librdf_Repository
*i_pRepository
,
430 ::osl::Mutex
& i_rMutex
,
431 std::shared_ptr
<librdf_stream
> const& i_pStream
,
432 std::shared_ptr
<librdf_node
> const& i_pContext
,
433 std::shared_ptr
<librdf_query
> const& i_pQuery
=
434 std::shared_ptr
<librdf_query
>() )
435 : m_xRep(i_pRepository
)
438 , m_pContext(i_pContext
)
439 , m_pStream(i_pStream
)
442 virtual ~librdf_GraphResult() override
444 ::osl::MutexGuard
g(m_rMutex
); // lock mutex when destroying members
445 const_cast<std::shared_ptr
<librdf_stream
>& >(m_pStream
).reset();
446 const_cast<std::shared_ptr
<librdf_node
>& >(m_pContext
).reset();
447 const_cast<std::shared_ptr
<librdf_query
>& >(m_pQuery
).reset();
450 // css::container::XEnumeration:
451 virtual sal_Bool SAL_CALL
hasMoreElements() override
;
452 virtual uno::Any SAL_CALL
nextElement() override
;
456 librdf_GraphResult(librdf_GraphResult
const&) = delete;
457 librdf_GraphResult
& operator=(librdf_GraphResult
const&) = delete;
459 // NB: this is not a weak pointer: streams _must_ be deleted before the
460 // storage they point into, so we keep the repository alive here
461 // also, sequence is important: the stream must be destroyed first.
462 ::rtl::Reference
< librdf_Repository
> m_xRep
;
463 // needed for synchronizing access to librdf (it doesn't do win32 threading)
464 ::osl::Mutex
& m_rMutex
;
465 // the query (in case this is a result of a graph query)
466 // not that the redland documentation spells this out explicitly, but
467 // queries must be freed only after all the results are completely read
468 std::shared_ptr
<librdf_query
> const m_pQuery
;
469 std::shared_ptr
<librdf_node
> const m_pContext
;
470 std::shared_ptr
<librdf_stream
> const m_pStream
;
472 librdf_node
* getContext_Lock() const;
476 // css::container::XEnumeration:
478 librdf_GraphResult::hasMoreElements()
480 ::osl::MutexGuard
g(m_rMutex
);
481 return m_pStream
&& !librdf_stream_end(m_pStream
.get());
484 librdf_node
* librdf_GraphResult::getContext_Lock() const
486 if (!m_pStream
|| librdf_stream_end(m_pStream
.get()))
489 #if LIBRDF_VERSION >= 10012
490 librdf_stream_get_context2(m_pStream
.get()) );
492 static_cast<librdf_node
*>(librdf_stream_get_context(m_pStream
.get())) );
496 return m_pContext
.get();
499 css::uno::Any SAL_CALL
500 librdf_GraphResult::nextElement()
502 ::osl::MutexGuard
g(m_rMutex
);
503 if (m_pStream
&& librdf_stream_end(m_pStream
.get())) {
504 throw container::NoSuchElementException();
506 librdf_node
* pCtxt
= getContext_Lock();
508 librdf_statement
*pStmt( librdf_stream_get_object(m_pStream
.get()) );
510 rdf::QueryException
e(
511 "librdf_GraphResult::nextElement: "
512 "librdf_stream_get_object failed", *this);
513 throw lang::WrappedTargetException(
514 "librdf_GraphResult::nextElement: "
515 "librdf_stream_get_object failed", *this,
518 // NB: pCtxt may be null here if this is result of a graph query
519 if (pCtxt
&& isInternalContext(pCtxt
)) {
520 pCtxt
= nullptr; // XML ID context is implementation detail!
523 m_xRep
->getTypeConverter().convertToStatement(pStmt
, pCtxt
) );
524 // NB: this will invalidate current item.
525 librdf_stream_next(m_pStream
.get());
526 return uno::makeAny(Stmt
);
530 /** result of operations that return a graph, i.e.,
531 an XEnumeration of statements.
533 class librdf_GraphResult2
:
534 public ::cppu::WeakImplHelper
<
535 container::XEnumeration
>
539 librdf_GraphResult2(std::vector
<rdf::Statement
> statements
)
540 : m_vStatements(std::move(statements
))
543 // css::container::XEnumeration:
544 virtual sal_Bool SAL_CALL
hasMoreElements() override
;
545 virtual uno::Any SAL_CALL
nextElement() override
;
549 std::vector
<rdf::Statement
> m_vStatements
;
550 std::atomic
<std::size_t> m_nIndex
= 0;
554 // css::container::XEnumeration:
556 librdf_GraphResult2::hasMoreElements()
558 return m_nIndex
< m_vStatements
.size();
561 css::uno::Any SAL_CALL
562 librdf_GraphResult2::nextElement()
564 std::size_t const n
= m_nIndex
++;
565 if (m_vStatements
.size() <= n
)
567 m_nIndex
= m_vStatements
.size(); // avoid overflow
568 throw container::NoSuchElementException();
570 return uno::makeAny(m_vStatements
[n
]);
573 /** result of tuple queries ("SELECT").
575 class librdf_QuerySelectResult
:
576 public ::cppu::WeakImplHelper
<
577 rdf::XQuerySelectResult
>
581 librdf_QuerySelectResult(librdf_Repository
*i_pRepository
,
582 ::osl::Mutex
& i_rMutex
,
583 std::shared_ptr
<librdf_query
> const& i_pQuery
,
584 std::shared_ptr
<librdf_query_results
> const& i_pQueryResult
,
585 uno::Sequence
< OUString
> const& i_rBindingNames
)
586 : m_xRep(i_pRepository
)
589 , m_pQueryResult(i_pQueryResult
)
590 , m_BindingNames(i_rBindingNames
)
593 virtual ~librdf_QuerySelectResult() override
595 ::osl::MutexGuard
g(m_rMutex
); // lock mutex when destroying members
596 const_cast<std::shared_ptr
<librdf_query_results
>& >(m_pQueryResult
)
598 const_cast<std::shared_ptr
<librdf_query
>& >(m_pQuery
).reset();
601 // css::container::XEnumeration:
602 virtual sal_Bool SAL_CALL
hasMoreElements() override
;
603 virtual uno::Any SAL_CALL
nextElement() override
;
605 // css::rdf::XQuerySelectResult:
606 virtual uno::Sequence
< OUString
> SAL_CALL
getBindingNames() override
;
610 librdf_QuerySelectResult(librdf_QuerySelectResult
const&) = delete;
611 librdf_QuerySelectResult
& operator=(librdf_QuerySelectResult
const&) = delete;
613 // NB: this is not a weak pointer: streams _must_ be deleted before the
614 // storage they point into, so we keep the repository alive here
615 // also, sequence is important: the stream must be destroyed first.
616 ::rtl::Reference
< librdf_Repository
> m_xRep
;
617 // needed for synchronizing access to librdf (it doesn't do win32 threading)
618 ::osl::Mutex
& m_rMutex
;
619 // not that the redland documentation spells this out explicitly, but
620 // queries must be freed only after all the results are completely read
621 std::shared_ptr
<librdf_query
> const m_pQuery
;
622 std::shared_ptr
<librdf_query_results
> const m_pQueryResult
;
623 uno::Sequence
< OUString
> const m_BindingNames
;
627 // css::container::XEnumeration:
629 librdf_QuerySelectResult::hasMoreElements()
631 ::osl::MutexGuard
g(m_rMutex
);
632 return !librdf_query_results_finished(m_pQueryResult
.get());
635 class NodeArray
: private std::vector
<librdf_node
*>
638 NodeArray(int cnt
) : std::vector
<librdf_node
*>(cnt
) {}
640 ~NodeArray() throw ()
642 std::for_each(begin(), end(), safe_librdf_free_node
);
645 using std::vector
<librdf_node
*>::data
;
646 using std::vector
<librdf_node
*>::operator[];
649 css::uno::Any SAL_CALL
650 librdf_QuerySelectResult::nextElement()
652 ::osl::MutexGuard
g(m_rMutex
);
653 if (librdf_query_results_finished(m_pQueryResult
.get())) {
654 throw container::NoSuchElementException();
656 sal_Int32
count(m_BindingNames
.getLength());
657 OSL_ENSURE(count
>= 0, "negative length?");
658 NodeArray
aNodes(count
);
659 if (librdf_query_results_get_bindings(m_pQueryResult
.get(), nullptr,
662 rdf::QueryException
e(
663 "librdf_QuerySelectResult::nextElement: "
664 "librdf_query_results_get_bindings failed", *this);
665 throw lang::WrappedTargetException(
666 "librdf_QuerySelectResult::nextElement: "
667 "librdf_query_results_get_bindings failed", *this,
670 uno::Sequence
< uno::Reference
< rdf::XNode
> > ret(count
);
671 for (int i
= 0; i
< count
; ++i
) {
672 ret
[i
] = m_xRep
->getTypeConverter().convertToXNode(aNodes
[i
]);
674 // NB: this will invalidate current item.
675 librdf_query_results_next(m_pQueryResult
.get());
676 return uno::makeAny(ret
);
679 // css::rdf::XQuerySelectResult:
680 uno::Sequence
< OUString
> SAL_CALL
681 librdf_QuerySelectResult::getBindingNames()
683 // const - no lock needed
684 return m_BindingNames
;
688 /** represents a named graph, and forwards all the work to repository.
690 class librdf_NamedGraph
:
691 public ::cppu::WeakImplHelper
<
695 librdf_NamedGraph(librdf_Repository
* i_pRep
,
696 uno::Reference
<rdf::XURI
> const & i_xName
)
703 virtual OUString SAL_CALL
getStringValue() override
;
706 virtual OUString SAL_CALL
getNamespace() override
;
707 virtual OUString SAL_CALL
getLocalName() override
;
709 // css::rdf::XNamedGraph:
710 virtual uno::Reference
<rdf::XURI
> SAL_CALL
getName() override
;
711 virtual void SAL_CALL
clear() override
;
712 virtual void SAL_CALL
addStatement(
713 const uno::Reference
< rdf::XResource
> & i_xSubject
,
714 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
715 const uno::Reference
< rdf::XNode
> & i_xObject
) override
;
716 virtual void SAL_CALL
removeStatements(
717 const uno::Reference
< rdf::XResource
> & i_xSubject
,
718 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
719 const uno::Reference
< rdf::XNode
> & i_xObject
) override
;
720 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
getStatements(
721 const uno::Reference
< rdf::XResource
> & i_xSubject
,
722 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
723 const uno::Reference
< rdf::XNode
> & i_xObject
) override
;
727 librdf_NamedGraph(librdf_NamedGraph
const&) = delete;
728 librdf_NamedGraph
& operator=(librdf_NamedGraph
const&) = delete;
730 static OUString
createCacheKey_NoLock(
731 const uno::Reference
< rdf::XResource
> & i_xSubject
,
732 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
733 const uno::Reference
< rdf::XNode
> & i_xObject
);
735 /// weak reference: this is needed to check if m_pRep is valid
736 uno::WeakReference
< rdf::XRepository
> const m_wRep
;
737 librdf_Repository
*const m_pRep
;
738 uno::Reference
< rdf::XURI
> const m_xName
;
740 /// Querying is rather slow, so cache the results.
741 std::map
<OUString
, std::vector
<rdf::Statement
>> m_aStatementsCache
;
742 ::osl::Mutex m_CacheMutex
;
747 OUString SAL_CALL
librdf_NamedGraph::getStringValue()
749 return m_xName
->getStringValue();
753 OUString SAL_CALL
librdf_NamedGraph::getNamespace()
755 return m_xName
->getNamespace();
758 OUString SAL_CALL
librdf_NamedGraph::getLocalName()
760 return m_xName
->getLocalName();
763 // css::rdf::XNamedGraph:
764 uno::Reference
< rdf::XURI
> SAL_CALL
librdf_NamedGraph::getName()
769 void SAL_CALL
librdf_NamedGraph::clear()
771 uno::Reference
< rdf::XRepository
> xRep( m_wRep
);
773 throw rdf::RepositoryException(
774 "librdf_NamedGraph::clear: repository is gone", *this);
776 const OUString
contextU( m_xName
->getStringValue() );
778 m_pRep
->clearGraph_NoLock(contextU
);
779 } catch (lang::IllegalArgumentException
& ex
) {
780 css::uno::Any anyEx
= cppu::getCaughtException();
781 throw lang::WrappedTargetRuntimeException( ex
.Message
,
784 ::osl::MutexGuard
g(m_CacheMutex
);
785 m_aStatementsCache
.clear();
788 void SAL_CALL
librdf_NamedGraph::addStatement(
789 const uno::Reference
< rdf::XResource
> & i_xSubject
,
790 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
791 const uno::Reference
< rdf::XNode
> & i_xObject
)
793 uno::Reference
< rdf::XRepository
> xRep( m_wRep
);
795 throw rdf::RepositoryException(
796 "librdf_NamedGraph::addStatement: repository is gone", *this);
799 ::osl::MutexGuard
g(m_CacheMutex
);
800 m_aStatementsCache
.clear();
802 m_pRep
->addStatementGraph_NoLock(
803 i_xSubject
, i_xPredicate
, i_xObject
, m_xName
);
806 void SAL_CALL
librdf_NamedGraph::removeStatements(
807 const uno::Reference
< rdf::XResource
> & i_xSubject
,
808 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
809 const uno::Reference
< rdf::XNode
> & i_xObject
)
811 uno::Reference
< rdf::XRepository
> xRep( m_wRep
);
813 throw rdf::RepositoryException(
814 "librdf_NamedGraph::removeStatements: repository is gone", *this);
817 ::osl::MutexGuard
g(m_CacheMutex
);
818 m_aStatementsCache
.clear();
820 m_pRep
->removeStatementsGraph_NoLock(
821 i_xSubject
, i_xPredicate
, i_xObject
, m_xName
);
824 OUString
librdf_NamedGraph::createCacheKey_NoLock(
825 const uno::Reference
< rdf::XResource
> & i_xSubject
,
826 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
827 const uno::Reference
< rdf::XNode
> & i_xObject
)
829 OUStringBuffer
cacheKey(256);
830 librdf_TypeConverter::extractResourceToCacheKey_NoLock(i_xSubject
, cacheKey
);
831 cacheKey
.append("\t");
832 librdf_TypeConverter::extractResourceToCacheKey_NoLock(i_xPredicate
, cacheKey
);
833 cacheKey
.append("\t");
834 librdf_TypeConverter::extractNodeToCacheKey_NoLock(i_xObject
, cacheKey
);
835 return cacheKey
.makeStringAndClear();
838 uno::Reference
< container::XEnumeration
> SAL_CALL
839 librdf_NamedGraph::getStatements(
840 const uno::Reference
< rdf::XResource
> & i_xSubject
,
841 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
842 const uno::Reference
< rdf::XNode
> & i_xObject
)
844 OUString cacheKey
= createCacheKey_NoLock(i_xSubject
, i_xPredicate
, i_xObject
);
846 ::osl::MutexGuard
g(m_CacheMutex
);
847 auto it
= m_aStatementsCache
.find(cacheKey
);
848 if (it
!= m_aStatementsCache
.end()) {
849 return new librdf_GraphResult2(it
->second
);
853 uno::Reference
< rdf::XRepository
> xRep( m_wRep
);
855 throw rdf::RepositoryException(
856 "librdf_NamedGraph::getStatements: repository is gone", *this);
858 std::vector
<rdf::Statement
> vStatements
= m_pRep
->getStatementsGraph_NoLock(
859 i_xSubject
, i_xPredicate
, i_xObject
, m_xName
);
862 ::osl::MutexGuard
g(m_CacheMutex
);
863 m_aStatementsCache
.emplace(cacheKey
, vStatements
);
865 return new librdf_GraphResult2(vStatements
);
869 std::shared_ptr
<librdf_world
> librdf_Repository::m_pWorld
;
870 sal_uInt32
librdf_Repository::m_NumInstances
= 0;
871 osl::Mutex
librdf_Repository::m_aMutex
;
873 librdf_Repository::librdf_Repository(
874 uno::Reference
< uno::XComponentContext
> const & i_xContext
)
875 : /*BaseMutex(),*/ m_xContext(i_xContext
)
876 // m_pWorld (static_cast<librdf_world *>(0), safe_librdf_free_world ),
877 , m_pStorage(static_cast<librdf_storage
*>(nullptr), safe_librdf_free_storage
)
878 , m_pModel (static_cast<librdf_model
*>(nullptr), safe_librdf_free_model
)
880 , m_TypeConverter(i_xContext
, *this)
882 OSL_ENSURE(i_xContext
.is(), "librdf_Repository: null context");
884 ::osl::MutexGuard
g(m_aMutex
);
885 if (!m_NumInstances
++) {
886 m_pWorld
.reset(m_TypeConverter
.createWorld_Lock(),
887 safe_librdf_free_world
);
891 librdf_Repository::~librdf_Repository()
893 ::osl::MutexGuard
g(m_aMutex
);
895 // must destroy these before world!
899 // FIXME: so it turns out that calling librdf_free_world will
900 // (via raptor_sax2_finish) call xmlCleanupParser, which will
901 // free libxml2's globals! ARRRGH!!! => never call librdf_free_world
903 if (!--m_NumInstances
) {
909 // com.sun.star.uno.XServiceInfo:
910 OUString SAL_CALL
librdf_Repository::getImplementationName()
912 return "librdf_Repository";
915 sal_Bool SAL_CALL
librdf_Repository::supportsService(
916 OUString
const & serviceName
)
918 return cppu::supportsService(this, serviceName
);
921 uno::Sequence
< OUString
> SAL_CALL
922 librdf_Repository::getSupportedServiceNames()
924 return { "com.sun.star.rdf.Repository" };
927 // css::rdf::XRepository:
928 uno::Reference
< rdf::XBlankNode
> SAL_CALL
librdf_Repository::createBlankNode()
930 ::osl::MutexGuard
g(m_aMutex
);
931 const std::shared_ptr
<librdf_node
> pNode(
932 librdf_new_node_from_blank_identifier(m_pWorld
.get(), nullptr),
933 safe_librdf_free_node
);
935 throw uno::RuntimeException(
936 "librdf_Repository::createBlankNode: "
937 "librdf_new_node_from_blank_identifier failed", *this);
939 const unsigned char * id (librdf_node_get_blank_identifier(pNode
.get()));
941 throw uno::RuntimeException(
942 "librdf_Repository::createBlankNode: "
943 "librdf_node_get_blank_identifier failed", *this);
945 const OUString
nodeID(OUString::createFromAscii(
946 reinterpret_cast<const char *>(id
)));
948 return rdf::BlankNode::create(m_xContext
, nodeID
);
949 } catch (const lang::IllegalArgumentException
&) {
950 css::uno::Any anyEx
= cppu::getCaughtException();
951 throw lang::WrappedTargetRuntimeException(
952 "librdf_Repository::createBlankNode: "
953 "illegal blank node label", *this, anyEx
);
958 uno::Reference
<rdf::XNamedGraph
> SAL_CALL
959 librdf_Repository::importGraph(::sal_Int16 i_Format
,
960 const uno::Reference
< io::XInputStream
> & i_xInStream
,
961 const uno::Reference
< rdf::XURI
> & i_xGraphName
,
962 const uno::Reference
< rdf::XURI
> & i_xBaseURI
)
964 if (!i_xInStream
.is()) {
965 throw lang::IllegalArgumentException(
966 "librdf_Repository::importGraph: stream is null", *this, 1);
968 //FIXME: other formats
969 if (i_Format
!= rdf::FileFormat::RDF_XML
) {
970 throw datatransfer::UnsupportedFlavorException(
971 "librdf_Repository::importGraph: file format not supported", *this);
973 if (!i_xGraphName
.is()) {
974 throw lang::IllegalArgumentException(
975 "librdf_Repository::importGraph: graph name is null", *this, 2);
977 if (i_xGraphName
->getStringValue().startsWith(s_nsOOo
))
979 throw lang::IllegalArgumentException(
980 "librdf_Repository::importGraph: URI is reserved", *this, 0);
982 if (!i_xBaseURI
.is()) { //FIXME: any i_Format that don't need a base URI?
983 throw lang::IllegalArgumentException(
984 "librdf_Repository::importGraph: base URI is null", *this, 3);
986 OSL_ENSURE(i_xBaseURI
.is(), "no base uri");
987 const OUString
baseURIU( i_xBaseURI
->getStringValue() );
988 if (baseURIU
.indexOf('#') >= 0) {
989 throw lang::IllegalArgumentException(
990 "librdf_Repository::importGraph: base URI is not absolute", *this, 3);
993 const OUString
contextU( i_xGraphName
->getStringValue() );
995 uno::Sequence
<sal_Int8
> buf
;
996 uno::Reference
<io::XSeekable
> xSeekable(i_xInStream
, uno::UNO_QUERY
);
997 // UGLY: if only redland could read streams...
998 const sal_Int64
sz( xSeekable
.is() ? xSeekable
->getLength() : 1 << 20 );
999 // exceptions are propagated
1000 i_xInStream
->readBytes( buf
, static_cast<sal_Int32
>( sz
) );
1002 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1004 if (m_NamedGraphs
.find(contextU
) != m_NamedGraphs
.end()) {
1005 throw container::ElementExistException(
1006 "librdf_Repository::importGraph: graph with given URI exists", *this);
1008 const OString
context(
1009 OUStringToOString(contextU
, RTL_TEXTENCODING_UTF8
) );
1011 const std::shared_ptr
<librdf_node
> pContext(
1012 librdf_new_node_from_uri_string(m_pWorld
.get(),
1013 reinterpret_cast<const unsigned char*> (context
.getStr())),
1014 safe_librdf_free_node
);
1016 throw uno::RuntimeException(
1017 "librdf_Repository::importGraph: librdf_new_node_from_uri_string failed", *this);
1020 const OString
baseURI(
1021 OUStringToOString(baseURIU
, RTL_TEXTENCODING_UTF8
) );
1022 const std::shared_ptr
<librdf_uri
> pBaseURI(
1023 librdf_new_uri(m_pWorld
.get(),
1024 reinterpret_cast<const unsigned char*> (baseURI
.getStr())),
1025 safe_librdf_free_uri
);
1027 throw uno::RuntimeException( "librdf_Repository::importGraph: librdf_new_uri failed", *this);
1030 const std::shared_ptr
<librdf_parser
> pParser(
1031 librdf_new_parser(m_pWorld
.get(), "rdfxml", nullptr, nullptr),
1032 safe_librdf_free_parser
);
1034 throw uno::RuntimeException(
1035 "librdf_Repository::importGraph: "
1036 "librdf_new_parser failed", *this);
1039 const std::shared_ptr
<librdf_stream
> pStream(
1040 librdf_parser_parse_counted_string_as_stream(pParser
.get(),
1041 reinterpret_cast<const unsigned char*>(buf
.getConstArray()),
1042 buf
.getLength(), pBaseURI
.get()),
1043 safe_librdf_free_stream
);
1045 throw rdf::ParseException(
1046 "librdf_Repository::importGraph: "
1047 "librdf_parser_parse_counted_string_as_stream failed", *this);
1049 rtl::Reference
<librdf_NamedGraph
> const pGraph(
1050 new librdf_NamedGraph(this, i_xGraphName
));
1051 m_NamedGraphs
.insert(std::make_pair(contextU
, pGraph
));
1052 if (librdf_model_context_add_statements(m_pModel
.get(),
1053 pContext
.get(), pStream
.get())) {
1054 throw rdf::RepositoryException(
1055 "librdf_Repository::importGraph: "
1056 "librdf_model_context_add_statements failed", *this);
1059 return uno::Reference
<rdf::XNamedGraph
>(pGraph
.get());
1062 void addChaffWhenEncryptedStorage(const uno::Reference
< io::XOutputStream
> &rStream
, unsigned char* pBuffer
, size_t length
)
1067 uno::Reference
< embed::XEncryptionProtectedSource2
> xEncr(rStream
,
1070 bool bAddChaff
= xEncr
.is() && xEncr
->hasEncryptionData();
1072 // exceptions are propagated
1075 const uno::Sequence
<sal_Int8
> buf(
1076 reinterpret_cast<sal_Int8
*>(pBuffer
), length
);
1077 rStream
->writeBytes(buf
);
1081 unsigned char *postcomment
=
1082 reinterpret_cast<unsigned char*>(strchr(reinterpret_cast<char*>(pBuffer
), '\n'));
1083 if (postcomment
!= nullptr)
1087 size_t preamblelen
= postcomment
- pBuffer
;
1089 uno::Sequence
<sal_Int8
> buf(
1090 reinterpret_cast<sal_Int8
*>(pBuffer
), preamblelen
);
1091 rStream
->writeBytes(buf
);
1093 OStringBuffer aComment
;
1094 aComment
.append("<!--");
1095 aComment
.append(comphelper::xml::makeXMLChaff());
1096 aComment
.append("-->");
1098 buf
= uno::Sequence
<sal_Int8
>(
1099 reinterpret_cast<const sal_Int8
*>(aComment
.getStr()), aComment
.getLength());
1100 rStream
->writeBytes(buf
);
1102 buf
= uno::Sequence
<sal_Int8
>(
1103 reinterpret_cast<sal_Int8
*>(postcomment
), length
-preamblelen
);
1104 rStream
->writeBytes(buf
);
1110 librdf_Repository::exportGraph(::sal_Int16 i_Format
,
1111 const uno::Reference
< io::XOutputStream
> & i_xOutStream
,
1112 const uno::Reference
< rdf::XURI
> & i_xGraphName
,
1113 const uno::Reference
< rdf::XURI
> & i_xBaseURI
)
1115 if (!i_xOutStream
.is()) {
1116 throw lang::IllegalArgumentException(
1117 "librdf_Repository::exportGraph: stream is null", *this, 1);
1119 // FIXME: other formats
1120 if (i_Format
!= rdf::FileFormat::RDF_XML
) {
1121 throw datatransfer::UnsupportedFlavorException(
1122 "librdf_Repository::exportGraph: "
1123 "file format not supported", *this);
1125 if (!i_xGraphName
.is()) {
1126 throw lang::IllegalArgumentException(
1127 "librdf_Repository::exportGraph: "
1128 "graph name is null", *this, 2);
1130 if (!i_xBaseURI
.is()) { //FIXME: any i_Format that don't need a base URI?
1131 throw lang::IllegalArgumentException(
1132 "librdf_Repository::exportGraph: "
1133 "base URI is null", *this, 3);
1135 OSL_ENSURE(i_xBaseURI
.is(), "no base uri");
1136 const OUString
baseURIU( i_xBaseURI
->getStringValue() );
1137 if (baseURIU
.indexOf('#') >= 0) {
1138 throw lang::IllegalArgumentException(
1139 "librdf_Repository::exportGraph: "
1140 "base URI is not absolute", *this, 3);
1143 const OUString
contextU( i_xGraphName
->getStringValue() );
1145 ::osl::ClearableMutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1147 if (m_NamedGraphs
.find(contextU
) == m_NamedGraphs
.end()) {
1148 throw container::NoSuchElementException(
1149 "librdf_Repository::exportGraph: "
1150 "no graph with given URI exists", *this);
1152 const OString
context(
1153 OUStringToOString(contextU
, RTL_TEXTENCODING_UTF8
) );
1155 const std::shared_ptr
<librdf_node
> pContext(
1156 librdf_new_node_from_uri_string(m_pWorld
.get(),
1157 reinterpret_cast<const unsigned char*> (context
.getStr())),
1158 safe_librdf_free_node
);
1160 throw uno::RuntimeException(
1161 "librdf_Repository::exportGraph: "
1162 "librdf_new_node_from_uri_string failed", *this);
1164 const OString
baseURI(
1165 OUStringToOString(baseURIU
, RTL_TEXTENCODING_UTF8
) );
1166 const std::shared_ptr
<librdf_uri
> pBaseURI(
1167 librdf_new_uri(m_pWorld
.get(),
1168 reinterpret_cast<const unsigned char*> (baseURI
.getStr())),
1169 safe_librdf_free_uri
);
1171 throw uno::RuntimeException(
1172 "librdf_Repository::exportGraph: "
1173 "librdf_new_uri failed", *this);
1176 const std::shared_ptr
<librdf_stream
> pStream(
1177 librdf_model_context_as_stream(m_pModel
.get(), pContext
.get()),
1178 safe_librdf_free_stream
);
1180 throw rdf::RepositoryException(
1181 "librdf_Repository::exportGraph: "
1182 "librdf_model_context_as_stream failed", *this);
1184 const char * const format("rdfxml");
1185 // #i116443#: abbrev breaks when certain URIs are used as data types
1186 // const char *format("rdfxml-abbrev");
1187 const std::shared_ptr
<librdf_serializer
> pSerializer(
1188 librdf_new_serializer(m_pWorld
.get(), format
, nullptr, nullptr),
1189 safe_librdf_free_serializer
);
1191 throw uno::RuntimeException(
1192 "librdf_Repository::exportGraph: "
1193 "librdf_new_serializer failed", *this);
1196 const std::shared_ptr
<librdf_uri
> pRelativeURI(
1197 librdf_new_uri(m_pWorld
.get(), reinterpret_cast<const unsigned char*>
1198 ("http://feature.librdf.org/raptor-relativeURIs")),
1199 safe_librdf_free_uri
);
1200 const std::shared_ptr
<librdf_uri
> pWriteBaseURI(
1201 librdf_new_uri(m_pWorld
.get(), reinterpret_cast<const unsigned char*>
1202 ("http://feature.librdf.org/raptor-writeBaseURI")),
1203 safe_librdf_free_uri
);
1204 const std::shared_ptr
<librdf_node
> p0(
1205 librdf_new_node_from_literal(m_pWorld
.get(),
1206 reinterpret_cast<const unsigned char*> ("0"), nullptr, 0),
1207 safe_librdf_free_node
);
1208 const std::shared_ptr
<librdf_node
> p1(
1209 librdf_new_node_from_literal(m_pWorld
.get(),
1210 reinterpret_cast<const unsigned char*> ("1"), nullptr, 0),
1211 safe_librdf_free_node
);
1212 if (!pWriteBaseURI
|| !pRelativeURI
|| !p0
|| !p1
) {
1213 throw uno::RuntimeException(
1214 "librdf_Repository::exportGraph: "
1215 "librdf_new_uri or librdf_new_node_from_literal failed", *this);
1218 // make URIs relative to base URI
1219 if (librdf_serializer_set_feature(pSerializer
.get(),
1220 pRelativeURI
.get(), p1
.get()))
1222 throw uno::RuntimeException(
1223 "librdf_Repository::exportGraph: "
1224 "librdf_serializer_set_feature relativeURIs failed", *this);
1226 // but do not write the base URI to the file!
1227 if (librdf_serializer_set_feature(pSerializer
.get(),
1228 pWriteBaseURI
.get(), p0
.get()))
1230 throw uno::RuntimeException(
1231 "librdf_Repository::exportGraph: "
1232 "librdf_serializer_set_feature writeBaseURI failed", *this);
1236 const std::shared_ptr
<unsigned char> pBuf(
1237 librdf_serializer_serialize_stream_to_counted_string(
1238 pSerializer
.get(), pBaseURI
.get(), pStream
.get(), &length
), free
);
1240 throw rdf::RepositoryException(
1241 "librdf_Repository::exportGraph: "
1242 "librdf_serializer_serialize_stream_to_counted_string failed",
1246 g
.clear(); // release Mutex before calling i_xOutStream methods
1248 addChaffWhenEncryptedStorage(i_xOutStream
, pBuf
.get(), length
);
1251 uno::Sequence
< uno::Reference
< rdf::XURI
> > SAL_CALL
1252 librdf_Repository::getGraphNames()
1254 ::osl::MutexGuard
g(m_aMutex
);
1255 ::std::vector
< uno::Reference
<rdf::XURI
> > ret
;
1256 std::transform(m_NamedGraphs
.begin(), m_NamedGraphs
.end(),
1257 std::back_inserter(ret
),
1258 [](std::pair
<OUString
, ::rtl::Reference
<librdf_NamedGraph
>> const& it
)
1259 { return it
.second
->getName(); });
1260 return comphelper::containerToSequence(ret
);
1263 uno::Reference
< rdf::XNamedGraph
> SAL_CALL
1264 librdf_Repository::getGraph(const uno::Reference
< rdf::XURI
> & i_xGraphName
)
1266 if (!i_xGraphName
.is()) {
1267 throw lang::IllegalArgumentException(
1268 "librdf_Repository::getGraph: URI is null", *this, 0);
1270 const OUString
contextU( i_xGraphName
->getStringValue() );
1272 ::osl::MutexGuard
g(m_aMutex
);
1273 const NamedGraphMap_t::iterator
iter( m_NamedGraphs
.find(contextU
) );
1274 if (iter
!= m_NamedGraphs
.end()) {
1275 return uno::Reference
<rdf::XNamedGraph
>(iter
->second
.get());
1281 uno::Reference
< rdf::XNamedGraph
> SAL_CALL
1282 librdf_Repository::createGraph(const uno::Reference
< rdf::XURI
> & i_xGraphName
)
1284 if (!i_xGraphName
.is()) {
1285 throw lang::IllegalArgumentException(
1286 "librdf_Repository::createGraph: URI is null", *this, 0);
1289 const OUString
contextU( i_xGraphName
->getStringValue() );
1290 if (contextU
.startsWith(s_nsOOo
))
1292 throw lang::IllegalArgumentException(
1293 "librdf_Repository::createGraph: URI is reserved", *this, 0);
1296 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1298 // NB: librdf does not have a concept of graphs as such;
1299 // a librdf named graph exists iff the model contains a statement with
1300 // the graph name as context
1302 if (m_NamedGraphs
.find(contextU
) != m_NamedGraphs
.end()) {
1303 throw container::ElementExistException(
1304 "librdf_Repository::createGraph: graph with given URI exists", *this);
1306 m_NamedGraphs
.insert(std::make_pair(contextU
,
1307 new librdf_NamedGraph(this, i_xGraphName
)));
1308 return uno::Reference
<rdf::XNamedGraph
>(
1309 m_NamedGraphs
.find(contextU
)->second
.get());
1313 librdf_Repository::destroyGraph(
1314 const uno::Reference
< rdf::XURI
> & i_xGraphName
)
1316 if (!i_xGraphName
.is()) {
1317 throw lang::IllegalArgumentException(
1318 "librdf_Repository::destroyGraph: URI is null", *this, 0);
1320 const OUString
contextU( i_xGraphName
->getStringValue() );
1322 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1324 const NamedGraphMap_t::iterator
iter( clearGraph_Lock(contextU
, false) );
1325 m_NamedGraphs
.erase(iter
);
1328 bool isMetadatableWithoutMetadata(
1329 uno::Reference
<uno::XInterface
> const & i_xNode
)
1331 const uno::Reference
<rdf::XMetadatable
> xMeta( i_xNode
, uno::UNO_QUERY
);
1332 return (xMeta
.is() && xMeta
->getMetadataReference().Second
.isEmpty());
1335 uno::Reference
< container::XEnumeration
> SAL_CALL
1336 librdf_Repository::getStatements(
1337 const uno::Reference
< rdf::XResource
> & i_xSubject
,
1338 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
1339 const uno::Reference
< rdf::XNode
> & i_xObject
)
1341 if (isMetadatableWithoutMetadata(i_xSubject
) ||
1342 isMetadatableWithoutMetadata(i_xPredicate
) ||
1343 isMetadatableWithoutMetadata(i_xObject
))
1345 return new librdf_GraphResult(this, m_aMutex
,
1346 std::shared_ptr
<librdf_stream
>(),
1347 std::shared_ptr
<librdf_node
>());
1350 librdf_TypeConverter::Statement
const stmt(
1351 librdf_TypeConverter::extractStatement_NoLock(
1352 i_xSubject
, i_xPredicate
, i_xObject
));
1354 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1356 const std::shared_ptr
<librdf_statement
> pStatement(
1357 librdf_TypeConverter::mkStatement_Lock(m_pWorld
.get(), stmt
),
1358 safe_librdf_free_statement
);
1359 OSL_ENSURE(pStatement
, "mkStatement failed");
1361 const std::shared_ptr
<librdf_stream
> pStream(
1362 librdf_model_find_statements(m_pModel
.get(), pStatement
.get()),
1363 safe_librdf_free_stream
);
1365 throw rdf::RepositoryException(
1366 "librdf_Repository::getStatements: "
1367 "librdf_model_find_statements failed", *this);
1370 return new librdf_GraphResult(this, m_aMutex
, pStream
,
1371 std::shared_ptr
<librdf_node
>());
1375 uno::Reference
< rdf::XQuerySelectResult
> SAL_CALL
1376 librdf_Repository::querySelect(const OUString
& i_rQuery
)
1378 ::osl::MutexGuard
g(m_aMutex
);
1379 const OString
query(
1380 OUStringToOString(i_rQuery
, RTL_TEXTENCODING_UTF8
) );
1381 const std::shared_ptr
<librdf_query
> pQuery(
1382 librdf_new_query(m_pWorld
.get(), s_sparql
, nullptr,
1383 reinterpret_cast<const unsigned char*> (query
.getStr()), nullptr),
1384 safe_librdf_free_query
);
1386 throw rdf::QueryException(
1387 "librdf_Repository::querySelect: "
1388 "librdf_new_query failed", *this);
1390 const std::shared_ptr
<librdf_query_results
> pResults(
1391 librdf_model_query_execute(m_pModel
.get(), pQuery
.get()),
1392 safe_librdf_free_query_results
);
1393 if (!pResults
|| !librdf_query_results_is_bindings(pResults
.get())) {
1394 throw rdf::QueryException(
1395 "librdf_Repository::querySelect: "
1396 "query result is null or not bindings", *this);
1399 const int count( librdf_query_results_get_bindings_count(pResults
.get()) );
1401 throw rdf::QueryException(
1402 "librdf_Repository::querySelect: "
1403 "librdf_query_results_get_bindings_count failed", *this);
1405 uno::Sequence
< OUString
> names(count
);
1406 for (int i
= 0; i
< count
; ++i
) {
1407 const char* name( librdf_query_results_get_binding_name(
1408 pResults
.get(), i
) );
1410 throw rdf::QueryException(
1411 "librdf_Repository::querySelect: binding is null", *this);
1414 names
[i
] = OUString::createFromAscii(name
);
1417 return new librdf_QuerySelectResult(this, m_aMutex
,
1418 pQuery
, pResults
, names
);
1421 uno::Reference
< container::XEnumeration
> SAL_CALL
1422 librdf_Repository::queryConstruct(const OUString
& i_rQuery
)
1424 ::osl::MutexGuard
g(m_aMutex
);
1425 const OString
query(
1426 OUStringToOString(i_rQuery
, RTL_TEXTENCODING_UTF8
) );
1427 const std::shared_ptr
<librdf_query
> pQuery(
1428 librdf_new_query(m_pWorld
.get(), s_sparql
, nullptr,
1429 reinterpret_cast<const unsigned char*> (query
.getStr()), nullptr),
1430 safe_librdf_free_query
);
1432 throw rdf::QueryException(
1433 "librdf_Repository::queryConstruct: "
1434 "librdf_new_query failed", *this);
1436 const std::shared_ptr
<librdf_query_results
> pResults(
1437 librdf_model_query_execute(m_pModel
.get(), pQuery
.get()),
1438 safe_librdf_free_query_results
);
1439 if (!pResults
|| !librdf_query_results_is_graph(pResults
.get())) {
1440 throw rdf::QueryException(
1441 "librdf_Repository::queryConstruct: "
1442 "query result is null or not graph", *this);
1444 const std::shared_ptr
<librdf_stream
> pStream(
1445 librdf_query_results_as_stream(pResults
.get()),
1446 safe_librdf_free_stream
);
1448 throw rdf::QueryException(
1449 "librdf_Repository::queryConstruct: "
1450 "librdf_query_results_as_stream failed", *this);
1453 return new librdf_GraphResult(this, m_aMutex
, pStream
,
1454 std::shared_ptr
<librdf_node
>(), pQuery
);
1458 librdf_Repository::queryAsk(const OUString
& i_rQuery
)
1460 ::osl::MutexGuard
g(m_aMutex
);
1462 const OString
query(
1463 OUStringToOString(i_rQuery
, RTL_TEXTENCODING_UTF8
) );
1464 const std::shared_ptr
<librdf_query
> pQuery(
1465 librdf_new_query(m_pWorld
.get(), s_sparql
, nullptr,
1466 reinterpret_cast<const unsigned char*> (query
.getStr()), nullptr),
1467 safe_librdf_free_query
);
1469 throw rdf::QueryException(
1470 "librdf_Repository::queryAsk: "
1471 "librdf_new_query failed", *this);
1473 const std::shared_ptr
<librdf_query_results
> pResults(
1474 librdf_model_query_execute(m_pModel
.get(), pQuery
.get()),
1475 safe_librdf_free_query_results
);
1476 if (!pResults
|| !librdf_query_results_is_boolean(pResults
.get())) {
1477 throw rdf::QueryException(
1478 "librdf_Repository::queryAsk: "
1479 "query result is null or not boolean", *this);
1481 return bool(librdf_query_results_get_boolean(pResults
.get()));
1484 // css::rdf::XDocumentRepository:
1485 void SAL_CALL
librdf_Repository::setStatementRDFa(
1486 const uno::Reference
< rdf::XResource
> & i_xSubject
,
1487 const uno::Sequence
< uno::Reference
< rdf::XURI
> > & i_rPredicates
,
1488 const uno::Reference
< rdf::XMetadatable
> & i_xObject
,
1489 const OUString
& i_rRDFaContent
,
1490 const uno::Reference
< rdf::XURI
> & i_xRDFaDatatype
)
1492 if (!i_xSubject
.is()) {
1493 throw lang::IllegalArgumentException(
1494 "librdf_Repository::setStatementRDFa: Subject is null", *this, 0);
1496 if (!i_rPredicates
.hasElements()) {
1497 throw lang::IllegalArgumentException(
1498 "librdf_Repository::setStatementRDFa: no Predicates",
1501 if (std::any_of(i_rPredicates
.begin(), i_rPredicates
.end(),
1502 [](const uno::Reference
< rdf::XURI
>& rPredicate
) { return !rPredicate
.is(); })) {
1503 throw lang::IllegalArgumentException(
1504 "librdf_Repository::setStatementRDFa: Predicate is null", *this, 1);
1506 if (!i_xObject
.is()) {
1507 throw lang::IllegalArgumentException(
1508 "librdf_Repository::setStatementRDFa: Object is null", *this, 2);
1510 const uno::Reference
<lang::XServiceInfo
> xService(i_xObject
,
1511 uno::UNO_QUERY_THROW
);
1512 uno::Reference
<text::XTextRange
> xTextRange
;
1513 if (xService
->supportsService("com.sun.star.table.Cell") ||
1514 xService
->supportsService("com.sun.star.text.CellProperties") || // for writer
1515 xService
->supportsService("com.sun.star.text.Paragraph"))
1517 xTextRange
.set(i_xObject
, uno::UNO_QUERY_THROW
);
1519 else if (xService
->supportsService("com.sun.star.text.Bookmark") ||
1520 xService
->supportsService("com.sun.star.text.InContentMetadata"))
1522 const uno::Reference
<text::XTextContent
> xTextContent(i_xObject
,
1523 uno::UNO_QUERY_THROW
);
1524 xTextRange
= xTextContent
->getAnchor();
1526 if (!xTextRange
.is()) {
1527 throw lang::IllegalArgumentException(
1528 "librdf_Repository::setStatementRDFa: "
1529 "Object does not support RDFa", *this, 2);
1531 // ensure that the metadatable has an XML ID
1532 i_xObject
->ensureMetadataReference();
1533 const beans::StringPair
mdref( i_xObject
->getMetadataReference() );
1534 if ((mdref
.First
.isEmpty()) || (mdref
.Second
.isEmpty())) {
1535 throw uno::RuntimeException(
1536 "librdf_Repository::setStatementRDFa: "
1537 "ensureMetadataReference did not", *this);
1539 OUString
const sXmlId(mdref
.First
+ "#" + mdref
.Second
);
1540 OUString
const sContext(s_nsOOo
+ sXmlId
);
1541 OUString
const content( (i_rRDFaContent
.isEmpty())
1542 ? xTextRange
->getString()
1544 uno::Reference
<rdf::XNode
> xContent
;
1546 if (i_xRDFaDatatype
.is()) {
1547 xContent
.set(rdf::Literal::createWithType(m_xContext
,
1548 content
, i_xRDFaDatatype
),
1549 uno::UNO_QUERY_THROW
);
1551 xContent
.set(rdf::Literal::create(m_xContext
, content
),
1552 uno::UNO_QUERY_THROW
);
1554 } catch (const lang::IllegalArgumentException
&) {
1555 css::uno::Any anyEx
= cppu::getCaughtException();
1556 throw lang::WrappedTargetRuntimeException(
1557 "librdf_Repository::setStatementRDFa: "
1558 "cannot create literal", *this, anyEx
);
1561 std::shared_ptr
<librdf_TypeConverter::Resource
> const pSubject(
1562 librdf_TypeConverter::extractResource_NoLock(i_xSubject
));
1563 std::shared_ptr
<librdf_TypeConverter::Node
> const pContent(
1564 librdf_TypeConverter::extractNode_NoLock(xContent
));
1565 ::std::vector
< std::shared_ptr
<librdf_TypeConverter::Resource
> >
1567 ::std::transform(i_rPredicates
.begin(), i_rPredicates
.end(),
1568 ::std::back_inserter(predicates
),
1569 [](uno::Reference
<rdf::XURI
> const& xURI
)
1570 { return librdf_TypeConverter::extractResource_NoLock(xURI
); });
1572 removeStatementRDFa(i_xObject
); // not atomic with insertion?
1574 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1576 if (i_rRDFaContent
.isEmpty()) {
1577 m_RDFaXHTMLContentSet
.erase(sXmlId
);
1579 m_RDFaXHTMLContentSet
.insert(sXmlId
);
1583 for (const auto& rPredicatePtr
: predicates
)
1585 addStatementGraph_Lock(
1586 librdf_TypeConverter::Statement(pSubject
,
1587 std::dynamic_pointer_cast
<librdf_TypeConverter::URI
>(rPredicatePtr
),
1592 catch (const container::NoSuchElementException
&)
1594 css::uno::Any anyEx
= cppu::getCaughtException();
1595 throw lang::WrappedTargetRuntimeException(
1596 "librdf_Repository::setStatementRDFa: "
1597 "cannot addStatementGraph", *this, anyEx
);
1601 void SAL_CALL
librdf_Repository::removeStatementRDFa(
1602 const uno::Reference
< rdf::XMetadatable
> & i_xElement
)
1604 if (!i_xElement
.is()) {
1605 throw lang::IllegalArgumentException(
1606 "librdf_Repository::removeStatementRDFa: Element is null",
1610 const beans::StringPair
mdref( i_xElement
->getMetadataReference() );
1611 if ((mdref
.First
.isEmpty()) || (mdref
.Second
.isEmpty())) {
1612 return; // nothing to do...
1615 OUString
const sXmlId(s_nsOOo
+ mdref
.First
+ "#" + mdref
.Second
);
1617 clearGraph_NoLock(sXmlId
, true);
1620 beans::Pair
< uno::Sequence
<rdf::Statement
>, sal_Bool
> SAL_CALL
1621 librdf_Repository::getStatementRDFa(
1622 const uno::Reference
< rdf::XMetadatable
> & i_xElement
)
1624 if (!i_xElement
.is()) {
1625 throw lang::IllegalArgumentException(
1626 "librdf_Repository::getStatementRDFa: Element is null", *this, 0);
1628 const beans::StringPair
mdref( i_xElement
->getMetadataReference() );
1629 if ((mdref
.First
.isEmpty()) || (mdref
.Second
.isEmpty())) {
1630 return beans::Pair
< uno::Sequence
<rdf::Statement
>, sal_Bool
>();
1632 OUString
const sXmlId(mdref
.First
+ "#" + mdref
.Second
);
1633 uno::Reference
<rdf::XURI
> xXmlId
;
1635 xXmlId
.set( rdf::URI::create(m_xContext
, s_nsOOo
+ sXmlId
),
1636 uno::UNO_SET_THROW
);
1637 } catch (const lang::IllegalArgumentException
&) {
1638 css::uno::Any anyEx
= cppu::getCaughtException();
1639 throw lang::WrappedTargetRuntimeException(
1640 "librdf_Repository::getStatementRDFa: "
1641 "cannot create URI for XML ID", *this, anyEx
);
1644 ::std::vector
< rdf::Statement
> ret
;
1647 ret
= getStatementsGraph_NoLock(nullptr, nullptr, nullptr, xXmlId
, true);
1649 catch (const container::NoSuchElementException
&)
1651 css::uno::Any anyEx
= cppu::getCaughtException();
1652 throw lang::WrappedTargetRuntimeException(
1653 "librdf_Repository::getStatementRDFa: "
1654 "cannot getStatementsGraph", *this, anyEx
);
1657 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1659 return beans::Pair
< uno::Sequence
<rdf::Statement
>, sal_Bool
>(
1660 comphelper::containerToSequence(ret
), 0 != m_RDFaXHTMLContentSet
.count(sXmlId
));
1664 librdf_statement
*rdfa_context_stream_map_handler(
1665 librdf_stream
*i_pStream
, void *, librdf_statement
*i_pStatement
)
1667 OSL_ENSURE(i_pStream
, "rdfa_context_stream_map_handler: stream null");
1670 #if LIBRDF_VERSION >= 10012
1671 librdf_stream_get_context2(i_pStream
) );
1673 static_cast<librdf_node
*>(librdf_stream_get_context(i_pStream
)) );
1675 OSL_ENSURE(pCtxt
, "rdfa_context_stream_map_handler: context null");
1676 if (pCtxt
&& isInternalContext(pCtxt
)) {
1677 return i_pStatement
;
1683 uno::Reference
< container::XEnumeration
> SAL_CALL
1684 librdf_Repository::getStatementsRDFa(
1685 const uno::Reference
< rdf::XResource
> & i_xSubject
,
1686 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
1687 const uno::Reference
< rdf::XNode
> & i_xObject
)
1689 if (isMetadatableWithoutMetadata(i_xSubject
) ||
1690 isMetadatableWithoutMetadata(i_xPredicate
) ||
1691 isMetadatableWithoutMetadata(i_xObject
))
1693 return new librdf_GraphResult(this, m_aMutex
,
1694 std::shared_ptr
<librdf_stream
>(),
1695 std::shared_ptr
<librdf_node
>());
1698 librdf_TypeConverter::Statement
const stmt(
1699 librdf_TypeConverter::extractStatement_NoLock(
1700 i_xSubject
, i_xPredicate
, i_xObject
));
1702 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1704 const std::shared_ptr
<librdf_statement
> pStatement(
1705 librdf_TypeConverter::mkStatement_Lock(m_pWorld
.get(), stmt
),
1706 safe_librdf_free_statement
);
1707 OSL_ENSURE(pStatement
, "mkStatement failed");
1709 const std::shared_ptr
<librdf_stream
> pStream(
1710 librdf_model_find_statements(m_pModel
.get(), pStatement
.get()),
1711 safe_librdf_free_stream
);
1713 throw rdf::RepositoryException(
1714 "librdf_Repository::getStatementsRDFa: "
1715 "librdf_model_find_statements failed", *this);
1718 if (librdf_stream_add_map(pStream
.get(), rdfa_context_stream_map_handler
,
1719 nullptr, nullptr)) {
1720 throw rdf::RepositoryException(
1721 "librdf_Repository::getStatementsRDFa: "
1722 "librdf_stream_add_map failed", *this);
1725 return new librdf_GraphResult(this, m_aMutex
, pStream
,
1726 std::shared_ptr
<librdf_node
>());
1729 // css::lang::XInitialization:
1730 void SAL_CALL
librdf_Repository::initialize(
1731 const uno::Sequence
< css::uno::Any
> &)
1733 ::osl::MutexGuard
g(m_aMutex
);
1735 // m_pWorld.reset(m_TypeConverter.createWorld(), safe_librdf_free_world);
1736 m_pStorage
.reset(m_TypeConverter
.createStorage_Lock(m_pWorld
.get()),
1737 safe_librdf_free_storage
);
1738 m_pModel
.reset(m_TypeConverter
.createModel_Lock(
1739 m_pWorld
.get(), m_pStorage
.get()), safe_librdf_free_model
);
1742 NamedGraphMap_t::iterator
librdf_Repository::clearGraph_NoLock(
1743 OUString
const& i_rGraphName
, bool i_Internal
)
1744 // throw (uno::RuntimeException, container::NoSuchElementException,
1745 // rdf::RepositoryException)
1747 ::osl::MutexGuard
g(m_aMutex
);
1749 return clearGraph_Lock(i_rGraphName
, i_Internal
);
1752 NamedGraphMap_t::iterator
librdf_Repository::clearGraph_Lock(
1753 OUString
const& i_rGraphName
, bool i_Internal
)
1755 // internal: must be called with mutex locked!
1756 const NamedGraphMap_t::iterator
iter( m_NamedGraphs
.find(i_rGraphName
) );
1757 if (!i_Internal
&& iter
== m_NamedGraphs
.end()) {
1758 throw container::NoSuchElementException(
1759 "librdf_Repository::clearGraph: "
1760 "no graph with given URI exists", *this);
1762 const OString
context(
1763 OUStringToOString(i_rGraphName
, RTL_TEXTENCODING_UTF8
) );
1765 const std::shared_ptr
<librdf_node
> pContext(
1766 librdf_new_node_from_uri_string(m_pWorld
.get(),
1767 reinterpret_cast<const unsigned char*> (context
.getStr())),
1768 safe_librdf_free_node
);
1770 throw uno::RuntimeException(
1771 "librdf_Repository::clearGraph: "
1772 "librdf_new_node_from_uri_string failed", *this);
1774 if (librdf_model_context_remove_statements(m_pModel
.get(), pContext
.get()))
1776 throw rdf::RepositoryException(
1777 "librdf_Repository::clearGraph: "
1778 "librdf_model_context_remove_statements failed", *this);
1783 void librdf_Repository::addStatementGraph_NoLock(
1784 const uno::Reference
< rdf::XResource
> & i_xSubject
,
1785 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
1786 const uno::Reference
< rdf::XNode
> & i_xObject
,
1787 const uno::Reference
< rdf::XURI
> & i_xGraphName
)
1788 //throw (uno::RuntimeException, lang::IllegalArgumentException,
1789 // container::NoSuchElementException, rdf::RepositoryException)
1791 if (!i_xSubject
.is()) {
1792 throw lang::IllegalArgumentException(
1793 "librdf_Repository::addStatement: Subject is null", *this, 0);
1795 if (!i_xPredicate
.is()) {
1796 throw lang::IllegalArgumentException(
1797 "librdf_Repository::addStatement: Predicate is null",
1800 if (!i_xObject
.is()) {
1801 throw lang::IllegalArgumentException(
1802 "librdf_Repository::addStatement: Object is null", *this, 2);
1805 librdf_TypeConverter::Statement
const stmt(
1806 librdf_TypeConverter::extractStatement_NoLock(
1807 i_xSubject
, i_xPredicate
, i_xObject
));
1809 const OUString
contextU( i_xGraphName
->getStringValue() );
1811 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1813 addStatementGraph_Lock(stmt
, contextU
, false/*i_Internal*/);
1816 void librdf_Repository::addStatementGraph_Lock(
1817 librdf_TypeConverter::Statement
const& i_rStatement
,
1818 OUString
const& i_rGraphName
,
1822 && (m_NamedGraphs
.find(i_rGraphName
) == m_NamedGraphs
.end()))
1824 throw container::NoSuchElementException(
1825 "librdf_Repository::addStatement: "
1826 "no graph with given URI exists", *this);
1828 const OString
context(
1829 OUStringToOString(i_rGraphName
, RTL_TEXTENCODING_UTF8
) );
1831 const std::shared_ptr
<librdf_node
> pContext(
1832 librdf_new_node_from_uri_string(m_pWorld
.get(),
1833 reinterpret_cast<const unsigned char*> (context
.getStr())),
1834 safe_librdf_free_node
);
1836 throw uno::RuntimeException(
1837 "librdf_Repository::addStatement: "
1838 "librdf_new_node_from_uri_string failed", *this);
1840 const std::shared_ptr
<librdf_statement
> pStatement(
1841 librdf_TypeConverter::mkStatement_Lock(m_pWorld
.get(), i_rStatement
),
1842 safe_librdf_free_statement
);
1843 OSL_ENSURE(pStatement
, "mkStatement failed");
1845 // Test for duplicate statement
1846 // librdf_model_add_statement disallows duplicates while
1847 // librdf_model_context_add_statement allows duplicates
1849 const std::shared_ptr
<librdf_stream
> pStream(
1850 librdf_model_find_statements_in_context(m_pModel
.get(),
1851 pStatement
.get(), pContext
.get()),
1852 safe_librdf_free_stream
);
1853 if (pStream
&& !librdf_stream_end(pStream
.get()))
1857 if (librdf_model_context_add_statement(m_pModel
.get(),
1858 pContext
.get(), pStatement
.get())) {
1859 throw rdf::RepositoryException(
1860 "librdf_Repository::addStatement: "
1861 "librdf_model_context_add_statement failed", *this);
1865 void librdf_Repository::removeStatementsGraph_NoLock(
1866 const uno::Reference
< rdf::XResource
> & i_xSubject
,
1867 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
1868 const uno::Reference
< rdf::XNode
> & i_xObject
,
1869 const uno::Reference
< rdf::XURI
> & i_xGraphName
)
1870 //throw (uno::RuntimeException, lang::IllegalArgumentException,
1871 // container::NoSuchElementException, rdf::RepositoryException)
1873 if (isMetadatableWithoutMetadata(i_xSubject
) ||
1874 isMetadatableWithoutMetadata(i_xPredicate
) ||
1875 isMetadatableWithoutMetadata(i_xObject
))
1880 librdf_TypeConverter::Statement
const stmt(
1881 librdf_TypeConverter::extractStatement_NoLock(
1882 i_xSubject
, i_xPredicate
, i_xObject
));
1883 const OUString
contextU( i_xGraphName
->getStringValue() );
1885 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1887 if (m_NamedGraphs
.find(contextU
) == m_NamedGraphs
.end()) {
1888 throw container::NoSuchElementException(
1889 "librdf_Repository::removeStatements: "
1890 "no graph with given URI exists", *this);
1892 const OString
context(
1893 OUStringToOString(contextU
, RTL_TEXTENCODING_UTF8
) );
1895 const std::shared_ptr
<librdf_node
> pContext(
1896 librdf_new_node_from_uri_string(m_pWorld
.get(),
1897 reinterpret_cast<const unsigned char*> (context
.getStr())),
1898 safe_librdf_free_node
);
1900 throw uno::RuntimeException(
1901 "librdf_Repository::removeStatements: "
1902 "librdf_new_node_from_uri_string failed", *this);
1904 const std::shared_ptr
<librdf_statement
> pStatement(
1905 librdf_TypeConverter::mkStatement_Lock(m_pWorld
.get(), stmt
),
1906 safe_librdf_free_statement
);
1907 OSL_ENSURE(pStatement
, "mkStatement failed");
1909 const std::shared_ptr
<librdf_stream
> pStream(
1910 librdf_model_find_statements_in_context(m_pModel
.get(),
1911 pStatement
.get(), pContext
.get()),
1912 safe_librdf_free_stream
);
1914 throw rdf::RepositoryException(
1915 "librdf_Repository::removeStatements: "
1916 "librdf_model_find_statements_in_context failed", *this);
1919 if (librdf_stream_end(pStream
.get()))
1923 librdf_statement
*pStmt( librdf_stream_get_object(pStream
.get()) );
1925 throw rdf::RepositoryException(
1926 "librdf_Repository::removeStatements: "
1927 "librdf_stream_get_object failed", *this);
1929 if (librdf_model_context_remove_statement(m_pModel
.get(),
1930 pContext
.get(), pStmt
)) {
1931 throw rdf::RepositoryException(
1932 "librdf_Repository::removeStatements: "
1933 "librdf_model_context_remove_statement failed", *this);
1935 } while (!librdf_stream_next(pStream
.get()));
1938 std::vector
<rdf::Statement
>
1939 librdf_Repository::getStatementsGraph_NoLock(
1940 const uno::Reference
< rdf::XResource
> & i_xSubject
,
1941 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
1942 const uno::Reference
< rdf::XNode
> & i_xObject
,
1943 const uno::Reference
< rdf::XURI
> & i_xGraphName
,
1945 //throw (uno::RuntimeException, lang::IllegalArgumentException,
1946 // container::NoSuchElementException, rdf::RepositoryException)
1948 std::vector
<rdf::Statement
> ret
;
1950 // N.B.: if any of subject, predicate, object is an XMetadatable, and
1951 // has no metadata reference, then there cannot be any node in the graph
1952 // representing it; in order to prevent side effect
1953 // (ensureMetadataReference), check for this condition and return
1954 if (isMetadatableWithoutMetadata(i_xSubject
) ||
1955 isMetadatableWithoutMetadata(i_xPredicate
) ||
1956 isMetadatableWithoutMetadata(i_xObject
))
1961 librdf_TypeConverter::Statement
const stmt(
1962 librdf_TypeConverter::extractStatement_NoLock(
1963 i_xSubject
, i_xPredicate
, i_xObject
));
1964 const OUString
contextU( i_xGraphName
->getStringValue() );
1966 ::osl::MutexGuard
g(m_aMutex
); // don't call i_x* with mutex locked
1968 if (!i_Internal
&& (m_NamedGraphs
.find(contextU
) == m_NamedGraphs
.end())) {
1969 throw container::NoSuchElementException(
1970 "librdf_Repository::getStatements: "
1971 "no graph with given URI exists", *this);
1973 const OString
context(
1974 OUStringToOString(contextU
, RTL_TEXTENCODING_UTF8
) );
1976 const std::shared_ptr
<librdf_node
> pContext(
1977 librdf_new_node_from_uri_string(m_pWorld
.get(),
1978 reinterpret_cast<const unsigned char*> (context
.getStr())),
1979 safe_librdf_free_node
);
1981 throw uno::RuntimeException(
1982 "librdf_Repository::getStatements: "
1983 "librdf_new_node_from_uri_string failed", *this);
1985 const std::shared_ptr
<librdf_statement
> pStatement(
1986 librdf_TypeConverter::mkStatement_Lock(m_pWorld
.get(), stmt
),
1987 safe_librdf_free_statement
);
1988 OSL_ENSURE(pStatement
, "mkStatement failed");
1990 const std::shared_ptr
<librdf_stream
> pStream(
1991 librdf_model_find_statements_in_context(m_pModel
.get(),
1992 pStatement
.get(), pContext
.get()),
1993 safe_librdf_free_stream
);
1995 throw rdf::RepositoryException(
1996 "librdf_Repository::getStatements: "
1997 "librdf_model_find_statements_in_context failed", *this);
2000 librdf_node
*pCtxt1(
2001 #if LIBRDF_VERSION >= 10012
2002 librdf_stream_get_context2(pStream
.get()) );
2004 static_cast<librdf_node
*>(librdf_stream_get_context(pStream
.get())) );
2006 while (!librdf_stream_end(pStream
.get()))
2008 auto pCtxt
= pCtxt1
;
2009 librdf_statement
*pStmt( librdf_stream_get_object(pStream
.get()) );
2011 rdf::QueryException
e(
2012 "librdf_GraphResult::nextElement: "
2013 "librdf_stream_get_object failed", *this);
2014 throw lang::WrappedTargetException(
2015 "librdf_GraphResult::nextElement: "
2016 "librdf_stream_get_object failed", *this,
2019 // NB: pCtxt may be null here if this is result of a graph query
2020 if (pCtxt
&& isInternalContext(pCtxt
)) {
2021 pCtxt
= nullptr; // XML ID context is implementation detail!
2025 getTypeConverter().convertToStatement(pStmt
, pCtxt
) );
2027 // NB: this will invalidate current item.
2028 librdf_stream_next(pStream
.get());
2035 void librdf_raptor_init(void* /*user_data*/, raptor_world
* pRaptorWorld
)
2037 // fdo#64672 prevent raptor from setting global libxml2 error handlers
2038 raptor_world_set_flag(pRaptorWorld
,
2039 RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE
, 0);
2040 raptor_world_set_flag(pRaptorWorld
,
2041 RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE
, 0);
2044 librdf_world
*librdf_TypeConverter::createWorld_Lock() const
2046 // create and initialize world
2047 librdf_world
*pWorld( librdf_new_world() );
2049 throw uno::RuntimeException(
2050 "librdf_TypeConverter::createWorld: librdf_new_world failed",
2053 librdf_world_set_raptor_init_handler(pWorld
, nullptr, &librdf_raptor_init
);
2054 //FIXME logger, digest, features?
2055 xsltSecurityPrefsPtr origprefs
= xsltGetDefaultSecurityPrefs();
2056 librdf_world_open(pWorld
);
2057 xsltSecurityPrefsPtr newprefs
= xsltGetDefaultSecurityPrefs();
2058 if (newprefs
!= origprefs
) {
2059 // #i110523# restore libxslt global configuration
2060 // (gratuitously overwritten by raptor_init_parser_grddl_common)
2061 // (this is the only reason unordf is linked against libxslt)
2062 xsltSetDefaultSecurityPrefs(origprefs
);
2068 librdf_TypeConverter::createStorage_Lock(librdf_world
*i_pWorld
) const
2070 librdf_storage
*pStorage(
2071 // librdf_new_storage(i_pWorld, "memory", NULL, "contexts='yes'") );
2072 librdf_new_storage(i_pWorld
, "hashes", nullptr,
2073 "contexts='yes',hash-type='memory'") );
2075 throw uno::RuntimeException(
2076 "librdf_TypeConverter::createStorage: librdf_new_storage failed",
2082 librdf_model
*librdf_TypeConverter::createModel_Lock(
2083 librdf_world
*i_pWorld
, librdf_storage
* i_pStorage
) const
2085 librdf_model
*pRepository( librdf_new_model(i_pWorld
, i_pStorage
, nullptr) );
2087 throw uno::RuntimeException(
2088 "librdf_TypeConverter::createModel: librdf_new_model failed",
2094 librdf_uri
* ctxt
= librdf_new_uri(i_pWorld
, reinterpret_cast<const unsigned char *>(LIBRDF_MODEL_FEATURE_CONTEXTS
));
2095 librdf_node
* contexts
= librdf_model_get_feature(repository
, ctxt
);
2098 std::cout
<< "value of contexts feature: ";
2100 std::cout
<< std::endl
;
2101 // librdf_model_set_feature(repository, LIBRDF_FEATURE_CONTEXTS, ...);
2102 safe_librdf_free_node(contexts
);
2103 safe_librdf_free_uri(ctxt
);
2109 // this does NOT create a node, only URI
2110 librdf_uri
* librdf_TypeConverter::mkURI_Lock( librdf_world
* i_pWorld
,
2111 OString
const& i_rURI
)
2113 librdf_uri
*pURI( librdf_new_uri(i_pWorld
,
2114 reinterpret_cast<const unsigned char *>(i_rURI
.getStr())));
2116 throw uno::RuntimeException(
2117 "librdf_TypeConverter::mkURI: librdf_new_uri failed", nullptr);
2122 // extract blank or URI node - call without Mutex locked
2123 std::shared_ptr
<librdf_TypeConverter::Resource
>
2124 librdf_TypeConverter::extractResource_NoLock(
2125 const uno::Reference
< rdf::XResource
> & i_xResource
)
2127 if (!i_xResource
.is()) {
2128 return std::shared_ptr
<Resource
>();
2130 uno::Reference
< rdf::XBlankNode
> xBlankNode(i_xResource
, uno::UNO_QUERY
);
2131 if (xBlankNode
.is()) {
2132 const OString
label(
2133 OUStringToOString(xBlankNode
->getStringValue(),
2134 RTL_TEXTENCODING_UTF8
) );
2135 return std::make_shared
<BlankNode
>(label
);
2136 } else { // assumption: everything else is URI
2138 OUStringToOString(i_xResource
->getStringValue(),
2139 RTL_TEXTENCODING_UTF8
) );
2140 return std::make_shared
<URI
>(uri
);
2145 librdf_TypeConverter::extractResourceToCacheKey_NoLock(
2146 const uno::Reference
< rdf::XResource
> & i_xResource
, OUStringBuffer
& rBuffer
)
2148 if (!i_xResource
.is()) {
2151 uno::Reference
< rdf::XBlankNode
> xBlankNode(i_xResource
, uno::UNO_QUERY
);
2152 if (xBlankNode
.is()) {
2153 rBuffer
.append("BlankNode ").append(xBlankNode
->getStringValue());
2154 } else { // assumption: everything else is URI
2155 rBuffer
.append("URI ").append(i_xResource
->getStringValue());
2159 // create blank or URI node
2160 librdf_node
* librdf_TypeConverter::mkResource_Lock( librdf_world
* i_pWorld
,
2161 Resource
const*const i_pResource
)
2163 if (!i_pResource
) return nullptr;
2164 BlankNode
const*const pBlankNode(
2165 dynamic_cast<BlankNode
const*>(i_pResource
));
2168 librdf_new_node_from_blank_identifier(i_pWorld
,
2169 reinterpret_cast<const unsigned char*>(
2170 pBlankNode
->value
.getStr())));
2172 throw uno::RuntimeException(
2173 "librdf_TypeConverter::mkResource: "
2174 "librdf_new_node_from_blank_identifier failed", nullptr);
2177 } else { // assumption: everything else is URI
2178 URI
const*const pURI(dynamic_cast<URI
const*>(i_pResource
));
2181 librdf_new_node_from_uri_string(i_pWorld
,
2182 reinterpret_cast<const unsigned char*>(pURI
->value
.getStr())));
2184 throw uno::RuntimeException(
2185 "librdf_TypeConverter::mkResource: "
2186 "librdf_new_node_from_uri_string failed", nullptr);
2192 // extract blank or URI or literal node - call without Mutex locked
2193 std::shared_ptr
<librdf_TypeConverter::Node
>
2194 librdf_TypeConverter::extractNode_NoLock(
2195 const uno::Reference
< rdf::XNode
> & i_xNode
)
2197 if (!i_xNode
.is()) {
2198 return std::shared_ptr
<Node
>();
2200 uno::Reference
< rdf::XResource
> xResource(i_xNode
, uno::UNO_QUERY
);
2201 if (xResource
.is()) {
2202 return extractResource_NoLock(xResource
);
2204 uno::Reference
< rdf::XLiteral
> xLiteral(i_xNode
, uno::UNO_QUERY
);
2205 OSL_ENSURE(xLiteral
.is(),
2206 "mkNode: someone invented a new rdf.XNode and did not tell me");
2207 if (!xLiteral
.is()) {
2208 return std::shared_ptr
<Node
>();
2211 OUStringToOString(xLiteral
->getValue(),
2212 RTL_TEXTENCODING_UTF8
) );
2214 OUStringToOString(xLiteral
->getLanguage(),
2215 RTL_TEXTENCODING_UTF8
) );
2216 const uno::Reference
< rdf::XURI
> xType(xLiteral
->getDatatype());
2217 std::optional
<OString
> type
;
2221 OUStringToOString(xType
->getStringValue(), RTL_TEXTENCODING_UTF8
);
2223 return std::make_shared
<Literal
>(val
, lang
, type
);
2226 // extract blank or URI or literal node - call without Mutex locked
2228 librdf_TypeConverter::extractNodeToCacheKey_NoLock(
2229 const uno::Reference
< rdf::XNode
> & i_xNode
,
2230 OUStringBuffer
& rBuffer
)
2232 if (!i_xNode
.is()) {
2235 uno::Reference
< rdf::XResource
> xResource(i_xNode
, uno::UNO_QUERY
);
2236 if (xResource
.is()) {
2237 return extractResourceToCacheKey_NoLock(xResource
, rBuffer
);
2239 uno::Reference
< rdf::XLiteral
> xLiteral(i_xNode
, uno::UNO_QUERY
);
2240 OSL_ENSURE(xLiteral
.is(),
2241 "mkNode: someone invented a new rdf.XNode and did not tell me");
2242 if (!xLiteral
.is()) {
2245 rBuffer
.append("Literal ").append(xLiteral
->getValue()).append("\t").append(xLiteral
->getLanguage());
2246 const uno::Reference
< rdf::XURI
> xType(xLiteral
->getDatatype());
2248 rBuffer
.append("\t").append(xType
->getStringValue());
2251 // create blank or URI or literal node
2252 librdf_node
* librdf_TypeConverter::mkNode_Lock( librdf_world
* i_pWorld
,
2253 Node
const*const i_pNode
)
2255 if (!i_pNode
) return nullptr;
2256 Resource
const*const pResource(dynamic_cast<Resource
const*>(i_pNode
));
2258 return mkResource_Lock(i_pWorld
, pResource
);
2261 Literal
const*const pLiteral(dynamic_cast<Literal
const*>(i_pNode
));
2263 librdf_node
* ret(nullptr);
2264 if (pLiteral
->language
.isEmpty()) {
2265 if (!pLiteral
->type
) {
2266 ret
= librdf_new_node_from_literal(i_pWorld
,
2267 reinterpret_cast<const unsigned char*>(pLiteral
->value
.getStr())
2270 const std::shared_ptr
<librdf_uri
> pDatatype(
2271 mkURI_Lock(i_pWorld
, *pLiteral
->type
),
2272 safe_librdf_free_uri
);
2273 ret
= librdf_new_node_from_typed_literal(i_pWorld
,
2274 reinterpret_cast<const unsigned char*>(pLiteral
->value
.getStr())
2275 , nullptr, pDatatype
.get());
2278 if (!pLiteral
->type
) {
2279 ret
= librdf_new_node_from_literal(i_pWorld
,
2280 reinterpret_cast<const unsigned char*>(pLiteral
->value
.getStr())
2281 , pLiteral
->language
.getStr(), 0);
2283 OSL_FAIL("mkNode: invalid literal");
2288 throw uno::RuntimeException(
2289 "librdf_TypeConverter::mkNode: librdf_new_node_from_literal failed", nullptr);
2294 // extract statement - call without Mutex locked
2295 librdf_TypeConverter::Statement
librdf_TypeConverter::extractStatement_NoLock(
2296 const uno::Reference
< rdf::XResource
> & i_xSubject
,
2297 const uno::Reference
< rdf::XURI
> & i_xPredicate
,
2298 const uno::Reference
< rdf::XNode
> & i_xObject
)
2300 std::shared_ptr
<Resource
> const pSubject(
2301 extractResource_NoLock(i_xSubject
));
2302 std::shared_ptr
<URI
> const pPredicate(
2303 std::dynamic_pointer_cast
<URI
>(extractResource_NoLock(i_xPredicate
)));
2304 std::shared_ptr
<Node
> const pObject(extractNode_NoLock(i_xObject
));
2305 return Statement(pSubject
, pPredicate
, pObject
);
2308 librdf_statement
* librdf_TypeConverter::mkStatement_Lock(librdf_world
* i_pWorld
,
2309 Statement
const& i_rStatement
)
2311 librdf_node
*const pSubject(
2312 mkResource_Lock(i_pWorld
, i_rStatement
.pSubject
.get()) );
2313 librdf_node
* pPredicate(nullptr);
2314 librdf_node
* pObject(nullptr);
2316 pPredicate
= mkResource_Lock(i_pWorld
, i_rStatement
.pPredicate
.get());
2318 pObject
= mkNode_Lock(i_pWorld
, i_rStatement
.pObject
.get());
2320 safe_librdf_free_node(pPredicate
);
2324 safe_librdf_free_node(pSubject
);
2327 // NB: this takes ownership of the nodes! (which is really ugly)
2328 librdf_statement
* pStatement( librdf_new_statement_from_nodes(i_pWorld
,
2329 pSubject
, pPredicate
, pObject
) );
2331 throw uno::RuntimeException(
2332 "librdf_TypeConverter::mkStatement: "
2333 "librdf_new_statement_from_nodes failed", nullptr);
2338 uno::Reference
<rdf::XURI
>
2339 librdf_TypeConverter::convertToXURI(librdf_uri
* i_pURI
) const
2341 if (!i_pURI
) return nullptr;
2342 const unsigned char* uri( librdf_uri_as_string(i_pURI
) );
2344 throw uno::RuntimeException(
2345 "librdf_TypeConverter::convertToXURI: "
2346 "librdf_uri_as_string failed", m_rRep
);
2348 OUString
uriU( OStringToOUString(
2349 OString(reinterpret_cast<const char*>(uri
)),
2350 RTL_TEXTENCODING_UTF8
) );
2352 return rdf::URI::create(m_xContext
, uriU
);
2353 } catch (const lang::IllegalArgumentException
&) {
2354 css::uno::Any anyEx
= cppu::getCaughtException();
2355 throw lang::WrappedTargetRuntimeException(
2356 "librdf_TypeConverter::convertToXURI: "
2357 "illegal uri", m_rRep
, anyEx
);
2361 uno::Reference
<rdf::XURI
>
2362 librdf_TypeConverter::convertToXURI(librdf_node
* i_pNode
) const
2364 if (!i_pNode
) return nullptr;
2365 if (librdf_node_is_resource(i_pNode
)) {
2366 librdf_uri
* pURI( librdf_node_get_uri(i_pNode
) );
2368 throw uno::RuntimeException(
2369 "librdf_TypeConverter::convertToXURI: "
2370 "resource has no uri", m_rRep
);
2372 return convertToXURI(pURI
);
2374 OSL_FAIL("convertToXURI: unknown librdf_node");
2379 uno::Reference
<rdf::XResource
>
2380 librdf_TypeConverter::convertToXResource(librdf_node
* i_pNode
) const
2382 if (!i_pNode
) return nullptr;
2383 if (librdf_node_is_blank(i_pNode
)) {
2384 const unsigned char* label( librdf_node_get_blank_identifier(i_pNode
) );
2386 throw uno::RuntimeException(
2387 "librdf_TypeConverter::convertToXResource: "
2388 "blank node has no label", m_rRep
);
2390 OUString
labelU( OStringToOUString(
2391 OString(reinterpret_cast<const char*>(label
)),
2392 RTL_TEXTENCODING_UTF8
) );
2394 return rdf::BlankNode::create(m_xContext
, labelU
);
2395 } catch (const lang::IllegalArgumentException
&) {
2396 css::uno::Any anyEx
= cppu::getCaughtException();
2397 throw lang::WrappedTargetRuntimeException(
2398 "librdf_TypeConverter::convertToXResource: "
2399 "illegal blank node label", m_rRep
, anyEx
);
2402 return convertToXURI(i_pNode
);
2406 uno::Reference
<rdf::XNode
>
2407 librdf_TypeConverter::convertToXNode(librdf_node
* i_pNode
) const
2409 if (!i_pNode
) return nullptr;
2410 if (!librdf_node_is_literal(i_pNode
)) {
2411 return convertToXResource(i_pNode
);
2413 const unsigned char* value( librdf_node_get_literal_value(i_pNode
) );
2415 throw uno::RuntimeException(
2416 "librdf_TypeConverter::convertToXNode: "
2417 "literal has no value", m_rRep
);
2419 const char * lang( librdf_node_get_literal_value_language(i_pNode
) );
2421 librdf_node_get_literal_value_datatype_uri(i_pNode
) );
2422 OSL_ENSURE(!lang
|| !pType
, "convertToXNode: invalid literal");
2423 const OUString
valueU( OStringToOUString(
2424 OString(reinterpret_cast<const char*>(value
)),
2425 RTL_TEXTENCODING_UTF8
) );
2427 const OUString
langU( OStringToOUString(
2428 OString(reinterpret_cast<const char*>(lang
)),
2429 RTL_TEXTENCODING_UTF8
) );
2430 return rdf::Literal::createWithLanguage(m_xContext
, valueU
, langU
);
2432 uno::Reference
<rdf::XURI
> xType(convertToXURI(pType
));
2433 OSL_ENSURE(xType
.is(), "convertToXNode: null uri");
2434 return rdf::Literal::createWithType(m_xContext
, valueU
, xType
);
2436 return rdf::Literal::create(m_xContext
, valueU
);
2441 librdf_TypeConverter::convertToStatement(librdf_statement
* i_pStmt
,
2442 librdf_node
* i_pContext
) const
2445 throw uno::RuntimeException();
2447 return rdf::Statement(
2448 convertToXResource(librdf_statement_get_subject(i_pStmt
)),
2449 convertToXURI(librdf_statement_get_predicate(i_pStmt
)),
2450 convertToXNode(librdf_statement_get_object(i_pStmt
)),
2451 convertToXURI(i_pContext
));
2454 } // closing anonymous implementation namespace
2457 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
2458 unoxml_rdfRepository_get_implementation(
2459 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
2461 return cppu::acquire(new librdf_Repository(context
));
2464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */