[Libreoffice-commits] .: 2 commits - oox/inc oox/source
Muthu Subramanian
sumuthu at kemper.freedesktop.org
Tue May 3 09:56:31 PDT 2011
oox/inc/oox/core/contexthandler2.hxx | 6 ++-
oox/inc/oox/core/fastparser.hxx | 5 ++
oox/inc/oox/core/fragmenthandler2.hxx | 15 +++++++-
oox/inc/oox/core/xmlfilterbase.hxx | 4 ++
oox/source/core/contexthandler2.cxx | 15 ++++++--
oox/source/core/fastparser.cxx | 15 ++++++++
oox/source/core/fragmenthandler2.cxx | 60 +++++++++++++++++++++++++++++++++-
oox/source/core/xmlfilterbase.cxx | 12 ++++++
oox/source/token/namespaces.hxx.tail | 1
oox/source/token/namespaces.txt | 2 +
oox/source/token/tokens.txt | 5 ++
11 files changed, 133 insertions(+), 7 deletions(-)
New commits:
commit ca510d87773851560507afbf3de50443192a8e4d
Author: Muthu Subramanian <sumuthu at novell.com>
Date: Tue May 3 22:31:56 2011 +0530
Reverting some file mode changes with previous commit.
diff --git a/oox/source/core/fastparser.cxx b/oox/source/core/fastparser.cxx
old mode 100755
new mode 100644
diff --git a/oox/source/token/namespaces.hxx.tail b/oox/source/token/namespaces.hxx.tail
old mode 100755
new mode 100644
commit 9a76531359ff18398df073f28aee2cd26993c79e
Author: Muthu Subramanian <sumuthu at novell.com>
Date: Tue May 3 22:27:29 2011 +0530
MCE Initial Implementation.
Points to note:
* Assumes all MCE content to be of 'Ignorable' type.
Handling other types needs to be implemented.
* Uses the first acceptable choice and parses the
content. Skips the others. E.g. assuming v2 and v3
both being acceptable and v3 being newer/better, if
the choice for v2 is stored first. v3 is skipped.
diff --git a/oox/inc/oox/core/contexthandler2.hxx b/oox/inc/oox/core/contexthandler2.hxx
index d434050..4c61d91 100644
--- a/oox/inc/oox/core/contexthandler2.hxx
+++ b/oox/inc/oox/core/contexthandler2.hxx
@@ -144,9 +144,12 @@ public:
// helpers ----------------------------------------------------------------
- /** Returns the identifier of the currently processed element. */
+ /** Returns the identifier of the currently processed element. Ignores MCE elements in stack */
sal_Int32 getCurrentElement() const;
+ /** Returns the identifier of the currently processed element - Including MCE root elements */
+ sal_Int32 getCurrentElementWithMce() const;
+
/** Returns true, if nElement contains the identifier of the currently
processed element. */
inline bool isCurrentElement( sal_Int32 nElement ) const
@@ -274,4 +277,4 @@ public:
#endif
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/inc/oox/core/fastparser.hxx b/oox/inc/oox/core/fastparser.hxx
index ad5555d..9b6bb4d 100644
--- a/oox/inc/oox/core/fastparser.hxx
+++ b/oox/inc/oox/core/fastparser.hxx
@@ -79,6 +79,11 @@ public:
void parseStream( StorageBase& rStorage, const ::rtl::OUString& rStreamName, bool bCloseStream = false )
throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
+ ::rtl::OUString getNamespaceURL( const ::rtl::OUString& rPrefix )
+ throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
+
+ sal_Int32 getNamespaceId( const ::rtl::OUString& aUrl );
+
private:
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastParser >
mxParser;
diff --git a/oox/inc/oox/core/fragmenthandler2.hxx b/oox/inc/oox/core/fragmenthandler2.hxx
index 0a718ef..b6a6139 100644
--- a/oox/inc/oox/core/fragmenthandler2.hxx
+++ b/oox/inc/oox/core/fragmenthandler2.hxx
@@ -31,6 +31,7 @@
#include "oox/core/contexthandler2.hxx"
#include "oox/core/fragmenthandler.hxx"
+#include <vector>
namespace oox {
namespace core {
@@ -39,6 +40,19 @@ namespace core {
class FragmentHandler2 : public FragmentHandler, public ContextHandler2Helper
{
+private:
+ enum MCE_STATE
+ {
+ MCE_UNUSED,
+ MCE_STARTED,
+ MCE_FOUND_CHOICE
+ };
+ ::std::vector<MCE_STATE> aMceState;
+
+private:
+ bool prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs );
+
+
public:
explicit FragmentHandler2(
XmlFilterBase& rFilter,
@@ -113,4 +127,4 @@ public:
#endif
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/inc/oox/core/xmlfilterbase.hxx b/oox/inc/oox/core/xmlfilterbase.hxx
index eb809c3..478b169 100644
--- a/oox/inc/oox/core/xmlfilterbase.hxx
+++ b/oox/inc/oox/core/xmlfilterbase.hxx
@@ -204,6 +204,10 @@ public:
*/
XmlFilterBase& exportDocumentProperties( ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xProperties );
+ ::rtl::OUString getNamespaceURL( const ::rtl::OUString& rPrefix );
+
+ sal_Int32 getNamespaceId( const ::rtl::OUString& rUrl );
+
void importDocumentProperties() throw();
protected:
diff --git a/oox/source/core/contexthandler2.cxx b/oox/source/core/contexthandler2.cxx
index 61c5266..d3f06a7 100644
--- a/oox/source/core/contexthandler2.cxx
+++ b/oox/source/core/contexthandler2.cxx
@@ -74,11 +74,20 @@ ContextHandler2Helper::~ContextHandler2Helper()
{
}
-sal_Int32 ContextHandler2Helper::getCurrentElement() const
+sal_Int32 ContextHandler2Helper::getCurrentElementWithMce() const
{
return mxContextStack->empty() ? XML_ROOT_CONTEXT : mxContextStack->back().mnElement;
}
+sal_Int32 ContextHandler2Helper::getCurrentElement() const
+{
+ for ( ContextStack::const_reverse_iterator It = mxContextStack->rbegin();
+ It != mxContextStack->rend(); It++ )
+ if( getNamespace( It->mnElement ) != NMSP_mce )
+ return It->mnElement;
+ return XML_ROOT_CONTEXT;
+}
+
sal_Int32 ContextHandler2Helper::getParentElement( sal_Int32 nCountBack ) const
{
if( (nCountBack < 0) || (mxContextStack->size() < static_cast< size_t >( nCountBack )) )
@@ -118,7 +127,7 @@ void ContextHandler2Helper::implCharacters( const OUString& rChars )
void ContextHandler2Helper::implEndElement( sal_Int32 nElement )
{
(void)nElement; // prevent "unused parameter" warning in product build
- OSL_ENSURE( getCurrentElement() == nElement, "ContextHandler2Helper::implEndElement - context stack broken" );
+ OSL_ENSURE( getCurrentElementWithMce() == nElement, "ContextHandler2Helper::implEndElement - context stack broken" );
if( !mxContextStack->empty() )
{
// #i76091# process collected characters (calls onCharacters() if needed)
@@ -142,7 +151,7 @@ void ContextHandler2Helper::implStartRecord( sal_Int32 nRecId, SequenceInputStre
void ContextHandler2Helper::implEndRecord( sal_Int32 nRecId )
{
(void)nRecId; // prevent "unused parameter" warning in product build
- OSL_ENSURE( getCurrentElement() == nRecId, "ContextHandler2Helper::implEndRecord - context stack broken" );
+ OSL_ENSURE( getCurrentElementWithMce() == nRecId, "ContextHandler2Helper::implEndRecord - context stack broken" );
if( !mxContextStack->empty() )
{
onEndRecord();
diff --git a/oox/source/core/fastparser.cxx b/oox/source/core/fastparser.cxx
old mode 100644
new mode 100755
index f14550b..718925e
--- a/oox/source/core/fastparser.cxx
+++ b/oox/source/core/fastparser.cxx
@@ -130,6 +130,21 @@ void FastParser::parseStream( StorageBase& rStorage, const OUString& rStreamName
parseStream( rStorage.openInputStream( rStreamName ), rStreamName, bCloseStream );
}
+OUString FastParser::getNamespaceURL( const OUString& rPrefix ) throw( IllegalArgumentException, RuntimeException )
+{
+ if( !mxParser.is() )
+ throw RuntimeException();
+ return mxParser->getNamespaceURL( rPrefix );
+}
+
+sal_Int32 FastParser::getNamespaceId( const OUString& rUrl )
+{
+ for( NamespaceMap::const_iterator aIt = mrNamespaceMap.begin(), aEnd = mrNamespaceMap.end(); aIt != aEnd; ++aIt )
+ if( rUrl == aIt->second )
+ return aIt->first;
+ return 0;
+}
+
// ============================================================================
} // namespace core
diff --git a/oox/source/core/fragmenthandler2.cxx b/oox/source/core/fragmenthandler2.cxx
index fb053d0..a42778e 100644
--- a/oox/source/core/fragmenthandler2.cxx
+++ b/oox/source/core/fragmenthandler2.cxx
@@ -27,6 +27,7 @@
************************************************************************/
#include "oox/core/fragmenthandler2.hxx"
+#include "oox/core/xmlfilterbase.hxx"
namespace oox {
namespace core {
@@ -38,6 +39,9 @@ using namespace ::com::sun::star::xml::sax;
using ::rtl::OUString;
+
+using ::com::sun::star::uno::Sequence;
+
// ============================================================================
FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
@@ -62,11 +66,58 @@ void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeExcept
finalizeImport();
}
+bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
+{
+ switch( nElement )
+ {
+ case MCE_TOKEN( AlternateContent ):
+ aMceState.push_back( MCE_STARTED );
+ break;
+
+ case MCE_TOKEN( Choice ):
+ {
+ OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString::createFromAscii("none") );
+ aRequires = getFilter().getNamespaceURL( aRequires );
+ if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
+ aMceState.back() = MCE_FOUND_CHOICE;
+ else
+ return false;
+ }
+ break;
+
+ case MCE_TOKEN( Fallback ):
+ if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
+ break;
+ return false;
+ default:
+ {
+ OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
+ if( !str.isEmpty() )
+ {
+ Sequence< ::com::sun::star::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
+ // printf("MCE: %s\n", ::rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
+ // TODO: Check & Get the namespaces in "Ignorable"
+ // printf("NS: %d : %s\n", attrs.getLength(), ::rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
+ }
+ }
+ return false;
+ }
+ return true;
+}
+
+
+
// com.sun.star.xml.sax.XFastContextHandler interface -------------------------
Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
{
+ if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
+ {
+ if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
+ return getFastContextHandler();
+ return NULL;
+ }
return implCreateChildContext( nElement, rxAttribs );
}
@@ -83,6 +134,14 @@ void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXE
void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
{
+ /* If MCE */
+ switch( nElement )
+ {
+ case MCE_TOKEN( AlternateContent ):
+ aMceState.pop_back();
+ break;
+ }
+
implEndElement( nElement );
}
@@ -150,4 +209,4 @@ void FragmentHandler2::finalizeImport()
} // namespace core
} // namespace oox
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 6085ffd..1a4e3e7 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -141,6 +141,8 @@ XmlFilterBaseImpl::XmlFilterBaseImpl( const Reference< XComponentContext >& rxCo
maFastParser.registerNamespace( NMSP_ax );
maFastParser.registerNamespace( NMSP_xm );
+ maFastParser.registerNamespace( NMSP_mce );
+ maFastParser.registerNamespace( NMSP_mceTest );
}
@@ -272,6 +274,16 @@ bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& r
return false;
}
+OUString XmlFilterBase::getNamespaceURL( const OUString& rPrefix )
+{
+ return mxImpl->maFastParser.getNamespaceURL( rPrefix );
+}
+
+sal_Int32 XmlFilterBase::getNamespaceId( const OUString& rUrl )
+{
+ return mxImpl->maFastParser.getNamespaceId( rUrl );
+}
+
RelationsRef XmlFilterBase::importRelations( const OUString& rFragmentPath )
{
// try to find cached relations
diff --git a/oox/source/token/namespaces.hxx.tail b/oox/source/token/namespaces.hxx.tail
old mode 100644
new mode 100755
index 2261c30..67ddce9
--- a/oox/source/token/namespaces.hxx.tail
+++ b/oox/source/token/namespaces.hxx.tail
@@ -27,6 +27,7 @@ inline sal_Int32 getNamespace( sal_Int32 nToken ) { return nToken & NMSP_MASK; }
#define XLS_TOKEN( token ) (::oox::NMSP_xls | XML_##token)
#define XM_TOKEN( token ) (::oox::NMSP_xm | XML_##token)
#define XML_TOKEN( token ) (::oox::NMSP_xml | XML_##token)
+#define MCE_TOKEN( token ) (::oox::NMSP_mce | XML_##token)
// ============================================================================
diff --git a/oox/source/token/namespaces.txt b/oox/source/token/namespaces.txt
index 81b5680..9251fe0 100644
--- a/oox/source/token/namespaces.txt
+++ b/oox/source/token/namespaces.txt
@@ -50,3 +50,5 @@ dc http://purl.org/dc/elements/1.1/
dcTerms http://purl.org/dc/terms/
xm http://schemas.microsoft.com/office/excel/2006/main
sprm http://sprm
+mce http://schemas.openxmlformats.org/markup-compatibility/2006
+mceTest http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2
diff --git a/oox/source/token/tokens.txt b/oox/source/token/tokens.txt
index ab03321..1cff6c0 100644
--- a/oox/source/token/tokens.txt
+++ b/oox/source/token/tokens.txt
@@ -37,6 +37,7 @@ AbbreviatedCaseNumber
Accel
Accel2
AlbumTitle
+AlternateContent
Always
Anchor
AppVersion
@@ -79,6 +80,7 @@ Characters
CharactersWithSpaces
Checkbox
Checked
+Choice
City
ClientData
ColHidden
@@ -142,6 +144,7 @@ EnhancedMetaFile
Extend
Extension
External
+Fallback
False
FieldCodes
FileBinding
@@ -183,6 +186,7 @@ IDREF
IDREFS
Icon
Id
+Ignorable
Inc
Institution
Internal
@@ -324,6 +328,7 @@ Relationships
RelationshipsGroupReference
Report
Reporter
+Requires
Right
RootElement
Row
More information about the Libreoffice-commits
mailing list