Kaydet (Commit) 900fccc2 authored tarafından Miklos Vajna's avatar Miklos Vajna

sfx2 classification: don't sort items on the toolbar listbox

Assuming the policy follows a least-confidential -> most-confidential
order, doing a lexicographical sort on the category names does more harm
than good. So use a vector instead of a name-indexed map for categories.

Also, don't duplicate the label map for the current state, but just
store the state in the same category structure that is used for other
(currently not used) categories as well.

Change-Id: I1672192e572abfc22b6aeeb152ee7484086cea91
üst 9729c112
......@@ -40,6 +40,7 @@ namespace
class SfxClassificationCategory
{
public:
OUString m_aName;
std::map<OUString, OUString> m_aLabels;
};
......@@ -47,7 +48,7 @@ public:
class SfxClassificationParser : public cppu::WeakImplHelper<xml::sax::XDocumentHandler>
{
public:
std::map<OUString, SfxClassificationCategory> m_aCategories;
std::vector<SfxClassificationCategory> m_aCategories;
OUString m_aPolicyAuthorityName;
bool m_bInPolicyAuthorityName;
......@@ -139,7 +140,9 @@ throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
OUString aIdentifier = xAttribs->getValueByName("Identifier");
// Create a new category and initialize it with the data that's true for all categories.
SfxClassificationCategory& rCategory = m_aCategories[aName];
m_aCategories.push_back(SfxClassificationCategory());
SfxClassificationCategory& rCategory = m_aCategories.back();
rCategory.m_aName = aName;
rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Name"] = m_aPolicyAuthorityName;
rCategory.m_aLabels["urn:bails:IntellectualProperty:Policy:Name"] = m_aPolicyName;
rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Identifier"] = m_aProgramID;
......@@ -282,9 +285,9 @@ void SAL_CALL SfxClassificationParser::setDocumentLocator(const uno::Reference<x
class SfxClassificationHelper::Impl
{
public:
std::map<OUString, OUString> m_aLabels;
SfxClassificationCategory m_aCategory;
/// Possible categories of a policy to choose from.
std::map<OUString, SfxClassificationCategory> m_aCategories;
std::vector<SfxClassificationCategory> m_aCategories;
SfxObjectShell& m_rObjectShell;
Impl(SfxObjectShell& rObjectShell);
......@@ -336,7 +339,7 @@ void SfxClassificationHelper::Impl::pushToObjectShell()
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY);
uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
for (const std::pair<OUString, OUString>& rLabel : m_aLabels)
for (const std::pair<OUString, OUString>& rLabel : m_aCategory.m_aLabels)
{
try
{
......@@ -388,7 +391,7 @@ SfxClassificationHelper::SfxClassificationHelper(SfxObjectShell& rObjectShell)
uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name);
OUString aValue;
if (aAny >>= aValue)
m_pImpl->m_aLabels[rProperty.Name] = aValue;
m_pImpl->m_aCategory.m_aLabels[rProperty.Name] = aValue;
}
}
......@@ -398,8 +401,8 @@ SfxClassificationHelper::~SfxClassificationHelper()
OUString SfxClassificationHelper::GetBACName()
{
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Name");
if (it != m_pImpl->m_aLabels.end())
std::map<OUString, OUString>::iterator it = m_pImpl->m_aCategory.m_aLabels.find("urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Name");
if (it != m_pImpl->m_aCategory.m_aLabels.end())
return it->second;
return OUString();
......@@ -407,12 +410,12 @@ OUString SfxClassificationHelper::GetBACName()
bool SfxClassificationHelper::HasImpactLevel()
{
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Scale");
if (it == m_pImpl->m_aLabels.end())
std::map<OUString, OUString>::iterator it = m_pImpl->m_aCategory.m_aLabels.find("urn:bails:IntellectualProperty:Impact:Scale");
if (it == m_pImpl->m_aCategory.m_aLabels.end())
return false;
it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
if (it == m_pImpl->m_aLabels.end())
it = m_pImpl->m_aCategory.m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
if (it == m_pImpl->m_aCategory.m_aLabels.end())
return false;
return true;
......@@ -420,8 +423,8 @@ bool SfxClassificationHelper::HasImpactLevel()
bool SfxClassificationHelper::HasDocumentHeader()
{
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find(SfxClassificationHelper::PROP_DOCHEADER());
if (it == m_pImpl->m_aLabels.end() || it->second.isEmpty())
std::map<OUString, OUString>::iterator it = m_pImpl->m_aCategory.m_aLabels.find(SfxClassificationHelper::PROP_DOCHEADER());
if (it == m_pImpl->m_aCategory.m_aLabels.end() || it->second.isEmpty())
return false;
return true;
......@@ -429,8 +432,8 @@ bool SfxClassificationHelper::HasDocumentHeader()
bool SfxClassificationHelper::HasDocumentFooter()
{
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find(SfxClassificationHelper::PROP_DOCFOOTER());
if (it == m_pImpl->m_aLabels.end() || it->second.isEmpty())
std::map<OUString, OUString>::iterator it = m_pImpl->m_aCategory.m_aLabels.find(SfxClassificationHelper::PROP_DOCFOOTER());
if (it == m_pImpl->m_aCategory.m_aLabels.end() || it->second.isEmpty())
return false;
return true;
......@@ -440,13 +443,13 @@ basegfx::BColor SfxClassificationHelper::GetImpactLevelColor()
{
basegfx::BColor aRet;
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Scale");
if (it == m_pImpl->m_aLabels.end())
std::map<OUString, OUString>::iterator it = m_pImpl->m_aCategory.m_aLabels.find("urn:bails:IntellectualProperty:Impact:Scale");
if (it == m_pImpl->m_aCategory.m_aLabels.end())
return aRet;
OUString aScale = it->second;
it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
if (it == m_pImpl->m_aLabels.end())
it = m_pImpl->m_aCategory.m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
if (it == m_pImpl->m_aCategory.m_aLabels.end())
return aRet;
OUString aLevel = it->second;
......@@ -488,8 +491,8 @@ basegfx::BColor SfxClassificationHelper::GetImpactLevelColor()
OUString SfxClassificationHelper::GetDocumentWatermark()
{
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find(SfxClassificationHelper::PROP_DOCWATERMARK());
if (it != m_pImpl->m_aLabels.end())
std::map<OUString, OUString>::iterator it = m_pImpl->m_aCategory.m_aLabels.find(SfxClassificationHelper::PROP_DOCWATERMARK());
if (it != m_pImpl->m_aCategory.m_aLabels.end())
return it->second;
return OUString();
......@@ -501,9 +504,9 @@ std::vector<OUString> SfxClassificationHelper::GetBACNames()
m_pImpl->parsePolicy();
std::vector<OUString> aRet;
std::transform(m_pImpl->m_aCategories.begin(), m_pImpl->m_aCategories.end(), std::back_inserter(aRet), [](const std::pair<OUString, SfxClassificationCategory>& rPair)
std::transform(m_pImpl->m_aCategories.begin(), m_pImpl->m_aCategories.end(), std::back_inserter(aRet), [](const SfxClassificationCategory& rCategory)
{
return rPair.first;
return rCategory.m_aName;
});
return aRet;
}
......@@ -513,14 +516,17 @@ void SfxClassificationHelper::SetBACName(const OUString& rName)
if (m_pImpl->m_aCategories.empty())
m_pImpl->parsePolicy();
std::map<OUString, SfxClassificationCategory>::iterator it = m_pImpl->m_aCategories.find(rName);
std::vector<SfxClassificationCategory>::iterator it = std::find_if(m_pImpl->m_aCategories.begin(), m_pImpl->m_aCategories.end(), [&](const SfxClassificationCategory& rCategory)
{
return rCategory.m_aName == rName;
});
if (it == m_pImpl->m_aCategories.end())
{
SAL_WARN("sfx.view", "'" << rName << "' is not a recognized category name");
return;
}
m_pImpl->m_aLabels = it->second.m_aLabels;
m_pImpl->m_aCategory.m_aLabels = it->m_aLabels;
m_pImpl->pushToObjectShell();
SfxViewFrame* pViewFrame = SfxViewFrame::Current();
if (!pViewFrame)
......
......@@ -203,7 +203,7 @@ void SigningTest::testOOXMLPartial()
SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE(
(OString::number(
static_cast<std::underlying_type<SignatureState>::type>(nActual))
static_cast<std::underlying_type<SignatureState>::type>(nActual))
.getStr()),
(nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::PARTIAL_OK));
......
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