summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2011-11-24 16:09:42 +0100
committerLuboš Luňák <l.lunak@suse.cz>2011-11-24 18:43:59 +0100
commit3236f5bea9b995922a59b43818f8f92cccde9956 (patch)
tree499220a3d6cc37ae26286029507aaa9b1df1ef57 /oox
parent199c95b3e9f4fc0f13cb0423b7f64779e4dfad9f (diff)
oox::AttributeList is actually not that usable outside
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/oox/mathml/importutils.hxx22
-rw-r--r--oox/source/mathml/importutils.cxx65
2 files changed, 80 insertions, 7 deletions
diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx
index eb7af2be09b0..d5d254009c9d 100644
--- a/oox/inc/oox/mathml/importutils.hxx
+++ b/oox/inc/oox/mathml/importutils.hxx
@@ -29,6 +29,7 @@
#define _STARMATHIMPORTUTILS_HXX
#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
+#include <map>
#include <oox/helper/attributelist.hxx>
#include <vector>
@@ -65,6 +66,20 @@ class OOX_DLLPUBLIC XmlStream
public:
XmlStream();
/**
+ Structure representing a list of attributes.
+ */
+ // One could theoretically use oox::AttributeList, but that complains if the passed reference is empty,
+ // which would be complicated to avoid here. Also, parsers apparently reuse the same instance of XFastAttributeList,
+ // which means using oox::AttributeList would make them all point to the one instance.
+ struct AttributeList
+ {
+ bool hasAttribute( int token ) const;
+ rtl::OUString attribute( int token, const rtl::OUString& def = rtl::OUString()) const;
+ bool attribute( int token, bool def ) const;
+ protected:
+ std::map< int, rtl::OUString > attrs;
+ };
+ /**
Structure representing a tag, including its attributes and content text immediatelly following it.
*/
struct Tag
@@ -154,13 +169,6 @@ public:
void appendCharacters( const rtl::OUString& characters );
};
-inline XmlStream::Tag::Tag( int t, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& a, const rtl::OUString& txt )
-: token( t )
-, attributes( a )
-, text( txt )
-{
-}
-
} // namespace
} // namespace
diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
index bec392922ecb..927f6e98cd9e 100644
--- a/oox/source/mathml/importutils.cxx
+++ b/oox/source/mathml/importutils.cxx
@@ -40,6 +40,71 @@ namespace oox
namespace formulaimport
{
+namespace
+{
+// a class that inherits from AttributeList, builds the internal data and then will be sliced off
+// during conversion to the base class
+class AttributeListBuilder
+ : public XmlStream::AttributeList
+{
+public:
+ AttributeListBuilder( const uno::Reference< xml::sax::XFastAttributeList >& a );
+};
+
+AttributeListBuilder::AttributeListBuilder( const uno::Reference< xml::sax::XFastAttributeList >& a )
+{
+ if( a.get() == NULL )
+ return;
+ uno::Sequence< xml::FastAttribute > aFastAttrSeq = a->getFastAttributes();
+ const xml::FastAttribute* pFastAttr = aFastAttrSeq.getConstArray();
+ sal_Int32 nFastAttrLength = aFastAttrSeq.getLength();
+ for( int i = 0;
+ i < nFastAttrLength;
+ ++i )
+ {
+ attrs[ pFastAttr[ i ].Token ] = pFastAttr[ i ].Value;
+ }
+}
+} // namespace
+
+bool XmlStream::AttributeList::hasAttribute( int token ) const
+{
+ return attrs.find( token ) != attrs.end();
+}
+
+rtl::OUString XmlStream::AttributeList::attribute( int token, const rtl::OUString& def ) const
+{
+ std::map< int, rtl::OUString >::const_iterator find = attrs.find( token );
+ if( find != attrs.end())
+ return find->second;
+ return def;
+}
+
+bool XmlStream::AttributeList::attribute( int token, bool def ) const
+{
+ std::map< int, rtl::OUString >::const_iterator find = attrs.find( token );
+ if( find != attrs.end())
+ {
+ if( find->second.equalsIgnoreAsciiCaseAscii( "true" ) || find->second.equalsIgnoreAsciiCaseAscii( "on" )
+ || find->second.equalsIgnoreAsciiCaseAscii( "t" ) || find->second.equalsIgnoreAsciiCaseAscii( "1" ))
+ return true;
+ if( find->second.equalsIgnoreAsciiCaseAscii( "false" ) || find->second.equalsIgnoreAsciiCaseAscii( "off" )
+ || find->second.equalsIgnoreAsciiCaseAscii( "f" ) || find->second.equalsIgnoreAsciiCaseAscii( "0" ))
+ return false;
+ fprintf( stderr, "Cannot convert \'%s\' to bool.\n",
+ rtl::OUStringToOString( find->second, RTL_TEXTENCODING_UTF8 ).getStr());
+ }
+ return def;
+}
+
+XmlStream::Tag::Tag( int t, const uno::Reference< xml::sax::XFastAttributeList >& a, const rtl::OUString& txt )
+: token( t )
+, attributes( AttributeListBuilder( a ))
+, text( txt )
+{
+}
+
+
XmlStream::XmlStream::Tag::operator bool() const
{
return token != XML_TOKEN_INVALID;