diff options
Diffstat (limited to 'sw/source/filter/ww8/docxexport.cxx')
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 139 |
1 files changed, 56 insertions, 83 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index eb10711b6e28..39105ace49f8 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -83,6 +83,7 @@ #include "ww8scan.hxx" #include <oox/token/properties.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <comphelper/storagehelper.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> @@ -351,24 +352,18 @@ void DocxExport::DoComboBox(const OUString& rName, m_pDocumentFS->startElementNS(XML_w, XML_ddList); // Output the 0-based index of the selected value - sal_uInt32 nListItems = rListItems.getLength(); - sal_Int32 nId = 0; - sal_uInt32 nI = 0; - while ( ( nI < nListItems ) && ( nId == 0 ) ) - { - if ( rListItems[nI] == rSelected ) - nId = nI; - nI++; - } + sal_Int32 nId = comphelper::findValue(rListItems, rSelected); + if (nId == -1) + nId = 0; m_pDocumentFS->singleElementNS(XML_w, XML_result, FSNS(XML_w, XML_val), OString::number(nId)); // Loop over the entries - for (sal_uInt32 i = 0; i < nListItems; i++) + for (const auto& rItem : rListItems) { m_pDocumentFS->singleElementNS( XML_w, XML_listEntry, - FSNS( XML_w, XML_val ), rListItems[i].toUtf8() ); + FSNS( XML_w, XML_val ), rItem.toUtf8() ); } m_pDocumentFS->endElementNS( XML_w, XML_ddList ); @@ -1044,50 +1039,50 @@ void DocxExport::WriteSettings() uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aGrabBagName ) >>= propList; - for( sal_Int32 i=0; i < propList.getLength(); ++i ) + for( const auto& rProp : propList ) { - if ( propList[i].Name == "ThemeFontLangProps" ) + if ( rProp.Name == "ThemeFontLangProps" ) { uno::Sequence< beans::PropertyValue > themeFontLangProps; - propList[i].Value >>= themeFontLangProps; + rProp.Value >>= themeFontLangProps; OUString aValues[3]; - for( sal_Int32 j=0; j < themeFontLangProps.getLength(); ++j ) + for( const auto& rThemeFontLangProp : themeFontLangProps ) { - if( themeFontLangProps[j].Name == "val" ) - themeFontLangProps[j].Value >>= aValues[0]; - else if( themeFontLangProps[j].Name == "eastAsia" ) - themeFontLangProps[j].Value >>= aValues[1]; - else if( themeFontLangProps[j].Name == "bidi" ) - themeFontLangProps[j].Value >>= aValues[2]; + if( rThemeFontLangProp.Name == "val" ) + rThemeFontLangProp.Value >>= aValues[0]; + else if( rThemeFontLangProp.Name == "eastAsia" ) + rThemeFontLangProp.Value >>= aValues[1]; + else if( rThemeFontLangProp.Name == "bidi" ) + rThemeFontLangProp.Value >>= aValues[2]; } pFS->singleElementNS( XML_w, XML_themeFontLang, FSNS( XML_w, XML_val ), aValues[0].toUtf8(), FSNS( XML_w, XML_eastAsia ), aValues[1].toUtf8(), FSNS( XML_w, XML_bidi ), aValues[2].toUtf8() ); } - else if ( propList[i].Name == "CompatSettings" ) + else if ( rProp.Name == "CompatSettings" ) { pFS->startElementNS(XML_w, XML_compat); uno::Sequence< beans::PropertyValue > aCompatSettingsSequence; - propList[i].Value >>= aCompatSettingsSequence; + rProp.Value >>= aCompatSettingsSequence; - for(sal_Int32 j=0; j < aCompatSettingsSequence.getLength(); ++j) + for(const auto& rCompatSetting : aCompatSettingsSequence) { uno::Sequence< beans::PropertyValue > aCompatSetting; - aCompatSettingsSequence[j].Value >>= aCompatSetting; + rCompatSetting.Value >>= aCompatSetting; OUString aName; OUString aUri; OUString aValue; - for(sal_Int32 k=0; k < aCompatSetting.getLength(); ++k) + for(const auto& rPropVal : aCompatSetting) { - if( aCompatSetting[k].Name == "name" ) - aCompatSetting[k].Value >>= aName; - else if( aCompatSetting[k].Name == "uri" ) - aCompatSetting[k].Value >>= aUri; - else if( aCompatSetting[k].Name == "val" ) - aCompatSetting[k].Value >>= aValue; + if( rPropVal.Name == "name" ) + rPropVal.Value >>= aName; + else if( rPropVal.Name == "uri" ) + rPropVal.Value >>= aUri; + else if( rPropVal.Name == "val" ) + rPropVal.Value >>= aValue; } pFS->singleElementNS( XML_w, XML_compatSetting, FSNS( XML_w, XML_name ), aName.toUtf8(), @@ -1097,16 +1092,16 @@ void DocxExport::WriteSettings() pFS->endElementNS( XML_w, XML_compat ); } - else if (propList[i].Name == "DocumentProtection") + else if (rProp.Name == "DocumentProtection") { uno::Sequence< beans::PropertyValue > rAttributeList; - propList[i].Value >>= rAttributeList; + rProp.Value >>= rAttributeList; if (rAttributeList.hasElements()) { sax_fastparser::FastAttributeList* pAttributeList = sax_fastparser::FastSerializerHelper::createAttrList(); - for (sal_Int32 j = 0; j < rAttributeList.getLength(); ++j) + for (const auto& rAttribute : rAttributeList) { static DocxStringTokenMap const aTokens[] = { @@ -1123,8 +1118,8 @@ void DocxExport::WriteSettings() { nullptr, 0 } }; - if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttributeList[j].Name)) - pAttributeList->add(FSNS(XML_w, nToken), rAttributeList[j].Value.get<OUString>().toUtf8()); + if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name)) + pAttributeList->add(FSNS(XML_w, nToken), rAttribute.Value.get<OUString>().toUtf8()); } // we have document protection from input DOCX file @@ -1169,15 +1164,10 @@ void DocxExport::WriteTheme() uno::Reference<xml::dom::XDocument> themeDom; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - OUString propName = propList[nProp].Name; - if ( propName == "OOXTheme" ) - { - propList[nProp].Value >>= themeDom; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXTheme"; }); + if (pProp != propList.end()) + pProp->Value >>= themeDom; // no theme dom to write if ( !themeDom.is() ) @@ -1209,17 +1199,17 @@ void DocxExport::WriteGlossary() uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; sal_Int32 collectedProperties = 0; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) + for ( const auto& rProp : propList ) { - OUString propName = propList[nProp].Name; + OUString propName = rProp.Name; if ( propName == "OOXGlossary" ) { - propList[nProp].Value >>= glossaryDocDom; + rProp.Value >>= glossaryDocDom; collectedProperties++; } if (propName == "OOXGlossaryDom") { - propList[nProp].Value >>= glossaryDomList; + rProp.Value >>= glossaryDomList; collectedProperties++; } if (collectedProperties == 2) @@ -1243,10 +1233,8 @@ void DocxExport::WriteGlossary() serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ), uno::Sequence< beans::StringPair >() ); - sal_Int32 length = glossaryDomList.getLength(); - for ( int i =0; i < length; i++) + for ( const uno::Sequence< uno::Any>& glossaryElement : glossaryDomList) { - uno::Sequence< uno::Any> glossaryElement = glossaryDomList[i]; OUString gTarget, gType, gId, contentType; uno::Reference<xml::dom::XDocument> xDom; glossaryElement[0] >>= xDom; @@ -1279,25 +1267,15 @@ void DocxExport::WriteCustomXml() uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - const OUString propName = propList[nProp].Name; - if ( propName == "OOXCustomXml" ) - { - propList[nProp].Value >>= customXmlDomlist; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; }); + if (pProp != propList.end()) + pProp->Value >>= customXmlDomlist; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - OUString propName = propList[nProp].Name; - if ( propName == "OOXCustomXmlProps" ) - { - propList[nProp].Value >>= customXmlDomPropslist; - break; - } - } + pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXmlProps"; }); + if (pProp != propList.end()) + pProp->Value >>= customXmlDomPropslist; for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++) { @@ -1406,20 +1384,15 @@ void DocxExport::WriteEmbeddings() uno::Sequence< beans::PropertyValue > embeddingsList; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - OUString propName = propList[nProp].Name; - if ( propName == "OOXEmbeddings" ) - { - propList[nProp].Value >>= embeddingsList; - break; - } - } - for (sal_Int32 j = 0; j < embeddingsList.getLength(); j++) + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; }); + if (pProp != propList.end()) + pProp->Value >>= embeddingsList; + for (const auto& rEmbedding : embeddingsList) { - OUString embeddingPath = embeddingsList[j].Name; + OUString embeddingPath = rEmbedding.Name; uno::Reference<io::XInputStream> embeddingsStream; - embeddingsList[j].Value >>= embeddingsStream; + rEmbedding.Value >>= embeddingsStream; OUString contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // FIXME: this .xlsm hack is silly - if anything the mime-type for an existing embedded object should be read from [Content_Types].xml |