summaryrefslogtreecommitdiff
path: root/writerfilter/source/ooxml
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2011-12-02 17:38:51 +0100
committerLuboš Luňák <l.lunak@suse.cz>2011-12-07 14:47:11 +0100
commit7be8bac42aa578dc7f250a490634e13d1dac550b (patch)
treec9b51c1b92a6683d50277038549243cd59eed7d5 /writerfilter/source/ooxml
parent1e4fb45c03e1787a6f73a93a1d9a68911d17a4e6 (diff)
make the linear xml processing API more generic
I'm pretty sure I'll love to use it in writerfilter instead of the normal API whenever I get the chance.
Diffstat (limited to 'writerfilter/source/ooxml')
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx58
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx42
2 files changed, 70 insertions, 30 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 732391ce4cad..4b183b903063 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -2366,35 +2366,16 @@ Token_t OOXMLFastContextHandlerWrapper::getToken() const
/*
- class OOXMLFastContextHandlerMath
+ class OOXMLFastContextHandlerLinear
*/
-OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler* pContext)
+OOXMLFastContextHandlerLinear::OOXMLFastContextHandlerLinear(OOXMLFastContextHandler* pContext)
: OOXMLFastContextHandlerProperties(pContext)
, depthCount( 0 )
{
}
-void OOXMLFastContextHandlerMath::process()
-{
- SvGlobalName name( SO3_SM_CLASSID );
- comphelper::EmbeddedObjectContainer container;
- rtl::OUString aName;
- uno::Reference< embed::XEmbeddedObject > ref = container.CreateEmbeddedObject( name.GetByteSequence(), aName );
- uno::Reference< uno::XInterface > component( ref->getComponent(), uno::UNO_QUERY );
- if( oox::FormulaImportBase* import = dynamic_cast< oox::FormulaImportBase* >( component.get()))
- import->readFormulaOoxml( buffer );
- if (isForwardEvents())
- {
- OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
- OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref ));
- OOXMLProperty::Pointer_t pProp( new OOXMLPropertyImpl( NS_ooxml::LN_starmath, pVal, OOXMLPropertyImpl::ATTRIBUTE ));
- pProps->add( pProp );
- mpStream->props( writerfilter::Reference< Properties >::Pointer_t( pProps ));
- }
-}
-
-void OOXMLFastContextHandlerMath::lcl_startFastElement(Token_t Element,
+void OOXMLFastContextHandlerLinear::lcl_startFastElement(Token_t Element,
const uno::Reference< xml::sax::XFastAttributeList >& Attribs)
throw (uno::RuntimeException, xml::sax::SAXException)
{
@@ -2402,7 +2383,7 @@ void OOXMLFastContextHandlerMath::lcl_startFastElement(Token_t Element,
++depthCount;
}
-void OOXMLFastContextHandlerMath::lcl_endFastElement(Token_t Element)
+void OOXMLFastContextHandlerLinear::lcl_endFastElement(Token_t Element)
throw (uno::RuntimeException, xml::sax::SAXException)
{
buffer.appendClosingTag( Element );
@@ -2411,7 +2392,7 @@ void OOXMLFastContextHandlerMath::lcl_endFastElement(Token_t Element)
}
uno::Reference< xml::sax::XFastContextHandler >
-OOXMLFastContextHandlerMath::lcl_createFastChildContext(Token_t,
+OOXMLFastContextHandlerLinear::lcl_createFastChildContext(Token_t,
const uno::Reference< xml::sax::XFastAttributeList >&)
throw (uno::RuntimeException, xml::sax::SAXException)
{
@@ -2420,12 +2401,39 @@ OOXMLFastContextHandlerMath::lcl_createFastChildContext(Token_t,
return xContextHandler;
}
-void OOXMLFastContextHandlerMath::lcl_characters(const ::rtl::OUString& aChars)
+void OOXMLFastContextHandlerLinear::lcl_characters(const ::rtl::OUString& aChars)
throw (uno::RuntimeException, xml::sax::SAXException)
{
buffer.appendCharacters( aChars );
}
+/*
+ class OOXMLFastContextHandlerLinear
+ */
+
+OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler* pContext)
+ : OOXMLFastContextHandlerLinear(pContext)
+{
+}
+
+void OOXMLFastContextHandlerMath::process()
+{
+ SvGlobalName name( SO3_SM_CLASSID );
+ comphelper::EmbeddedObjectContainer container;
+ rtl::OUString aName;
+ uno::Reference< embed::XEmbeddedObject > ref = container.CreateEmbeddedObject( name.GetByteSequence(), aName );
+ uno::Reference< uno::XInterface > component( ref->getComponent(), uno::UNO_QUERY );
+ if( oox::FormulaImportBase* import = dynamic_cast< oox::FormulaImportBase* >( component.get()))
+ import->readFormulaOoxml( buffer );
+ if (isForwardEvents())
+ {
+ OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
+ OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref ));
+ OOXMLProperty::Pointer_t pProp( new OOXMLPropertyImpl( NS_ooxml::LN_starmath, pVal, OOXMLPropertyImpl::ATTRIBUTE ));
+ pProps->add( pProp );
+ mpStream->props( writerfilter::Reference< Properties >::Pointer_t( pProps ));
+ }
+}
}}
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index 0d75b7d328f2..bb0e8895e808 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -641,15 +641,37 @@ private:
OOXMLFastContextHandler * getFastContextHandler() const;
};
+/**
+ A class that converts from XFastParser/XFastContextHandler usage to a liner XML stream of data.
+
+ The purpose of this class is to convert the rather complex XFastContextHandler-based XML
+ processing that requires context subclasses, callbacks, etc. into a linear stream of XML tokens
+ that can be handled simply by reading the tokens one by one and directly processing them.
+ See the oox::formulaimport::XmlStream class documentation for more information.
+
+ Usage: Create a subclass of OOXMLFastContextHandlerLinear, reimplemented getType() to provide
+ type of the subclass and process() to actually process the XML stream. Also make sure to
+ add a line like the following to model.xml (for class OOXMLFastContextHandlerMath):
-class OOXMLFastContextHandlerMath: public OOXMLFastContextHandlerProperties
+ <resource name="CT_OMath" resource="Math"/>
+
+ @since 3.5
+*/
+class OOXMLFastContextHandlerLinear: public OOXMLFastContextHandlerProperties
{
public:
- explicit OOXMLFastContextHandlerMath(OOXMLFastContextHandler * pContext);
- virtual string getType() const { return "Math"; }
+ explicit OOXMLFastContextHandlerLinear(OOXMLFastContextHandler * pContext);
+ /**
+ Return the type of the class, as written in model.xml .
+ */
+ virtual string getType() const = 0;
protected:
- virtual void process();
+ /**
+ Called when the tokens for the element, its content and sub-elements have been linearized
+ and should be processed. The data member @ref buffer contains the converted data.
+ */
+ virtual void process() = 0;
virtual void lcl_startFastElement(Token_t Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
throw (uno::RuntimeException, xml::sax::SAXException);
@@ -662,11 +684,21 @@ protected:
virtual void lcl_characters(const ::rtl::OUString & aChars) throw (uno::RuntimeException, xml::sax::SAXException);
-private:
+ // should be private, but not much point in making deep copies of it
oox::formulaimport::XmlStreamBuilder buffer;
+
+private:
int depthCount;
};
+class OOXMLFastContextHandlerMath: public OOXMLFastContextHandlerLinear
+{
+public:
+ explicit OOXMLFastContextHandlerMath(OOXMLFastContextHandler * pContext);
+ virtual string getType() const { return "Math"; }
+protected:
+ virtual void process();
+};
}}
#endif // INCLUDED_OOXML_FAST_CONTEXT_HANDLER_HXX