From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- svx/source/dialog/ClassificationCommon.cxx | 125 +++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 svx/source/dialog/ClassificationCommon.cxx (limited to 'svx/source/dialog/ClassificationCommon.cxx') diff --git a/svx/source/dialog/ClassificationCommon.cxx b/svx/source/dialog/ClassificationCommon.cxx new file mode 100644 index 000000000..885dff644 --- /dev/null +++ b/svx/source/dialog/ClassificationCommon.cxx @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include +#include +#include + +#include +#include +#include + +using namespace css; + +namespace svx::classification +{ +OUString convertClassificationResultToString(std::vector const& rResults) +{ + OUStringBuffer sRepresentation; + + for (svx::ClassificationResult const& rResult : rResults) + { + switch (rResult.meType) + { + case svx::ClassificationType::CATEGORY: + case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: + case svx::ClassificationType::MARKING: + case svx::ClassificationType::TEXT: + sRepresentation.append(rResult.msName); + break; + + case svx::ClassificationType::PARAGRAPH: + sRepresentation.append(" "); + break; + } + } + return sRepresentation.makeStringAndClear(); +} + +OUString getProperty(uno::Reference const& rxPropertyContainer, + OUString const& rName) +{ + try + { + uno::Reference xPropertySet(rxPropertyContainer, uno::UNO_QUERY); + return xPropertySet->getPropertyValue(rName).get(); + } + catch (const css::uno::Exception&) + { + } + + return OUString(); +} + +bool containsProperty(uno::Sequence const& rProperties, std::u16string_view rName) +{ + return std::any_of(rProperties.begin(), rProperties.end(), + [&](const beans::Property& rProperty) { return rProperty.Name == rName; }); +} + +void removeAllProperties(uno::Reference const& rxPropertyContainer) +{ + uno::Reference xPropertySet(rxPropertyContainer, uno::UNO_QUERY); + const uno::Sequence aProperties + = xPropertySet->getPropertySetInfo()->getProperties(); + + for (const beans::Property& rProperty : aProperties) + { + rxPropertyContainer->removeProperty(rProperty.Name); + } +} + +bool addOrInsertDocumentProperty( + uno::Reference const& rxPropertyContainer, OUString const& rsKey, + OUString const& rsValue) +{ + uno::Reference xPropertySet(rxPropertyContainer, uno::UNO_QUERY); + + try + { + if (containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey)) + xPropertySet->setPropertyValue(rsKey, uno::Any(rsValue)); + else + rxPropertyContainer->addProperty(rsKey, beans::PropertyAttribute::REMOVABLE, + uno::Any(rsValue)); + } + catch (const uno::Exception& /*rException*/) + { + return false; + } + return true; +} + +void insertFullTextualRepresentationAsDocumentProperty( + uno::Reference const& rxPropertyContainer, + sfx::ClassificationKeyCreator const& rKeyCreator, + std::vector const& rResults) +{ + OUString sString = convertClassificationResultToString(rResults); + addOrInsertDocumentProperty(rxPropertyContainer, rKeyCreator.makeFullTextualRepresentationKey(), + sString); +} + +void insertCreationOrigin(uno::Reference const& rxPropertyContainer, + sfx::ClassificationKeyCreator const& rKeyCreator, + sfx::ClassificationCreationOrigin eOrigin) +{ + // Nothing to do if origin is "NONE" + if (eOrigin == sfx::ClassificationCreationOrigin::NONE) + return; + + OUString sValue = (eOrigin == sfx::ClassificationCreationOrigin::BAF_POLICY) + ? OUString("BAF_POLICY") + : OUString("MANUAL"); + addOrInsertDocumentProperty(rxPropertyContainer, rKeyCreator.makeCreationOriginKey(), sValue); +} +} // end svx::classification namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3