diff options
author | Daniel Sikeler <d.sikeler94@gmail.com> | 2015-08-01 13:55:40 +0200 |
---|---|---|
committer | Daniel Sikeler <d.sikeler94@gmail.com> | 2015-08-01 14:09:54 +0200 |
commit | d72d9728d0ccf4c137cf7539f02aa872d0c8e166 (patch) | |
tree | 55cbce96c3efdd8fbd1186b1645c114bb3d3dc4c | |
parent | a01cbeef14441c45e3501e56895cc1542219bae1 (diff) |
fastparser impl. for XMLFootnoteImportContext
and XMLFootnoteBodyImportContext
Change-Id: Icc23222d0506766e32f8f91d4946a1058e0bd8d4
-rw-r--r-- | xmloff/source/text/XMLFootnoteBodyImportContext.cxx | 25 | ||||
-rw-r--r-- | xmloff/source/text/XMLFootnoteBodyImportContext.hxx | 9 | ||||
-rw-r--r-- | xmloff/source/text/XMLFootnoteImportContext.cxx | 135 | ||||
-rw-r--r-- | xmloff/source/text/XMLFootnoteImportContext.hxx | 17 |
4 files changed, 186 insertions, 0 deletions
diff --git a/xmloff/source/text/XMLFootnoteBodyImportContext.cxx b/xmloff/source/text/XMLFootnoteBodyImportContext.cxx index 11e975cb8fbf..cd915a33ae51 100644 --- a/xmloff/source/text/XMLFootnoteBodyImportContext.cxx +++ b/xmloff/source/text/XMLFootnoteBodyImportContext.cxx @@ -29,6 +29,8 @@ using ::com::sun::star::uno::Reference; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::xml::sax::XAttributeList; +using css::xml::sax::XFastAttributeList; +using css::xml::sax::XFastContextHandler; TYPEINIT1( XMLFootnoteBodyImportContext, SvXMLImportContext ); @@ -41,6 +43,13 @@ XMLFootnoteBodyImportContext::XMLFootnoteBodyImportContext( { } +XMLFootnoteBodyImportContext::XMLFootnoteBodyImportContext( + SvXMLImport& rImport, + sal_Int32 /*Element*/ ) +: SvXMLImportContext( rImport ) +{ +} + SvXMLImportContext* XMLFootnoteBodyImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, @@ -59,4 +68,20 @@ SvXMLImportContext* XMLFootnoteBodyImportContext::CreateChildContext( return pContext; } +Reference< XFastContextHandler > + XMLFootnoteBodyImportContext::createFastChildContext( + sal_Int32 Element, + const Reference< XFastAttributeList >& xAttrList ) + throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) +{ + // return text context + Reference< XFastContextHandler > pContext = + GetImport().GetTextImport()->CreateTextChildContext(GetImport(), + Element, xAttrList, XML_TEXT_TYPE_FOOTNOTE); + if( !pContext.is() ) + pContext = new SvXMLImportContext( GetImport() ); + + return pContext; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLFootnoteBodyImportContext.hxx b/xmloff/source/text/XMLFootnoteBodyImportContext.hxx index 53f97786ab51..dc35c90cb7cf 100644 --- a/xmloff/source/text/XMLFootnoteBodyImportContext.hxx +++ b/xmloff/source/text/XMLFootnoteBodyImportContext.hxx @@ -27,6 +27,8 @@ namespace com { namespace sun { namespace star { namespace xml { namespace sax { class XAttributeList; + class XFastAttributeList; + class XFastContextHandler; } } } } } @@ -43,6 +45,9 @@ public: SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName ); + XMLFootnoteBodyImportContext( + SvXMLImport& rImport, + sal_Int32 Element ); protected: @@ -51,6 +56,10 @@ protected: const OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList ) SAL_OVERRIDE; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > + createFastChildContext( sal_Int32 Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) + throw(css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE; }; diff --git a/xmloff/source/text/XMLFootnoteImportContext.cxx b/xmloff/source/text/XMLFootnoteImportContext.cxx index de264022deab..bfff1c0dd26b 100644 --- a/xmloff/source/text/XMLFootnoteImportContext.cxx +++ b/xmloff/source/text/XMLFootnoteImportContext.cxx @@ -82,6 +82,17 @@ XMLFootnoteImportContext::XMLFootnoteImportContext( { } +XMLFootnoteImportContext::XMLFootnoteImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_Int32 /*Element*/ ) +: SvXMLImportContext( rImport ), + sPropertyReferenceId("ReferenceId"), + mbListContextPushed(false), + rHelper(rHlp) +{ +} + void XMLFootnoteImportContext::StartElement( const Reference<XAttributeList> & xAttrList) { @@ -159,12 +170,80 @@ void XMLFootnoteImportContext::StartElement( // else: ignore footnote! Content will be merged into document. } +void XMLFootnoteImportContext::startFastElement( sal_Int32 /*Element*/, + const Reference< XFastAttributeList >& xAttrList ) + throw (RuntimeException, SAXException, std::exception) +{ + // create footnote + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(), UNO_QUERY); + + if( xFactory.is() ) + { + // create endnote or footnote + bool bIsEndnote = false; + if( xAttrList.is() && + xAttrList->hasAttribute( NAMESPACE | XML_NAMESPACE_TEXT | XML_note_class ) ) + { + if( IsXMLToken( xAttrList->getValue( NAMESPACE | XML_NAMESPACE_TEXT | XML_note_class ), + XML_ENDNOTE ) ) + bIsEndnote = true; + } + + Reference<XInterface> xIfc = xFactory->createInstance( + bIsEndnote ? + OUString(sAPI_service_endnote) : + OUString(sAPI_service_footnote) ); + + // attach footnote to document + Reference<XTextContent> xTextContent(xIfc, UNO_QUERY); + rHelper.InsertTextContent(xTextContent); + + // process id attribute + if( xAttrList.is() && + xAttrList->hasAttribute( NAMESPACE | XML_NAMESPACE_TEXT | XML_id ) ) + { + // get ID ... + Reference<XPropertySet> xPropertySet(xTextContent, UNO_QUERY); + Any aAny = xPropertySet->getPropertyValue(sPropertyReferenceId); + sal_Int16 nID = 0; + aAny >>= nID; + + // ... and insert into map + rHelper.InsertFootnoteID( + xAttrList->getValue( NAMESPACE | XML_NAMESPACE_TEXT | XML_id ), + nID ); + } + + // save old cursor and install new one + xOldCursor = rHelper.GetCursor(); + Reference<XText> xText(xTextContent, UNO_QUERY); + rHelper.SetCursor(xText->createTextCursor()); + + // remember old list item and block (#89891#) and reset them + // for the footnote + rHelper.PushListContext(); + mbListContextPushed = true; + + // remember footnote (for createFastChildContext) + Reference<XFootnote> xNote(xTextContent, UNO_QUERY); + xFootnote = xNote; + } + // else: ignore footnote! Content will be merged into document. +} + void XMLFootnoteImportContext::Characters(const OUString&) { // ignore characters! Text must be contained in paragraphs! // rHelper.InsertString(rString); } +void XMLFootnoteImportContext::characters(const OUString&) + throw (RuntimeException, SAXException, std::exception) +{ + // ignore characters! Text must be contained in paragraphs! + // rHelper.InsertString(rString); +} + void XMLFootnoteImportContext::EndElement() { // get rid of last dummy paragraph @@ -179,6 +258,19 @@ void XMLFootnoteImportContext::EndElement() } } +void XMLFootnoteImportContext::endFastElement( sal_Int32 /*Element*/ ) + throw (RuntimeException, SAXException, std::exception) +{ + // get rid of last dumy paragraph + rHelper.DeleteParagraph(); + + // reinstall old cursor + rHelper.SetCursor(xOldCursor); + + // reinstall old list item + if( mbListContextPushed ) + rHelper.PopListContext(); +} SvXMLImportContext *XMLFootnoteImportContext::CreateChildContext( sal_uInt16 p_nPrefix, @@ -233,4 +325,47 @@ SvXMLImportContext *XMLFootnoteImportContext::CreateChildContext( return pContext; } +Reference< XFastContextHandler > + XMLFootnoteImportContext::createFastChildContext( + sal_Int32 Element, + const Reference< XFastAttributeList >& xAttrList ) + throw (RuntimeException, SAXException, std::exception) +{ + Reference< XFastContextHandler > pContext = NULL; + + SvXMLTokenMap aTokenMap(aFootnoteChildTokenMap); + + switch( aTokenMap.Get( Element ) ) + { + case XML_TOK_FTN_NOTE_CITATION: + { + // little hack: we only care for one attribute of the citation + // element. We handle that here, and the return a + // default context. + if( xAttrList.is() && + xAttrList->hasAttribute( NAMESPACE | XML_NAMESPACE_TEXT | XML_label ) ) + { + xFootnote->setLabel(xAttrList->getValue( + NAMESPACE | XML_NAMESPACE_TEXT | XML_label ) ); + } + + // ignore content: return default context + pContext = new SvXMLImportContext( GetImport() ); + break; + } + + case XML_TOK_FTN_NOTE_BODY: + // return footnoe body + pContext = new XMLFootnoteBodyImportContext( GetImport(), Element ); + break; + default: + // default: + pContext = SvXMLImportContext::createFastChildContext( + Element, xAttrList ); + break; + } + + return pContext; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLFootnoteImportContext.hxx b/xmloff/source/text/XMLFootnoteImportContext.hxx index cbf26c61bc91..d4eb1d279abb 100644 --- a/xmloff/source/text/XMLFootnoteImportContext.hxx +++ b/xmloff/source/text/XMLFootnoteImportContext.hxx @@ -31,6 +31,8 @@ namespace com { namespace sun { namespace star { } namespace xml { namespace sax { class XAttributeList; + class XFastAttributeList; + class XFastContextHandler; } } } } } class XMLTextImportHelper; @@ -63,23 +65,38 @@ public: XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, const OUString& rLocalName ); + XMLFootnoteImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_Int32 Element ); protected: virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList) SAL_OVERRIDE; + virtual void startFastElement( sal_Int32 Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) + throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE; virtual void Characters( const OUString& rChars) SAL_OVERRIDE; + virtual void characters( const OUString& rChars ) + throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE; virtual void EndElement() SAL_OVERRIDE; + virtual void endFastElement( sal_Int32 Element ) + throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE; virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList ) SAL_OVERRIDE; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > + createFastChildContext( sal_Int32 Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) + throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE; }; |