Kaydet (Commit) 904c9dde authored tarafından Miklos Vajna's avatar Miklos Vajna

Move sw::mark::MarkManager::dumpAsXml() out of docnode

It has nothing to do with SwTxtNode. There is still some code
duplication, but at least now the implementation is next to the rest of
the sw::mark code.

Change-Id: I119a253b8e3fd024dcfc088259f7516a4a8060b8
Reviewed-on: https://gerrit.libreoffice.org/14156Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 3da925eb
......@@ -55,6 +55,7 @@
#include <edimp.hxx>
#include <stdio.h>
#include <tools/datetimeutils.hxx>
#include <comphelper/anytostring.hxx>
using namespace ::boost;
using namespace ::sw::mark;
......@@ -1138,6 +1139,78 @@ namespace sw { namespace mark
return (m_aMarkNamesSet.find(rName) != m_aMarkNamesSet.end());
}
void MarkManager::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("markManager"));
if (!m_vBookmarks.empty())
{
xmlTextWriterStartElement(pWriter, BAD_CAST("bookmarks"));
for (const_iterator_t it = m_vBookmarks.begin(); it != m_vBookmarks.end(); ++it)
{
pMark_t pMark = *it;
xmlTextWriterStartElement(pWriter, BAD_CAST("bookmark"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("startNode"), BAD_CAST(OString::number(pMark->GetMarkStart().nNode.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("startOffset"), BAD_CAST(OString::number(pMark->GetMarkStart().nContent.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("endNode"), BAD_CAST(OString::number(pMark->GetMarkEnd().nNode.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("endOffset"), BAD_CAST(OString::number(pMark->GetMarkEnd().nContent.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"), BAD_CAST(pMark->GetName().toUtf8().getStr()));
xmlTextWriterEndElement(pWriter);
}
xmlTextWriterEndElement(pWriter);
}
if (!m_vFieldmarks.empty())
{
xmlTextWriterStartElement(pWriter, BAD_CAST("fieldmarks"));
for (const_iterator_t it = m_vFieldmarks.begin(); it != m_vFieldmarks.end(); ++it)
{
pMark_t pMark = *it;
xmlTextWriterStartElement(pWriter, BAD_CAST("fieldmark"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("startNode"), BAD_CAST(OString::number(pMark->GetMarkStart().nNode.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("startOffset"), BAD_CAST(OString::number(pMark->GetMarkStart().nContent.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("endNode"), BAD_CAST(OString::number(pMark->GetMarkEnd().nNode.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("endOffset"), BAD_CAST(OString::number(pMark->GetMarkEnd().nContent.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"), BAD_CAST(pMark->GetName().toUtf8().getStr()));
if (sw::mark::IFieldmark* pFieldmark = dynamic_cast<sw::mark::IFieldmark*>(pMark.get()))
{
sw::mark::IFieldmark::parameter_map_t* pParameters = pFieldmark->GetParameters();
if (pParameters)
{
xmlTextWriterStartElement(pWriter, BAD_CAST("parameters"));
for (sw::mark::IFieldmark::parameter_map_t::iterator parameter = pParameters->begin(); parameter != pParameters->end(); ++parameter)
{
xmlTextWriterStartElement(pWriter, BAD_CAST("parameter"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"), BAD_CAST(parameter->first.toUtf8().getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(comphelper::anyToString(parameter->second).toUtf8().getStr()));
xmlTextWriterEndElement(pWriter);
}
xmlTextWriterEndElement(pWriter);
}
}
xmlTextWriterEndElement(pWriter);
}
xmlTextWriterEndElement(pWriter);
}
if (!m_vAnnotationMarks.empty())
{
xmlTextWriterStartElement(pWriter, BAD_CAST("annotationmarks"));
for (const_iterator_t it = m_vAnnotationMarks.begin(); it != m_vAnnotationMarks.end(); ++it)
{
pMark_t pMark = *it;
xmlTextWriterStartElement(pWriter, BAD_CAST("annotationmark"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("startNode"), BAD_CAST(OString::number(pMark->GetMarkStart().nNode.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("startOffset"), BAD_CAST(OString::number(pMark->GetMarkStart().nContent.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("endNode"), BAD_CAST(OString::number(pMark->GetMarkEnd().nNode.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("endOffset"), BAD_CAST(OString::number(pMark->GetMarkEnd().nContent.GetIndex()).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"), BAD_CAST(pMark->GetName().toUtf8().getStr()));
xmlTextWriterEndElement(pWriter);
}
xmlTextWriterEndElement(pWriter);
}
xmlTextWriterEndElement(pWriter);
}
}} // namespace ::sw::mark
namespace
......
......@@ -24,7 +24,6 @@
#include <tools/datetimeutils.hxx>
#include <libxml/xmlwriter.h>
#include <comphelper/anytostring.hxx>
using namespace com::sun::star;
......@@ -129,90 +128,6 @@ void SwDoc::dumpAsXml( xmlTextWriterPtr w ) const
writer.endElement();
}
namespace sw {
namespace mark {
void MarkManager::dumpAsXml( xmlTextWriterPtr w ) const
{
WriterHelper writer(w);
writer.startElement("markManager");
if (!m_vBookmarks.empty())
{
writer.startElement("bookmarks");
for (const_iterator_t it = m_vBookmarks.begin(); it != m_vBookmarks.end(); ++it)
{
pMark_t pMark = *it;
writer.startElement("bookmark");
writer.writeFormatAttribute("startNode", TMP_FORMAT, pMark->GetMarkStart().nNode.GetIndex());
writer.writeFormatAttribute("startOffset", TMP_FORMAT_I32, pMark->GetMarkStart().nContent.GetIndex());
writer.writeFormatAttribute("endNode", TMP_FORMAT, pMark->GetMarkEnd().nNode.GetIndex());
writer.writeFormatAttribute("endOffset", TMP_FORMAT_I32, pMark->GetMarkEnd().nContent.GetIndex());
OString txt8 = OUStringToOString(pMark->GetName(), RTL_TEXTENCODING_UTF8);
writer.writeFormatAttribute("name", "%s", BAD_CAST( txt8.getStr()));
writer.endElement();
}
writer.endElement();
}
if (!m_vFieldmarks.empty())
{
writer.startElement("fieldmarks");
for (const_iterator_t it = m_vFieldmarks.begin(); it != m_vFieldmarks.end(); ++it)
{
pMark_t pMark = *it;
writer.startElement("fieldmark");
writer.writeFormatAttribute("startNode", TMP_FORMAT, pMark->GetMarkStart().nNode.GetIndex());
writer.writeFormatAttribute("startOffset", TMP_FORMAT_I32, pMark->GetMarkStart().nContent.GetIndex());
writer.writeFormatAttribute("endNode", TMP_FORMAT, pMark->GetMarkEnd().nNode.GetIndex());
writer.writeFormatAttribute("endOffset", TMP_FORMAT_I32, pMark->GetMarkEnd().nContent.GetIndex());
OString txt8 = OUStringToOString(pMark->GetName(), RTL_TEXTENCODING_UTF8);
writer.writeFormatAttribute("name", "%s", BAD_CAST( txt8.getStr()));
if (sw::mark::IFieldmark* pFieldmark = dynamic_cast<sw::mark::IFieldmark*>(pMark.get()))
{
sw::mark::IFieldmark::parameter_map_t* pParameters = pFieldmark->GetParameters();
if (pParameters)
{
writer.startElement("parameters");
for (sw::mark::IFieldmark::parameter_map_t::iterator parameter = pParameters->begin(); parameter != pParameters->end(); ++parameter)
{
writer.startElement("parameter");
OString aName = OUStringToOString(parameter->first, RTL_TEXTENCODING_UTF8);
writer.writeFormatAttribute("name", "%s", BAD_CAST(aName.getStr()));
OString aValue = OUStringToOString(comphelper::anyToString(parameter->second), RTL_TEXTENCODING_UTF8);
writer.writeFormatAttribute("value", "%s", BAD_CAST(aValue.getStr()));
writer.endElement();
}
writer.endElement();
}
}
writer.endElement();
}
writer.endElement();
}
if (!m_vAnnotationMarks.empty())
{
writer.startElement("annotationmarks");
for (const_iterator_t it = m_vAnnotationMarks.begin(); it != m_vAnnotationMarks.end(); ++it)
{
pMark_t pMark = *it;
writer.startElement("annotationmark");
writer.writeFormatAttribute("startNode", TMP_FORMAT, pMark->GetMarkStart().nNode.GetIndex());
writer.writeFormatAttribute("startOffset", TMP_FORMAT_I32, pMark->GetMarkStart().nContent.GetIndex());
writer.writeFormatAttribute("endNode", TMP_FORMAT, pMark->GetMarkEnd().nNode.GetIndex());
writer.writeFormatAttribute("endOffset", TMP_FORMAT_I32, pMark->GetMarkEnd().nContent.GetIndex());
OString txt8 = OUStringToOString(pMark->GetName(), RTL_TEXTENCODING_UTF8);
writer.writeFormatAttribute("name", "%s", BAD_CAST( txt8.getStr()));
writer.endElement();
}
writer.endElement();
}
writer.endElement();
}
} // namespace mark
} // namespace sw
void SwFldTypes::dumpAsXml( xmlTextWriterPtr w ) const
{
WriterHelper writer(w);
......
......@@ -84,7 +84,7 @@ namespace sw {
virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition &rPos) const SAL_OVERRIDE;
virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const SAL_OVERRIDE;
void dumpAsXml(xmlTextWriterPtr w) const;
void dumpAsXml(struct _xmlTextWriter* pWriter) const;
// Annotation Marks
virtual const_iterator_t getAnnotationMarksBegin() const SAL_OVERRIDE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment