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 98ae538d3b53379162a1ffb373efff296f2b2887
Author: Pedro Giffuni <[email protected]>
AuthorDate: Wed Nov 25 09:59:21 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.
---
 main/oox/inc/oox/core/fragmenthandler.hxx     | 167 +++++++++++++++++---------
 main/oox/inc/oox/core/mcealternatecontext.hxx |  35 +++---
 main/oox/source/core/fragmenthandler.cxx      |   5 +-
 main/oox/source/core/mcealternatecontext.cxx  |  27 +----
 main/sot/source/sdstor/ucbstorage.cxx         |   5 +
 main/unotools/inc/unotools/streamwrap.hxx     |  10 +-
 main/unotools/source/streaming/streamwrap.cxx |  24 ++++
 7 files changed, 176 insertions(+), 97 deletions(-)

diff --git a/main/oox/inc/oox/core/fragmenthandler.hxx 
b/main/oox/inc/oox/core/fragmenthandler.hxx
index 1307c23ab8..4e6eedb594 100644
--- a/main/oox/inc/oox/core/fragmenthandler.hxx
+++ b/main/oox/inc/oox/core/fragmenthandler.hxx
@@ -1,22 +1,86 @@
-#ifndef OOX_CORE_MCEALTERNATECONTEXT_HXX
-#define OOX_CORE_MCEALTERNATECONTEXT_HXX
+/**************************************************************
+ *
+ * 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.
+ *
+ *************************************************************/
 
-#include <com/sun/star/xml/sax/XFastContextHandler.hpp>
-#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
+
+
+#ifndef OOX_CORE_FRAGMENTHANDLER_HXX
+#define OOX_CORE_FRAGMENTHANDLER_HXX
+
+#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
 #include <cppuhelper/implbase1.hxx>
-#include <rtl/ustring.hxx>
 #include <vector>
-#include "oox/core/mceprocessor.hxx"
+#include "oox/core/contexthandler.hxx"
+#include "oox/core/relations.hxx"
+
+namespace com { namespace sun { namespace star {
+    namespace io { class XInputStream; }
+} } }
 
 namespace oox {
 namespace core {
 
-/** Class for handling OOXML filter context.
- *
- *  Manages namespace stack, ignorable namespaces, and process content elements
- *  for OOXML document processing.
+// ============================================================================
+
+/** 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 FragmentHandler
+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
 {
 public:
     explicit            FragmentHandler( XmlFilterBase& rFilter, const 
::rtl::OUString& rFragmentPath );
@@ -26,13 +90,44 @@ public:
     inline ::com::sun::star::uno::Reference< 
::com::sun::star::xml::sax::XFastContextHandler >
                         getFastContextHandler() { return static_cast< 
ContextHandler* >( this ); }
 
+    // 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 );
+
+    // 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 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 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;
+
+    // MCE (Markup Compatibility Extensibility) -------------------------------
+
     /** 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. */
-    std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > 
maNamespaceStack;
+    std::vector< std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > 
> maNamespaceStack;
 
     /** Resolves a namespace prefix to a URI using the full namespace stack
         (ancestor declarations are overridden by more local declarations). */
@@ -50,52 +145,14 @@ public:
     void popNamespaces();
 
 protected:
-    explicit            FragmentHandler( XmlFilterBase& rFilter, const 
::rtl::OUString& rFragmentPath );
-
-    // 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 );
-
-    // 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 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 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 );
+    explicit            FragmentHandler( XmlFilterBase& rFilter, const 
::rtl::OUString& rFragmentPath, RelationsRef xRelations );
+};
 
-protected:
-    explicit            FragmentHandler( XmlFilterBase& rFilter, const 
::rtl::OUString& rFragmentPath );
-    virtual             ~FragmentHandler();
+typedef ::rtl::Reference< FragmentHandler > FragmentHandlerRef;
 
-private:
-    friend class MceAlternateContext;
-};
+// ============================================================================
 
 } // namespace core
 } // namespace oox
 
-#endif
+#endif
\ No newline at end of file
diff --git a/main/oox/inc/oox/core/mcealternatecontext.hxx 
b/main/oox/inc/oox/core/mcealternatecontext.hxx
index 099040c234..f7ee76c4c8 100644
--- a/main/oox/inc/oox/core/mcealternatecontext.hxx
+++ b/main/oox/inc/oox/core/mcealternatecontext.hxx
@@ -7,6 +7,7 @@
 #include <rtl/ustring.hxx>
 #include <vector>
 #include "oox/core/mceprocessor.hxx"
