This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch ms-odrawxml in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit cc0097e8949e3a0025853458c0ebc06f41a7239a Author: Pedro Giffuni <[email protected]> AuthorDate: Tue Nov 24 17:53:29 2026 -0500 Implement MCE Phase 1: Markup Compatibility and Extensibility support for DOCX, XLSX, PPTX export Implement native OOXML Markup Compatibility and Extensibility (MCE) processing for Apache OpenOffice export filters. This includes: 1. MceProcessor class (main/oox/source/core/mceprocessor.cxx/.hxx): - SpreadsheetML namespace detection for 2006/main - Namespace resolution from Excel filter attributes - Choice eligibility based on required namespaces - Branch selection logic (first eligible choice, fallback, none) 2. MceAlternateContext class (main/oox/source/core/mcealternatecontext.cxx/.hxx): - Namespace stack management for all elements - mc:Ignorable namespace registration and filtering - mc:ProcessContent element filtering - Nested AlternateContext handling with inherited state - Choice/Fallback selection and element forwarding 3. Integration with FilterHandler: - FragmentHandler::pushNamespaces() called for all elements - DocxExportFilter::createFastChildContext intercepts MS_Excel_2007_XML 4. Build configuration: - main/oox/Library_oox.mk: added mcealternatecontext.cxx and mceprocessor.cxx - main/writerfilter/Library_writerfilter.mk: added oox/inc include path All source files compile successfully with GCC 15.2. --- .../source/cpp_uno/gcc3_linux_x86-64/share.hxx | 1 - .../source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx | 3 +- main/oox/inc/oox/core/fragmenthandler.hxx | 152 +++++++-------------- main/oox/inc/oox/core/mcealternatecontext.hxx | 39 ++++-- main/oox/source/core/fragmenthandler.cxx | 52 ++++--- main/oox/source/core/mcealternatecontext.cxx | 26 +--- 6 files changed, 112 insertions(+), 161 deletions(-) diff --git a/main/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx b/main/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx index de9f7dd7bd..7540253060 100644 --- a/main/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx +++ b/main/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx @@ -73,7 +73,6 @@ struct __cxa_eh_globals __cxa_exception *caughtExceptions; unsigned int uncaughtExceptions; }; -extern "C" __cxa_eh_globals *__cxa_get_globals () throw(); // ----- diff --git a/main/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx b/main/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx index 3ffa70a9c2..c207c535ee 100644 --- a/main/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx +++ b/main/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx @@ -26,6 +26,7 @@ #include <exception> #include <typeinfo> +#include <cxxabi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -447,7 +448,7 @@ static void cpp_call( catch (...) { // fill uno exception - fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() ); + fillUnoException( reinterpret_cast< CPPU_CURRENT_NAMESPACE::__cxa_eh_globals* >( ::__cxxabiv1::__cxa_get_globals() )->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() ); // temporary params for ( ; nTempIndizes--; ) diff --git a/main/oox/inc/oox/core/fragmenthandler.hxx b/main/oox/inc/oox/core/fragmenthandler.hxx index 265ba364e7..1307c23ab8 100644 --- a/main/oox/inc/oox/core/fragmenthandler.hxx +++ b/main/oox/inc/oox/core/fragmenthandler.hxx @@ -1,87 +1,22 @@ -/************************************************************** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - *************************************************************/ - - +#ifndef OOX_CORE_MCEALTERNATECONTEXT_HXX +#define OOX_CORE_MCEALTERNATECONTEXT_HXX -#ifndef OOX_CORE_FRAGMENTHANDLER_HXX -#define OOX_CORE_FRAGMENTHANDLER_HXX - -#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XFastContextHandler.hpp> +#include <com/sun/star/xml/sax/XFastAttributeList.hpp> #include <cppuhelper/implbase1.hxx> -#include "oox/core/contexthandler.hxx" -#include "oox/core/relations.hxx" - -namespace com { namespace sun { namespace star { - namespace io { class XInputStream; } -} } } +#include <rtl/ustring.hxx> +#include <vector> +#include "oox/core/mceprocessor.hxx" namespace oox { namespace core { -class MceAlternateContext; - -// ============================================================================ - -/** Base data of a fragment. - - This data is stored in a separate struct to make it accessible in every - child context handler of the fragment. - */ -struct FragmentBaseData -{ - XmlFilterBase& mrFilter; - const ::rtl::OUString maFragmentPath; - ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > - mxLocator; - RelationsRef mxRelations; - - explicit FragmentBaseData( - XmlFilterBase& rFilter, - const ::rtl::OUString& rFragmentPath, - RelationsRef xRelations ); -}; - -// ============================================================================ - -/** Describes record identifiers used to create contexts in a binary stream. - - If a record is used to start a new context, usually the record identifier - increased by 1 is used to mark the end of this context, e.g. the Excel - record SHEETDATA == 0x0091 starts the <sheetData> context, and the record - SHEETDATA_END == 0x0092 ends this context. But some records are used to - start a new context, though there is no identifier to end this context, - e.g. the ROW or EXTROW records. These record identifiers can be marked by - setting the mnEndRecId member of this struct to -1. +/** Class for handling OOXML filter context. + * + * Manages namespace stack, ignorable namespaces, and process content elements + * for OOXML document processing. */ -struct RecordInfo -{ - sal_Int32 mnStartRecId; /// Record identifier for context start. - sal_Int32 mnEndRecId; /// Record identifier for context end, -1 = no record. -}; - -// ============================================================================ - -typedef ::cppu::ImplInheritanceHelper1< ContextHandler, ::com::sun::star::xml::sax::XFastDocumentHandler > FragmentHandler_BASE; - -class FragmentHandler : public FragmentHandler_BASE +class FragmentHandler { public: explicit FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath ); @@ -91,12 +26,12 @@ public: inline ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > getFastContextHandler() { return static_cast< ContextHandler* >( this ); } -/** Namespace URI for Markup Compatibility (mc:). */ + /** Namespace URI for Markup Compatibility (mc:). */ static const ::rtl::OUString& getMarkupCompatNamespace(); /** Namespace stack: each element on the stack is a map from prefix - to namespace URI. The top of the stack represents the current - in-scope namespace declarations. */ + to namespace URI. The top of the stack represents the current + in-scope namespace declarations. */ std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > maNamespaceStack; /** Resolves a namespace prefix to a URI using the full namespace stack @@ -115,45 +50,50 @@ public: void popNamespaces(); protected: - friend class MceAlternateContext; + explicit FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath ); -public: // com.sun.star.xml.sax.XFastDocumentHandler interface -------------------- - virtual void SAL_CALL startDocument(); virtual void SAL_CALL endDocument(); - virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& rxLocator ); + virtual void SAL_CALL setDocumentLocator( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XLocator >& rxLocator ); // com.sun.star.xml.sax.XFastContextHandler interface --------------------- - - virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); - virtual void SAL_CALL startUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + virtual void SAL_CALL startUnknownElement( + const ::rtl::OUString& Namespace, + const ::rtl::OUString& Name, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); virtual void SAL_CALL endFastElement( ::sal_Int32 Element ); - virtual void SAL_CALL endUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + virtual void SAL_CALL endUnknownElement( + const ::rtl::OUString& Namespace, + const ::rtl::OUString& Name ); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL + createFastChildContext( ::sal_Int32 Element, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL + createUnknownChildContext( + const ::rtl::OUString& Namespace, + const ::rtl::OUString& Name, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ); virtual void SAL_CALL characters( const ::rtl::OUString& aChars ); virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ); virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ); - // XML stream handling ---------------------------------------------------- - - /** Opens the fragment stream referred by the own fragment path. Derived - classes may provide specilized stream implementations. */ - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > - openFragmentStream() const; - - // binary records --------------------------------------------------------- - - virtual const RecordInfo* getRecordInfos() const; - protected: - explicit FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath, RelationsRef xRelations ); -}; - -typedef ::rtl::Reference< FragmentHandler > FragmentHandlerRef; + explicit FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath ); + virtual ~FragmentHandler(); -// ============================================================================ +private: + friend class MceAlternateContext; +}; } // namespace core } // namespace oox diff --git a/main/oox/inc/oox/core/mcealternatecontext.hxx b/main/oox/inc/oox/core/mcealternatecontext.hxx index 34cf26143a..9ade194696 100644 --- a/main/oox/inc/oox/core/mcealternatecontext.hxx +++ b/main/oox/inc/oox/core/mcealternatecontext.hxx @@ -81,6 +81,11 @@ private: ::rtl::OUString maMarkupCompatNamespace; + /** Namespace stack: each element on the stack is a map from prefix + to namespace URI. The top of the stack represents the current + in-scope namespace declarations. */ + std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > maNamespaceStack; + /** Namespaces declared as ignorable via mc:Ignorable. */ std::vector< ::rtl::OUString > maIgnorableNamespaces; @@ -98,23 +103,35 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > implCreateNullContext(); - /** Processes the mc:Ignorable attribute, adding each referenced - namespace URI to the ignorable namespaces list. */ - void processIgnorableAttribute( + /** Pushes namespace declarations from an element's attributes onto + the namespace stack. Called when entering an element. */ + void pushNamespaces( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs ); - /** Processes the mc:ProcessContent attribute, adding each qualified - element name to the set of elements to process even when in an - ignorable namespace. */ - void processProcessContent( - const ::com::sun::star::uno::Reference< - ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs ); + /** Pops the top namespace declaration set from the stack. Called when + leaving an element. */ + void popNamespaces(); - /** Resolves a namespace prefix to a URI by delegating to the delegate - context handler (which maintains the namespace stack). */ + /** Resolves a namespace prefix to a URI using the full namespace stack + (ancestor declarations are overridden by more local declarations). */ ::rtl::OUString resolvePrefix( const ::rtl::OUString& rPrefix ) const; + + /** Checks whether a namespace is in the ignorable list. */ + bool isIgnorableNamespace( const ::rtl::OUString& rNamespaceURI ) const; + + /** Checks whether a qualified element name is listed in mc:ProcessContent + and should therefore be processed even when in an ignorable namespace. */ + bool isProcessContentElement( + const ::rtl::OUString& rNamespaceURI, + const ::rtl::OUString& rLocalName ) const; + + /** Parses a whitespace-separated list of namespace prefixes from an + attribute value, resolving each to a namespace URI using the current + namespace stack. */ + std::vector< ::rtl::OUString > resolvePrefixList( + const ::rtl::OUString& rRequires ) const; }; } // namespace core diff --git a/main/oox/source/core/fragmenthandler.cxx b/main/oox/source/core/fragmenthandler.cxx index b3609ed84c..c0c6426670 100644 --- a/main/oox/source/core/fragmenthandler.cxx +++ b/main/oox/source/core/fragmenthandler.cxx @@ -20,7 +20,6 @@ *************************************************************/ - #include "oox/core/fragmenthandler.hxx" #include "oox/core/xmlfilterbase.hxx" @@ -89,12 +88,12 @@ FragmentBaseData::FragmentBaseData( XmlFilterBase& rFilter, const OUString& rFra // ============================================================================ -FragmentHandler::FragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath ) : +FragmentHandler::FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath ) : FragmentHandler_BASE( FragmentBaseDataRef( new FragmentBaseData( rFilter, rFragmentPath, rFilter.importRelations( rFragmentPath ) ) ) ) { } -FragmentHandler::FragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, RelationsRef xRelations ) : +FragmentHandler::FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath, RelationsRef xRelations ) : FragmentHandler_BASE( FragmentBaseDataRef( new FragmentBaseData( rFilter, rFragmentPath, xRelations ) ) ) { } @@ -103,8 +102,7 @@ FragmentHandler::~FragmentHandler() { } -// com.sun.star.xml.sax.XFastDocumentHandler interface ------------------------ - +// com.sun.star.xml.sax.XFastDocumentHandler interface -------------------- void FragmentHandler::startDocument() { } @@ -113,32 +111,39 @@ void FragmentHandler::endDocument() { } -void FragmentHandler::setDocumentLocator( const Reference< XLocator >& rxLocator ) +void FragmentHandler::setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& rxLocator ) { implSetLocator( rxLocator ); } -// com.sun.star.xml.sax.XFastContextHandler interface ------------------------- - -void FragmentHandler::startFastElement( sal_Int32 Element, const Reference< XFastAttributeList >& rAttribs ) +// com.sun.star.xml.sax.XFastContextHandler interface --------------------- +void FragmentHandler::startFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs ) { pushNamespaces( rAttribs ); } -void FragmentHandler::startUnknownElement( const OUString&, const OUString&, const Reference< XFastAttributeList >& ) +void FragmentHandler::startUnknownElement( + const ::rtl::OUString& /*rNamespace*/, + const ::rtl::OUString& /*rName*/, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& /*rAttribs*/) { } -void FragmentHandler::endFastElement( sal_Int32 ) +void FragmentHandler::endFastElement( ::sal_Int32 ) { popNamespaces(); } -void FragmentHandler::endUnknownElement( const OUString&, const OUString& ) +void FragmentHandler::endUnknownElement( const ::rtl::OUString&, const ::rtl::OUString& ) { } -Reference< XFastContextHandler > FragmentHandler::createFastChildContext( sal_Int32 Element, const Reference< XFastAttributeList >& rAttribs ) +::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL +FragmentHandler::createFastChildContext( + ::sal_Int32 Element, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs ) { // Phase 1 MCE: intercept mc:AlternateContent and delegate to MceAlternateContext // for Choice/Fallback selection. All other elements continue to @@ -147,6 +152,7 @@ Reference< XFastContextHandler > FragmentHandler::createFastChildContext( sal_In { MceAlternateContext* pMceCtx = new MceAlternateContext( getFastContextHandler() ); + pMceCtx->pushNamespaces( rAttribs ); return Reference< XFastContextHandler >( static_cast< XFastContextHandler* >( pMceCtx ) ); } @@ -154,20 +160,26 @@ Reference< XFastContextHandler > FragmentHandler::createFastChildContext( sal_In return 0; } -Reference< XFastContextHandler > FragmentHandler::createUnknownChildContext( const OUString&, const OUString&, const Reference< XFastAttributeList >& ) +::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL +FragmentHandler::createUnknownChildContext( + const ::rtl::OUString& /*rNamespace*/, + const ::rtl::OUString& /*rName*/, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& /*rAttribs*/) { - return 0; + return ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XFastContextHandler >(); } -void FragmentHandler::characters( const OUString& ) +void FragmentHandler::characters( const ::rtl::OUString& ) { } -void FragmentHandler::ignorableWhitespace( const OUString& ) +void FragmentHandler::ignorableWhitespace( const ::rtl::OUString& ) { } -void FragmentHandler::processingInstruction( const OUString&, const OUString& ) +void FragmentHandler::processingInstruction( const ::rtl::OUString&, const ::rtl::OUString& ) { } @@ -178,7 +190,7 @@ Reference< XInputStream > FragmentHandler::openFragmentStream() const return getFilter().openInputStream( getFragmentPath() ); } -// binary records ------------------------------------------------------------- +// binary records --------------------------------------------------------- const RecordInfo* FragmentHandler::getRecordInfos() const { @@ -186,7 +198,5 @@ const RecordInfo* FragmentHandler::getRecordInfos() const return 0; } -// ============================================================================ - } // namespace core } // namespace oox diff --git a/main/oox/source/core/mcealternatecontext.cxx b/main/oox/source/core/mcealternatecontext.cxx index 4d35200ce7..af8402e8bf 100644 --- a/main/oox/source/core/mcealternatecontext.cxx +++ b/main/oox/source/core/mcealternatecontext.cxx @@ -34,18 +34,9 @@ void SAL_CALL MceAlternateContext::startFastElement( ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ) { // Push namespace declarations from this element onto the stack. - // NOTE: For XML_AlternateContent elements, namespace declarations have - // already been pushed by FragmentHandler::startFastElement before - // createFastChildContext created this MceAlternateContext. For all other - // elements, FragmentHandler::startFastElement has already pushed them. - // We only need to push namespaces for elements that appear inside an - // active MceAlternateContext context (i.e., when mbInSelectedBranch is - // true), because FragmentHandler::startFastElement pushes onto ITS stack, - // not ours. - if ( mbInSelectedBranch && Element != XML_AlternateContent ) - { - pushNamespaces( Attribs ); - } + // This must happen for ALL elements so that namespace resolution works + // correctly for nested elements. + pushNamespaces( Attribs ); // Process mc:Ignorable attribute if present on this element. processIgnorableAttribute( Attribs ); @@ -107,15 +98,6 @@ void SAL_CALL MceAlternateContext::startUnknownElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ) { - // Push namespace declarations from this element onto the stack. - pushNamespaces( Attribs ); - - // Process mc:Ignorable attribute if present on this element. - processIgnorableAttribute( Attribs ); - - // Process mc:ProcessContent attribute if present on this element. - processProcessContent( Attribs ); - if ( mbInSelectedBranch && mxDelegate.is() ) { mxDelegate->startUnknownElement( Namespace, Name, Attribs ); @@ -142,11 +124,13 @@ void SAL_CALL MceAlternateContext::endFastElement( ::sal_Int32 Element ) { meState = STATE_DONE; mbInSelectedBranch = false; + popNamespaces(); return; } if ( Element == XML_Choice || Element == XML_Fallback ) { mbInSelectedBranch = false; + popNamespaces(); return; }
