12#include <com/sun/star/frame/XModel.hpp> 
   13#include <com/sun/star/rdf/Literal.hpp> 
   14#include <com/sun/star/rdf/Statement.hpp> 
   15#include <com/sun/star/rdf/URI.hpp> 
   16#include <com/sun/star/rdf/XDocumentMetadataAccess.hpp> 
   28    const css::uno::Reference<rdf::XDocumentMetadataAccess>& xDocumentMetadataAccess,
 
   29    const css::uno::Reference<rdf::XURI>& xType)
 
   33        return xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
 
   35    catch (
const uno::RuntimeException&)
 
   37        return uno::Sequence<uno::Reference<rdf::XURI>>();
 
   41css::uno::Sequence<uno::Reference<css::rdf::XURI>>
 
   43                           const OUString& rType)
 
   47        uno::Reference<uno::XComponentContext> xComponentContext(
 
   52        uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
   53        uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
xModel,
 
   57    catch (const ::css::uno::Exception&)
 
   59        return uno::Sequence<uno::Reference<rdf::XURI>>();
 
   63std::map<OUString, OUString>
 
   65                           const uno::Sequence<uno::Reference<css::rdf::XURI>>& rGraphNames,
 
   66                           const css::uno::Reference<css::rdf::XResource>& xSubject)
 
   68    std::map<OUString, OUString> aRet;
 
   69    if (!rGraphNames.hasElements())
 
   72    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
 
   73    const uno::Reference<rdf::XRepository>& xRepo = xDocumentMetadataAccess->getRDFRepository();
 
   74    for (
const uno::Reference<rdf::XURI>& xGraphName : rGraphNames)
 
   76        uno::Reference<rdf::XNamedGraph> xGraph = xRepo->getGraph(xGraphName);
 
   80        uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(
 
   81            xSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
 
   82        while (xStatements->hasMoreElements())
 
   84            const rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
 
   85            aRet[aStatement.Predicate->getStringValue()] = aStatement.Object->getStringValue();
 
   92std::map<OUString, OUString>
 
   94                           const OUString& rType,
 
   95                           const css::uno::Reference<css::rdf::XResource>& xSubject)
 
  101                               const OUString& rType, 
const OUString& rPath,
 
  102                               const css::uno::Reference<css::rdf::XResource>& xSubject,
 
  103                               const OUString& rKey, 
const OUString& rValue)
 
  106    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  107    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
xModel, uno::UNO_QUERY);
 
  108    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
 
  109    uno::Reference<rdf::XURI> xGraphName;
 
  110    if (aGraphNames.hasElements())
 
  111        xGraphName = aGraphNames[0];
 
  114        uno::Sequence< uno::Reference<rdf::XURI> > xTypes = { xType };
 
  115        xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes);
 
  117    uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
 
  118    uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
 
  119    uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue);
 
  120    xGraph->addStatement(xSubject, xKey, xValue);
 
  126    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  127    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
xModel, uno::UNO_QUERY);
 
  128    return getGraphNames(xDocumentMetadataAccess, xType).hasElements();
 
  132                                  const OUString& rType,
 
  133                                  const css::uno::Reference<css::rdf::XResource>& xSubject,
 
  134                                  const OUString& rKey, 
const OUString& rValue)
 
  137    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  138    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
xModel, uno::UNO_QUERY);
 
  139    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
 
  140    if (!aGraphNames.hasElements())
 
  143    uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(aGraphNames[0]);
 
  144    uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
 
  145    uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue);
 
  146    xGraph->removeStatements(xSubject, xKey, xValue);
 
  150                                  const OUString& rType,
 
  151                                  const css::uno::Reference<css::rdf::XResource>& xSubject)
 
  154    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  155    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
