# HG changeset patch
# User Michael Stahl <mst@openoffice.org>
# Date 1303140562 0
# Node ID aa5f5a7a9c3064ea1e8eecc3d3fe1431b669cc82
# Parent  6d5ee77161481fd3b40778f1b3ce3ca4f5823a89
rtftok01: writerfilter: generic implementation of some properties

diff --git a/writerfilter/source/rtftok/RTFDocumentImpl.cxx b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
--- a/writerfilter/source/rtftok/RTFDocumentImpl.cxx
+++ b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
@@ -27,6 +27,7 @@
 
 #include <RTFDocumentImpl.hxx>
 
+#include <map>
 #include <algorithm>
 
 #include <rtl/strbuf.hxx>
@@ -53,6 +54,170 @@
 
 
 
+/** Value class for Integer (32 bit should be enough).
+ */
+class RTFValueInt
+    : public Value
+{
+
+public:
+    explicit RTFValueInt(int const i_Value)
+        : m_Value(i_Value)
+    { }
+    virtual ~RTFValueInt() { }
+    virtual int getInt() const
+    {
+        return m_Value;
+    }
+    // don't throw exceptions, just return null values
+    virtual ::rtl::OUString getString() const
+    {
+        return ::rtl::OUString();
+    }
+    virtual uno::Any getAny() const
+    {
+        uno::Any ret;
+        ret <<= static_cast<sal_Int32>(m_Value);
+        return ret;
+    }
+    virtual writerfilter::Reference<Properties>::Pointer_t getProperties()
+    {
+        return writerfilter::Reference<Properties>::Pointer_t();
+    }
+    virtual writerfilter::Reference<Stream>::Pointer_t getStream()
+    {
+        return writerfilter::Reference<Stream>::Pointer_t();
+    }
+    virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary()
+    {
+        return writerfilter::Reference<BinaryObj>::Pointer_t();
+    }
+    virtual ::std::string toString() const
+    {
+        return ::rtl::OString::valueOf(m_Value).getStr();
+    }
+
+private:
+    sal_Int32 const m_Value;
+};
+
+/** Value class for String.
+ */
+class RTFValueString
+    : public Value
+{
+
+public:
+    explicit RTFValueString(::rtl::OUString const& rValue)
+        : m_Value(rValue)
+    { }
+    virtual ~RTFValueString() { }
+    // don't throw exceptions, just return null values
+    virtual int getInt() const
+    {
+        return 0;
+    }
+    virtual ::rtl::OUString getString() const
+    {
+        return m_Value;
+    }
+    virtual uno::Any getAny() const
+    {
+        uno::Any ret;
+        ret <<= m_Value;
+        return ret;
+    }
+    virtual writerfilter::Reference<Properties>::Pointer_t getProperties()
+    {
+        return writerfilter::Reference<Properties>::Pointer_t();
+    }
+    virtual writerfilter::Reference<Stream>::Pointer_t getStream()
+    {
+        return writerfilter::Reference<Stream>::Pointer_t();
+    }
+    virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary()
+    {
+        return writerfilter::Reference<BinaryObj>::Pointer_t();
+    }
+    virtual ::std::string toString() const
+    {
+        ::std::string mk("\"");
+        return mk
+            + ::rtl::OUStringToOString(m_Value, RTL_TEXTENCODING_UTF8).getStr()
+            +  mk;
+    }
+
+private:
+    ::rtl::OUString const m_Value;
+};
+
+
+/** Implementation of Reference<Properties>.
+ */
+class RTFRefProperties
+    : public writerfilter::Reference<Properties>
+{
+
+public:
+    typedef ::std::map<Id, ::boost::shared_ptr<Value> > Attributes_t;
+
+    explicit RTFRefProperties(Attributes_t const& rAttributes)
+        : m_Attributes(rAttributes)
+    { }
+    virtual ~RTFRefProperties() { }
+    virtual void resolve(Properties & rHandler)
+    {
+        for (Attributes_t::const_iterator iter = m_Attributes.begin();
+                iter != m_Attributes.end(); ++iter)
+        {
+fprintf(stderr, "RTFRefProperties::resolve: %ld -> %s\n", iter->first, iter->second->toString().c_str());
+            rHandler.attribute(iter->first, *iter->second.get());
+        }
+    }
+    ::std::string getType() const
+    {
+        return "RTFRefProperties";
+    }
+
+private:
+    Attributes_t const m_Attributes;
+};
+
+
+/** Implementation of Reference<Table>.
+ */
+class RTFRefTable
+    : public writerfilter::Reference<Table>
+{
+
+public:
+    typedef ::std::map<int, writerfilter::Reference<Properties>::Pointer_t>
+        Properties_t;
+
+    explicit RTFRefTable(Properties_t const& rProperties)
+        : m_Properties(rProperties)
+    { }
+    virtual ~RTFRefTable() { }
+    virtual void resolve(Table & rHandler)
+    {
+        for (Properties_t::const_iterator iter = m_Properties.begin();
+                iter != m_Properties.end(); ++iter)
+        {
+fprintf(stderr, "RTFRefTable::resolve: %d -> %s\n", iter->first, iter->second->getType().c_str());
+            rHandler.entry(iter->first, iter->second);
+        }
+    }
+    ::std::string getType() const
+    {
+        return "RTFRefTable";
+    }
+
+private:
+    Properties_t const m_Properties;
+};
+
+
+
 class RTFInputStream
     : public RTFInputSource
 {
@@ -179,7 +344,6 @@
 };
 
 
-
 class RTFDocumentImpl::Impl
 {
     friend class RTFDocumentImpl;
