Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit f245caf

Browse files
danielkweonChase
andauthored
Downloaded Files aren't opening in word (#101)
* M-1090 - Fix docx relationship export document.xml.rels prevent duplicates and keep webSettings + stylesWithEffects Clear customXML/itemN.xml.rels before writing QA env: Ignore folders when unzipping docx files * Bump version --------- Co-authored-by: Chase <[email protected]>
1 parent da1a97b commit f245caf

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.2.0
1+
v0.2.1

libreoffice-core/include/oox/core/xmlfilterbase.hxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ public:
175175
*/
176176
OUString addRelation( const css::uno::Reference< css::io::XOutputStream >& rOutputStream, const OUString& rType, std::u16string_view rTarget, bool bExternal = false );
177177

178+
// MACRO: M-1090 Fix custom XML relations {
179+
void clearRelations(const css::uno::Reference<css::io::XOutputStream>& rOutputStream);
180+
181+
bool hasRelWithType(const css::uno::Reference<css::io::XOutputStream>& rOutputStream,
182+
const OUString& type);
183+
// MACRO: }
184+
178185
/** Opens and returns the specified output stream from the base storage with specified media type.
179186
180187
@param rStreamName

libreoffice-core/include/oox/token/relationship.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ enum class Relationship
6565
AUDIO,
6666
VMLDRAWING,
6767
WORDVBADATA,
68-
WORKSHEET
68+
WORKSHEET,
69+
// MACRO: Fix docx export {
70+
STYLESWITHEFFECTS,
71+
WEBSETTINGS,
72+
// MACRO: }
6973
};
7074

7175
OUString OOX_DLLPUBLIC getRelationship(Relationship eRelationship);

libreoffice-core/oox/source/core/xmlfilterbase.cxx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,36 @@ OUString XmlFilterBase::addRelation( const Reference< XOutputStream >& rOutputSt
561561
return OUString();
562562
}
563563

564+
// MACRO: M-1090 Fix custom XML relations {
565+
void XmlFilterBase::clearRelations(const Reference<XOutputStream>& rOutputStream)
566+
{
567+
Reference<XRelationshipAccess> xRelations(rOutputStream, UNO_QUERY);
568+
if (xRelations.is())
569+
xRelations->clearRelationships();
570+
}
571+
572+
bool XmlFilterBase::hasRelWithType(const css::uno::Reference<css::io::XOutputStream>& rOutputStream,
573+
const OUString& type)
574+
{
575+
Reference<XRelationshipAccess> xRelations(rOutputStream, UNO_QUERY);
576+
577+
if (xRelations.is())
578+
{
579+
try
580+
{
581+
auto relationships = xRelations->getRelationshipsByType(type);
582+
return relationships.getLength() > 0;
583+
}
584+
catch (const Exception&)
585+
{
586+
return false;
587+
}
588+
}
589+
590+
return false;
591+
}
592+
// MACRO: M-1090 Fix custom XML relations }
593+
564594
static void
565595
writeElement( const FSHelperPtr& pDoc, sal_Int32 nXmlElement, std::u16string_view sValue )
566596
{

libreoffice-core/oox/source/token/relationship.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@
4545
{Relationship::AUDIO, u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/audio"},
4646
{Relationship::VMLDRAWING, u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"},
4747
{Relationship::WORDVBADATA, u"http://schemas.microsoft.com/office/2006/relationships/wordVbaData"},
48-
{Relationship::WORKSHEET, u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}
48+
{Relationship::WORKSHEET, u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"},
49+
{Relationship::STYLESWITHEFFECTS, u"http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects"},
50+
{Relationship::WEBSETTINGS, u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"}

libreoffice-core/sw/source/filter/ww8/docxexport.cxx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,16 @@ void DocxExport::InitStyles()
675675
{
676676
m_pStyles.reset(new MSWordStyles( *this, /*bListStyles =*/ true ));
677677

678+
// MACRO: M-1090 Fix docx export {
679+
const bool hasWebSettings
680+
= m_rFilter.hasRelWithType(m_pDocumentFS->getOutputStream(), u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"_ustr);
681+
682+
const bool hasStylesWithEffects
683+
= m_rFilter.hasRelWithType(m_pDocumentFS->getOutputStream(), u"http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects"_ustr);
684+
685+
m_rFilter.clearRelations(m_pDocumentFS->getOutputStream());
686+
687+
// MACRO: M-1090 }
678688
// setup word/styles.xml and the relations + content type
679689
m_rFilter.addRelation( m_pDocumentFS->getOutputStream(),
680690
oox::getRelationship(Relationship::STYLES),
@@ -694,6 +704,20 @@ void DocxExport::InitStyles()
694704
m_pAttrOutput->SetSerializer( m_pDocumentFS );
695705

696706
pStylesFS->endDocument();
707+
708+
// MACRO: M-1090 Fix docx export {
709+
if (hasStylesWithEffects)
710+
{
711+
m_rFilter.addRelation(m_pDocumentFS->getOutputStream(),
712+
oox::getRelationship(Relationship::STYLESWITHEFFECTS),
713+
u"stylesWithEffects.xml");
714+
}
715+
if (hasWebSettings)
716+
{
717+
m_rFilter.addRelation(m_pDocumentFS->getOutputStream(),
718+
oox::getRelationship(Relationship::WEBSETTINGS), u"webSettings.xml");
719+
}
720+
// MACRO: M-1090 }
697721
}
698722

699723
void DocxExport::WriteFootnotesEndnotes()
@@ -1692,6 +1716,10 @@ void DocxExport::WriteCustomXml()
16921716

16931717
for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++)
16941718
{
1719+
// MACRO: M-1090 Fix docx export {
1720+
m_rFilter.clearRelations(GetFilter().openFragmentStream(
1721+
"customXml/item" + OUString::number(j + 1) + ".xml", "application/xml"));
1722+
// MACRO: M-1090 }
16951723
uno::Reference<xml::dom::XDocument> customXmlDom = customXmlDomlist[j];
16961724
uno::Reference<xml::dom::XDocument> customXmlDomProps = customXmlDomPropslist[j];
16971725
if (customXmlDom.is())

qa-env/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export function downloadFile(name: string, buffer: ArrayBuffer, type: string) {
1717
export async function unzipDocxFile(blob: Blob): Promise<Array<{path: string, content: ArrayBuffer}>> {
1818
const zip = await JsZip.loadAsync(blob);
1919

20-
const files = Promise.all(Object.keys(zip.files).map(async (key) => {
20+
const files = Promise.all(Object.keys(zip.files)
21+
.filter((key) => !zip.files[key].dir)
22+
.map(async (key) => {
2123
const file = zip.files[key];
2224
return {
2325
path: key,

0 commit comments

Comments
 (0)