diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-02-26 09:30:59 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-02-26 09:31:31 +0100 |
commit | a4dbfa82fdf8e4473e342a358feff05df35260f7 (patch) | |
tree | 8649389690f3fcfa3d649366bc8a1dd31076fb43 | |
parent | 463f7be3f7d315789ecfbcbe874205995dbd3524 (diff) |
Extract SwTxtAttr::dumpAsXml() from SwTxtNode
Change-Id: I20914ec147b2af096bd40ec0e4da7567a44abaaa
-rw-r--r-- | sw/inc/txatbase.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/docnode/nodedump.cxx | 44 | ||||
-rw-r--r-- | sw/source/core/txtnode/txatbase.cxx | 43 |
3 files changed, 45 insertions, 43 deletions
diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx index f62ab1e9fa51..d8ccb02eded6 100644 --- a/sw/inc/txatbase.hxx +++ b/sw/inc/txatbase.hxx @@ -119,6 +119,7 @@ public: inline const SwFmtRuby &GetRuby() const; inline const SwFmtMeta &GetMeta() const; + void dumpAsXml(struct _xmlTextWriter* pWriter) const; }; class SwTxtAttrEnd : public virtual SwTxtAttr diff --git a/sw/source/core/docnode/nodedump.cxx b/sw/source/core/docnode/nodedump.cxx index edcf5ae02142..43f628a9a7d3 100644 --- a/sw/source/core/docnode/nodedump.cxx +++ b/sw/source/core/docnode/nodedump.cxx @@ -283,49 +283,7 @@ void SwTxtNode::dumpAsXml( xmlTextWriterPtr w ) const writer.startElement("hints"); const SwpHints& rHints = GetSwpHints(); for (size_t i = 0; i < rHints.Count(); ++i) - { - writer.startElement("hint"); - const SwTxtAttr* pHint = rHints.GetTextHint(i); - - if (pHint->GetStart()) - writer.writeFormatAttribute("start", TMP_FORMAT, pHint->GetStart()); - if (pHint->End()) - writer.writeFormatAttribute("end", TMP_FORMAT, *pHint->End()); - writer.writeFormatAttribute("whichId", TMP_FORMAT, pHint->Which()); - - const char* pWhich = 0; - boost::optional<OString> oValue; - switch (pHint->Which()) - { - case RES_TXTATR_AUTOFMT: - pWhich = "autofmt"; - break; - case RES_TXTATR_ANNOTATION: - pWhich = "annotation"; - break; - case RES_TXTATR_FLYCNT: - pWhich = "fly content"; - break; - case RES_TXTATR_CHARFMT: - { - pWhich = "character format"; - if (SwCharFmt* pCharFmt = pHint->GetCharFmt().GetCharFmt()) - oValue = "name: " + OUStringToOString(pCharFmt->GetName(), RTL_TEXTENCODING_UTF8); - break; - } - default: - break; - } - if (pWhich) - writer.writeFormatAttribute("which", "%s", BAD_CAST(pWhich)); - if (oValue) - writer.writeFormatAttribute("value", "%s", BAD_CAST(oValue->getStr())); - - if (pHint->Which() == RES_TXTATR_AUTOFMT) - pHint->GetAutoFmt().dumpAsXml(writer); - - writer.endElement(); - } + rHints.GetTextHint(i)->dumpAsXml(w); writer.endElement(); } if (GetNumRule()) diff --git a/sw/source/core/txtnode/txatbase.cxx b/sw/source/core/txtnode/txatbase.cxx index 7fe27c238cef..061cb257a63b 100644 --- a/sw/source/core/txtnode/txatbase.cxx +++ b/sw/source/core/txtnode/txatbase.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <boost/optional.hpp> +#include <libxml/xmlwriter.h> #include <svl/itempool.hxx> #include <txatbase.hxx> #include <fmtfld.hxx> @@ -73,4 +75,45 @@ sal_Int32* SwTxtAttrEnd::GetEnd() return & m_nEnd; } +void SwTxtAttr::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + xmlTextWriterStartElement(pWriter, BAD_CAST("swTxtAttr")); + + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr())); + if (End()) + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr())); + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr())); + const char* pWhich = 0; + boost::optional<OString> oValue; + switch (Which()) + { + case RES_TXTATR_AUTOFMT: + pWhich = "autofmt"; + break; + case RES_TXTATR_ANNOTATION: + pWhich = "annotation"; + break; + case RES_TXTATR_FLYCNT: + pWhich = "fly content"; + break; + case RES_TXTATR_CHARFMT: + { + pWhich = "character format"; + if (SwCharFmt* pCharFmt = GetCharFmt().GetCharFmt()) + oValue = "name: " + OUStringToOString(pCharFmt->GetName(), RTL_TEXTENCODING_UTF8); + break; + } + default: + break; + } + if (pWhich) + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(pWhich)); + if (oValue) + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr())); + if (Which() == RES_TXTATR_AUTOFMT) + GetAutoFmt().dumpAsXml(pWriter); + + xmlTextWriterEndElement(pWriter); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |