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

sw classification: put the relevant field to the footer if policy wants so

Change-Id: I61c235660366ec1aba137097600605aae76c39a7
üst a3a7a708
...@@ -43,10 +43,14 @@ public: ...@@ -43,10 +43,14 @@ public:
OUString GetDocumentWatermark(); OUString GetDocumentWatermark();
/// The selected category has some content for the document header. /// The selected category has some content for the document header.
bool HasDocumentHeader(); bool HasDocumentHeader();
/// The selected category has some content for the document footer.
bool HasDocumentFooter();
void UpdateInfobar(SfxViewFrame& rViewFrame); void UpdateInfobar(SfxViewFrame& rViewFrame);
/// Brief text located at the top of each document's pages. /// Brief text located at the top of each document's pages.
static const OUString& PROP_DOCHEADER(); static const OUString& PROP_DOCHEADER();
/// Brief text located at the bottom of each document's pages.
static const OUString& PROP_DOCFOOTER();
}; };
#endif #endif
......
...@@ -163,8 +163,8 @@ throw (xml::sax::SAXException, uno::RuntimeException, std::exception) ...@@ -163,8 +163,8 @@ throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:2"].clear(); rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:2"].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:3"].clear(); rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:3"].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:4"].clear(); rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:4"].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-footer"].clear(); rCategory.m_aLabels[SfxClassificationHelper::PROP_DOCHEADER()].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-header"].clear(); rCategory.m_aLabels[SfxClassificationHelper::PROP_DOCFOOTER()].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-watermark"].clear(); rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-watermark"].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-first-line-of-text"].clear(); rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-first-line-of-text"].clear();
rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-last-line-of-text"].clear(); rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-last-line-of-text"].clear();
...@@ -235,9 +235,9 @@ void SAL_CALL SfxClassificationParser::endElement(const OUString& rName) throw ( ...@@ -235,9 +235,9 @@ void SAL_CALL SfxClassificationParser::endElement(const OUString& rName) throw (
if (m_pCategory) if (m_pCategory)
{ {
if (m_aIdentifier == "Document: Header") if (m_aIdentifier == "Document: Header")
m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-header"] = m_aValue; m_pCategory->m_aLabels[SfxClassificationHelper::PROP_DOCHEADER()] = m_aValue;
else if (m_aIdentifier == "Document: Footer") else if (m_aIdentifier == "Document: Footer")
m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-footer"] = m_aValue; m_pCategory->m_aLabels[SfxClassificationHelper::PROP_DOCFOOTER()] = m_aValue;
else if (m_aIdentifier == "Document: Watermark") else if (m_aIdentifier == "Document: Watermark")
m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-watermark"] = m_aValue; m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-watermark"] = m_aValue;
} }
...@@ -418,7 +418,16 @@ bool SfxClassificationHelper::HasImpactLevel() ...@@ -418,7 +418,16 @@ bool SfxClassificationHelper::HasImpactLevel()
bool SfxClassificationHelper::HasDocumentHeader() bool SfxClassificationHelper::HasDocumentHeader()
{ {
std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Marking:document-header"); std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find(SfxClassificationHelper::PROP_DOCHEADER());
if (it == m_pImpl->m_aLabels.end() || it->second.isEmpty())
return false;
return true;
}
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()) if (it == m_pImpl->m_aLabels.end() || it->second.isEmpty())
return false; return false;
...@@ -527,4 +536,10 @@ const OUString& SfxClassificationHelper::PROP_DOCHEADER() ...@@ -527,4 +536,10 @@ const OUString& SfxClassificationHelper::PROP_DOCHEADER()
return sProp; return sProp;
} }
const OUString& SfxClassificationHelper::PROP_DOCFOOTER()
{
static OUString sProp("urn:bails:IntellectualProperty:Marking:document-footer");
return sProp;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -123,7 +123,10 @@ void SwEditShell::SetClassification(const OUString& rName) ...@@ -123,7 +123,10 @@ void SwEditShell::SetClassification(const OUString& rName)
// This updates the infobar as well. // This updates the infobar as well.
aHelper.SetBACName(rName); aHelper.SetBACName(rName);
if (aHelper.HasDocumentHeader()) bool bHeaderIsNeeded = aHelper.HasDocumentHeader();
bool bFooterIsNeeded = aHelper.HasDocumentFooter();
if (bHeaderIsNeeded || bFooterIsNeeded)
{ {
uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel(); uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY); uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
...@@ -134,25 +137,50 @@ void SwEditShell::SetClassification(const OUString& rName) ...@@ -134,25 +137,50 @@ void SwEditShell::SetClassification(const OUString& rName)
for (const OUString& rPageStyleName : aUsedPageStyles) for (const OUString& rPageStyleName : aUsedPageStyles)
{ {
uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
OUString aServiceName = "com.sun.star.text.TextField.DocInfo.Custom";
// If the header is off, turn it on. if (bHeaderIsNeeded)
bool bHeaderIsOn = false; {
xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn; // If the header is off, turn it on.
if (!bHeaderIsOn) bool bHeaderIsOn = false;
xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::makeAny(true)); xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
if (!bHeaderIsOn)
xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::makeAny(true));
// If the header already contains a document header field, no need to do anything.
uno::Reference<text::XText> xHeaderText;
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
if (!lcl_hasField(xHeaderText, aServiceName, SfxClassificationHelper::PROP_DOCHEADER()))
{
// Append a field to the end of the header text.
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY);
xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(SfxClassificationHelper::PROP_DOCHEADER()));
uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent, /*bAbsorb=*/false);
}
}
// If the header already contains a document header field, no need to do anything. if (bFooterIsNeeded)
uno::Reference<text::XText> xHeaderText;
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
OUString aServiceName = "com.sun.star.text.TextField.DocInfo.Custom";
if (!lcl_hasField(xHeaderText, aServiceName, SfxClassificationHelper::PROP_DOCHEADER()))
{ {
// Append a field to the end of the header text. // If the footer is off, turn it on.
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY); bool bFooterIsOn = false;
uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY); xPageStyle->getPropertyValue(UNO_NAME_FOOTER_IS_ON) >>= bFooterIsOn;
xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(SfxClassificationHelper::PROP_DOCHEADER())); if (!bFooterIsOn)
uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY); xPageStyle->setPropertyValue(UNO_NAME_FOOTER_IS_ON, uno::makeAny(true));
xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent, /*bAbsorb=*/false);
// If the footer already contains a document header field, no need to do anything.
uno::Reference<text::XText> xFooterText;
xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText;
if (!lcl_hasField(xFooterText, aServiceName, SfxClassificationHelper::PROP_DOCFOOTER()))
{
// Append a field to the end of the footer text.
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY);
xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(SfxClassificationHelper::PROP_DOCFOOTER()));
uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
xFooterText->insertTextContent(xFooterText->getEnd(), xTextContent, /*bAbsorb=*/false);
}
} }
} }
} }
......
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