xModel, uno::UNO_QUERY);
 
  156    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
 
  157    if (!aGraphNames.hasElements())
 
  160    for (
const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
 
  162        uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
 
  163        uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
 
  164        while (xStatements->hasMoreElements())
 
  166            rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
 
  167            uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, aStatement.Predicate->getStringValue());
 
  168            uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, aStatement.Object->getStringValue());
 
  169            xGraph->removeStatements(xSubject, xKey, xValue);
 
  175                                  const css::uno::Reference<css::frame::XModel>& xDstModel,
 
  176                                  const OUString& rType,
 
  177                                  const css::uno::Reference<css::rdf::XResource>& xSrcSubject,
 
  178                                  const css::uno::Reference<css::rdf::XResource>& xDstSubject)
 
  181    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  182    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xSrcModel, uno::UNO_QUERY);
 
  183    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
 
  184    if (!aGraphNames.hasElements())
 
  187    for (
const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
 
  189        uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
 
  190        uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xSrcSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
 
  191        while (xStatements->hasMoreElements())
 
  193            const rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
 
  195            const OUString sKey = aStatement.Predicate->getStringValue();
 
  196            const OUString sValue = aStatement.Object->getStringValue();
 
  197            addStatement(xDstModel, rType, xGraphName->getLocalName(), xDstSubject, sKey, sValue);
 
  217    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  219    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
 
  220    if (!aGraphNames.hasElements())
 
  223    uno::Reference<rdf::XURI> xGraphName = aGraphNames[0];
 
  224    uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
 
  226    uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
 
  227    uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue);
 
  228    xGraph->removeStatements(xSubject, xKey, xValue);
 
  234    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
 
  236    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
 
  237    uno::Reference<rdf::XURI> xGraphName;
 
  238    if (aGraphNames.hasElements())
 
  240        xGraphName = aGraphNames[0];
 
  244        uno::Sequence< uno::Reference<rdf::XURI> > xTypes = { xType };
 
  245        xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes);
 
  248    uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
 
  250    uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
 
  252    if (aGraphNames.hasElements())
 
  255        uno::Reference<rdf::XLiteral> xOldValue = rdf::Literal::create(xComponentContext, rOldValue);
 
  256        xGraph->removeStatements(xSubject, xKey, xOldValue);
 
  260    uno::Reference<rdf::XLiteral> xNewValue = rdf::Literal::create(xComponentContext, rNewValue);
 
  261    xGraph->addStatement(xSubject, xKey, xNewValue);
 
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
 
SwDocShell * GetDocShell()
 
static void removeTextNodeStatement(const OUString &rType, SwTextNode &rTextNode, const OUString &rKey, const OUString &rValue)
Remove an (rTextNode, key, value) statement in the graph of type rType.
 
static void removeStatement(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const css::uno::Reference< css::rdf::XResource > &xSubject, const OUString &rKey, const OUString &rValue)
Remove an (XResource, key, value) statement in the graph of type rType, if it exists.
 
static std::map< OUString, OUString > getStatements(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Sequence< css::uno::Reference< css::rdf::XURI > > &rGraphNames, const css::uno::Reference< css::rdf::XResource > &xSubject)
Gets all (XResource, key, value) statements in RDF graphs given the graph-names.
 
static void clearStatements(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const css::uno::Reference< css::rdf::XResource > &xSubject)
Remove all statements in the graph of type rType, if any exists.
 
static void addStatement(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const OUString &rPath, const css::uno::Reference< css::rdf::XResource > &xSubject, const OUString &rKey, const OUString &rValue)
Add an (XResource, key, value) statement in the graph of type rType – or if it does not exist,...
 
static void updateTextNodeStatement(const OUString &rType, const OUString &rPath, SwTextNode &rTextNode, const OUString &rKey, const OUString &rOldValue, const OUString &rNewValue)
Update an (rTextNode, key, value) statement in the graph of type rType from old value to new....
 
static void cloneStatements(const css::uno::Reference< css::frame::XModel > &xSrcModel, const css::uno::Reference< css::frame::XModel > &xDstModel, const OUString &rType, const css::uno::Reference< css::rdf::XResource > &xSrcSubject, const css::uno::Reference< css::rdf::XResource > &xDstSubject)
Clone all statements in the graph of type rType, if any exists, from one subject to another.
 
static css::uno::Sequence< css::uno::Reference< css::rdf::XURI > > getGraphNames(const css::uno::Reference< css::rdf::XDocumentMetadataAccess > &xDocumentMetadataAccess, const css::uno::Reference< css::rdf::XURI > &xType)
Gets all graph-names in RDF of a given type.
 
static void addTextNodeStatement(const OUString &rType, const OUString &rPath, SwTextNode &rTextNode, const OUString &rKey, const OUString &rValue)
Add an (rTextNode, key, value) statement in the graph of type rType – or if it does not exist,...
 
static bool hasMetadataGraph(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType)
Check if a graph of type rType exists.
 
static std::map< OUString, OUString > getTextNodeStatements(const OUString &rType, SwTextNode &rTextNode)
Gets all (rTextNode, key, value) statements in RDF graphs of type rType.
 
SwTextNode is a paragraph in the document model.
 
static rtl::Reference< SwXParagraph > CreateXParagraph(SwDoc &rDoc, SwTextNode *pTextNode, css::uno::Reference< css::text::XText > const &xParentText=nullptr, const sal_Int32 nSelStart=-1, const sal_Int32 nSelEnd=- 1)
 
Reference< XComponentContext > getProcessComponentContext()
 
Reference< XModel > xModel