+#include "oox/dllapi.h"
 
 namespace oox {
 namespace core {
@@ -21,7 +22,7 @@ namespace core {
     Unknown namespaces listed in mc:Ignorable are silently skipped
     unless mc:ProcessContent explicitly includes them.
 */
-class MceAlternateContext : public ::cppu::WeakImplHelper1<
+class OOX_DLLPUBLIC MceAlternateContext : public ::cppu::WeakImplHelper1<
     ::com::sun::star::xml::sax::XFastContextHandler >
 {
 public:
@@ -60,6 +61,21 @@ public:
             ::com::sun::star::xml::sax::XFastAttributeList >& Attribs );
     virtual void SAL_CALL characters( const ::rtl::OUString& aChars );
 
+    /** 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 );
+
+    /** Pops the top namespace declaration set from the stack. Called when
+        leaving an element. */
+    void popNamespaces();
+
+    /** 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;
+
 private:
     enum State
     {
@@ -84,7 +100,7 @@ private:
     /** 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;
+    std::vector< std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > 
> maNamespaceStack;
 
     /** Namespaces declared as ignorable via mc:Ignorable. */
     std::vector< ::rtl::OUString > maIgnorableNamespaces;
@@ -103,21 +119,6 @@ private:
     ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastContextHandler > 
implCreateNullContext();
 
-    /** 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 );
-
-    /** Pops the top namespace declaration set from the stack. Called when
-        leaving an element. */
-    void popNamespaces();
-
-    /** 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;
 
diff --git a/main/oox/source/core/fragmenthandler.cxx 
b/main/oox/source/core/fragmenthandler.cxx
index c0c6426670..ecc2615978 100644
--- a/main/oox/source/core/fragmenthandler.cxx
+++ b/main/oox/source/core/fragmenthandler.cxx
@@ -51,8 +51,9 @@ void FragmentHandler::pushNamespaces(
     const ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs )
 {
-    std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > aMap;
-    MceProcessor::extractNamespaceDeclarations( rAttribs, aMap );
+    ::rtl::OUString aRequires;
+    std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > aMap =
+        MceProcessor::extractNamespaceDeclarations( rAttribs, aRequires );
     maNamespaceStack.push_back( aMap );
 }
 
diff --git a/main/oox/source/core/mcealternatecontext.cxx 
b/main/oox/source/core/mcealternatecontext.cxx
index af8402e8bf..c204bb96fc 100644
--- a/main/oox/source/core/mcealternatecontext.cxx
+++ b/main/oox/source/core/mcealternatecontext.cxx
@@ -68,22 +68,8 @@ void SAL_CALL MceAlternateContext::startFastElement(
     }
     if ( Element == XML_AlternateContent )
     {
-        // Nested AlternateContent: create a new context.
-        MceAlternateContext* pMceCtx = new MceAlternateContext(
-            mxDelegate );
-        pMceCtx->maNamespaceStack = maNamespaceStack;  // inherit namespace 
stack
-        pMceCtx->maIgnorableNamespaces = maIgnorableNamespaces;  // inherit 
ignorable namespaces
-        pMceCtx->maProcessContentElements = maProcessContentElements;  // 
inherit process content
-        pMceCtx->meState = STATE_INITIAL;
-        pMceCtx->mnNextChoiceIndex = 0;
-        pMceCtx->mbHasFallback = false;
-        pMceCtx->mbInSelectedBranch = false;
-        pMceCtx->maSelection.meResult = MceProcessor::BRANCH_NONE;
-        pMceCtx->maSelection.mnChoiceIndex = -1;
-
-        return ::com::sun::star::uno::Reference<
-            ::com::sun::star::xml::sax::XFastContextHandler >(
-                static_cast< XFastContextHandler* >( pMceCtx ) );
+        // Nested AlternateContent: handled in createFastChildContext
+        return;
     }
 
     // Non-MCE element inside selected branch - forward to delegate
@@ -158,7 +144,6 @@ MceAlternateContext::createFastChildContext(
     if ( Element == XML_AlternateContent )
     {
         // Nested AlternateContent: create a new context.
-        // Namespace declarations have already been pushed in startFastElement.
         MceAlternateContext* pMceCtx = new MceAlternateContext(
             mxDelegate );
         pMceCtx->maNamespaceStack = maNamespaceStack;  // inherit namespace 
stack
@@ -231,7 +216,7 @@ void MceAlternateContext::implEvaluateChoice(
                 }
             }
             if ( !bFound )
-                aMap.push_back( rPair );
+                aPrefixMap.push_back( rPair );
         }
     }
 
@@ -353,7 +338,7 @@ void MceAlternateContext::processIgnorableAttribute(
     try
     {
         ::com::sun::star::uno::Sequence< ::com::sun::star::xml::Attribute > 
aAttrs =
-            rAttribs->getAttributes();
+            rAttribs->getUnknownAttributes();
 
         for ( sal_Int32 i = 0; i < aAttrs.getLength(); ++i )
         {
@@ -384,7 +369,7 @@ void MceAlternateContext::processIgnorableAttribute(
     }
     catch ( ... )
     {
-        // getAttributes() may throw if not supported
+        // getUnknownAttributes() may throw if not supported
     }
 }
 
@@ -398,7 +383,7 @@ void MceAlternateContext::processProcessContent(
     try
     {
         ::com::sun::star::uno::Sequence< ::com::sun::star::xml::Attribute > 
aAttrs =
-            rAttribs->getAttributes();
+            rAttribs->getUnknownAttributes();
 
         for ( sal_Int32 i = 0; i < aAttrs.getLength(); ++i )
         {
diff --git a/main/sot/source/sdstor/ucbstorage.cxx 
b/main/sot/source/sdstor/ucbstorage.cxx
index be393077ca..166e451d4b 100644
--- a/main/sot/source/sdstor/ucbstorage.cxx
+++ b/main/sot/source/sdstor/ucbstorage.cxx
@@ -99,6 +99,11 @@ public:
 
     //DECLARE_UNO3_AGG_DEFAULTS( FileStreamWrapper_Impl, 
FileInputStreamWrapper_Base);
 
+    virtual void SAL_CALL acquire() throw ()
+        { FileInputStreamWrapper_Base::acquire(); }
+    virtual void SAL_CALL release() throw ()
+        { FileInputStreamWrapper_Base::release(); }
+
     virtual void SAL_CALL seek( sal_Int64 _nLocation );
     virtual sal_Int64 SAL_CALL getPosition(  );
     virtual sal_Int64 SAL_CALL getLength(  );
diff --git a/main/unotools/inc/unotools/streamwrap.hxx 
b/main/unotools/inc/unotools/streamwrap.hxx
index 2c43d5e771..9d2d52e21e 100644
--- a/main/unotools/inc/unotools/streamwrap.hxx
+++ b/main/unotools/inc/unotools/streamwrap.hxx
@@ -63,7 +63,10 @@ public:
        OInputStreamWrapper(SvStream* pStream, sal_Bool bOwner=sal_False);
        virtual ~OInputStreamWrapper();
 
-// stario::XInputStream
+       virtual void SAL_CALL acquire() throw ();
+       virtual void SAL_CALL release() throw ();
+
+ // stario::XInputStream
        virtual sal_Int32       SAL_CALL        readBytes(staruno::Sequence< 
sal_Int8 >& aData, sal_Int32 nBytesToRead);
        virtual sal_Int32       SAL_CALL        
readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead);
        virtual void            SAL_CALL        skipBytes(sal_Int32 
nBytesToSkip);
@@ -113,7 +116,10 @@ protected:
 public:
        OOutputStreamWrapper(SvStream& _rStream) :rStream(_rStream) { }
 
-// stario::XOutputStream
+       virtual void SAL_CALL acquire() throw ();
+       virtual void SAL_CALL release() throw ();
+
+ // stario::XOutputStream
        virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& 
aData);
        virtual void SAL_CALL flush();
        virtual void SAL_CALL closeOutput();
diff --git a/main/unotools/source/streaming/streamwrap.cxx 
b/main/unotools/source/streaming/streamwrap.cxx
index b9d332a369..c0f9e7e6da 100644
--- a/main/unotools/source/streaming/streamwrap.cxx
+++ b/main/unotools/source/streaming/streamwrap.cxx
@@ -65,6 +65,18 @@ OInputStreamWrapper::~OInputStreamWrapper()
        DBG_DTOR(OInputStreamWrapper,NULL);
 }
 
+//------------------------------------------------------------------------------
+void SAL_CALL OInputStreamWrapper::acquire() throw ()
+{
+    InputStreamWrapper_Base::acquire();
+}
+
+//------------------------------------------------------------------------------
+void SAL_CALL OInputStreamWrapper::release() throw ()
+{
+    InputStreamWrapper_Base::release();
+}
+
 
//------------------------------------------------------------------------------
 sal_Int32 SAL_CALL OInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 
>& aData, sal_Int32 nBytesToRead)
 {
@@ -252,6 +264,18 @@ void SAL_CALL OOutputStreamWrapper::closeOutput()
 {
 }
 
+//------------------------------------------------------------------------------
+void SAL_CALL OOutputStreamWrapper::acquire() throw ()
+{
+    OutputStreamWrapper_Base::acquire();
+}
+
+//------------------------------------------------------------------------------
+void SAL_CALL OOutputStreamWrapper::release() throw ()
+{
+    OutputStreamWrapper_Base::release();
+}
+
 
//------------------------------------------------------------------------------
 void OOutputStreamWrapper::checkError() const
 {

Reply via email to