Kaydet (Commit) 8a5a9e05 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

TSCP: bail out quickly in paragraph classification check on save

Before saving a document we need to check that the document level
classification is at the higher or same level as the individual
paragraph level classification is. The trouble here is tha this
can be quite a costly operation, so bail out quickly if we don't
detect that no paragraph classification has been applied to the
content by checking if we have the RDF metadata present or not.

Change-Id: Iaef29de7e138937a5c1881cf34c9075fb37ba87d
Reviewed-on: https://gerrit.libreoffice.org/44573Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst e4d15516
...@@ -45,6 +45,10 @@ public: ...@@ -45,6 +45,10 @@ public:
const css::uno::Reference<css::rdf::XResource>& xSubject, const css::uno::Reference<css::rdf::XResource>& xSubject,
const OUString& rKey, const OUString& rValue); const OUString& rKey, const OUString& rValue);
/// Check if a graph of type rType exists.
static bool hasMetadataGraph(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType);
/// Remove an (XResource, key, value) statement in the graph of type rType, if it exists. /// Remove an (XResource, key, value) statement in the graph of type rType, if it exists.
static void removeStatement(const css::uno::Reference<css::frame::XModel>& xModel, static void removeStatement(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType, const OUString& rType,
......
...@@ -73,6 +73,15 @@ void SwRDFHelper::addStatement(const css::uno::Reference<css::frame::XModel>& xM ...@@ -73,6 +73,15 @@ void SwRDFHelper::addStatement(const css::uno::Reference<css::frame::XModel>& xM
xGraph->addStatement(xSubject, xKey, xValue); xGraph->addStatement(xSubject, xKey, xValue);
} }
bool SwRDFHelper::hasMetadataGraph(const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rType)
{
uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
return aGraphNames.hasElements();
}
void SwRDFHelper::removeStatement(const css::uno::Reference<css::frame::XModel>& xModel, void SwRDFHelper::removeStatement(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType, const OUString& rType,
const css::uno::Reference<css::rdf::XResource>& xSubject, const css::uno::Reference<css::rdf::XResource>& xSubject,
......
...@@ -2035,6 +2035,10 @@ void SwEditShell::ClassifyDocPerHighestParagraphClass() ...@@ -2035,6 +2035,10 @@ void SwEditShell::ClassifyDocPerHighestParagraphClass()
if (!pDocShell) if (!pDocShell)
return; return;
// bail out as early as possible if we don't have paragraph classification
if (!SwRDFHelper::hasMetadataGraph(pDocShell->GetBaseModel(), MetaNS))
return;
SfxClassificationHelper aHelper(pDocShell->getDocProperties()); SfxClassificationHelper aHelper(pDocShell->getDocProperties());
const OUString sHighestParaClass = lcl_GetHighestClassificationParagraphClass(GetCursor()); const OUString sHighestParaClass = lcl_GetHighestClassificationParagraphClass(GetCursor());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment