[Libreoffice-commits] core.git: Branch 'feature/ods-edit-cell-import' - 2 commits - sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Feb 11 11:16:52 PST 2013


 sc/source/filter/xml/celltextparacontext.cxx |   72 ++++++++++++++++++++++++---
 sc/source/filter/xml/celltextparacontext.hxx |   26 +++++++--
 sc/source/filter/xml/xmlcelli.cxx            |   10 +++
 sc/source/filter/xml/xmlcelli.hxx            |    2 
 sc/source/filter/xml/xmlimprt.cxx            |   39 ++++++++++----
 sc/source/filter/xml/xmlimprt.hxx            |   15 ++++-
 6 files changed, 139 insertions(+), 25 deletions(-)

New commits:
commit 238ef32870f8e6025dbdd0dc91782483cc206279
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Feb 11 14:08:01 2013 -0500

    Import URL fields as well. Now I'm done.
    
    Also fix Tokem to Token typos.
    
    Change-Id: If22b673f6833f3fd485472b17ec508e616e0d59d

diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx
index abca9d8..ddc0fc3 100644
--- a/sc/source/filter/xml/celltextparacontext.cxx
+++ b/sc/source/filter/xml/celltextparacontext.cxx
@@ -61,6 +61,8 @@ SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext(
             return new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, *this);
         case XML_TOK_CELL_TEXT_TITLE:
             return new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, *this);
+        case XML_TOK_CELL_TEXT_URL:
+            return new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, *this);
         default:
             ;
     }
@@ -88,6 +90,11 @@ void ScXMLCellTextParaContext::PushFieldTitle()
     mrParentCxt.PushParagraphFieldDocTitle();
 }
 
+void ScXMLCellTextParaContext::PushFieldURL(const OUString& rURL, const OUString& rRep)
+{
+    mrParentCxt.PushParagraphFieldURL(rURL, rRep);
+}
+
 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     ScXMLImportContext(rImport, nPrefix, rLName),
@@ -132,7 +139,7 @@ void ScXMLCellTextSpanContext::EndElement()
 
 void ScXMLCellTextSpanContext::Characters(const OUString& rChars)
 {
-    maContent = rChars;
+    maContent += rChars;
 }
 
 SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext(
@@ -220,4 +227,57 @@ SvXMLImportContext* ScXMLCellFieldTitleContext::CreateChildContext(
     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
 }
 
+ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
+    ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
+    ScXMLImportContext(rImport, nPrefix, rLName),
+    mrParentCxt(rParent)
+{
+}
+
+void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+{
+    if (!xAttrList.is())
+        return;
+
+    OUString aLocalName;
+    sal_Int16 nAttrCount = xAttrList->getLength();
+
+    const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextURLAttrTokenMap();
+    for (sal_Int16 i = 0; i < nAttrCount; ++i)
+    {
+        sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
+            xAttrList->getNameByIndex(i), &aLocalName);
+
+        const OUString& rAttrValue = xAttrList->getValueByIndex(i);
+        sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
+        switch (nToken)
+        {
+            case XML_TOK_CELL_TEXT_URL_ATTR_UREF:
+                maURL = rAttrValue;
+            break;
+            case XML_TOK_CELL_TEXT_URL_ATTR_TYPE:
+                // Ignored for now.
+            break;
+            default:
+                ;
+        }
+    }
+}
+
+void ScXMLCellFieldURLContext::EndElement()
+{
+    mrParentCxt.PushFieldURL(maURL, maRep);
+}
+
+void ScXMLCellFieldURLContext::Characters(const OUString& rChars)
+{
+    maRep += rChars;
+}
+
+SvXMLImportContext* ScXMLCellFieldURLContext::CreateChildContext(
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+    return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/celltextparacontext.hxx b/sc/source/filter/xml/celltextparacontext.hxx
index e9d11aa..9390a3e 100644
--- a/sc/source/filter/xml/celltextparacontext.hxx
+++ b/sc/source/filter/xml/celltextparacontext.hxx
@@ -35,6 +35,7 @@ public:
     void PushFieldSheetName();
     void PushFieldDate();
     void PushFieldTitle();
+    void PushFieldURL(const OUString& rURL, const OUString& rRep);
 };
 
 /**
@@ -57,7 +58,6 @@ public:
 
 /**
  * This context handles <text:sheet-name> element inside <text:p>.
- *
  */
 class ScXMLCellFieldSheetNameContext : public ScXMLImportContext
 {
@@ -74,7 +74,6 @@ public:
 
 /**
  * This context handles <text:date> element inside <text:p>.
- *
  */
 class ScXMLCellFieldDateContext : public ScXMLImportContext
 {
@@ -91,7 +90,6 @@ public:
 
 /**
  * This context handles <text:title> element inside <text:p>.
- *
  */
 class ScXMLCellFieldTitleContext : public ScXMLImportContext
 {
@@ -106,6 +104,24 @@ public:
         sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
 };
 
+/**
+ * This context handles <text:a> element inside <text:p>.
+ */
+class ScXMLCellFieldURLContext : public ScXMLImportContext
+{
+    ScXMLCellTextParaContext& mrParentCxt;
+    OUString maURL;
+    OUString maRep;
+public:
+    ScXMLCellFieldURLContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
+
+    virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    virtual void EndElement();
+    virtual void Characters(const OUString& rChars);
+    virtual SvXMLImportContext* CreateChildContext(
+        sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 86a6f04..701e784 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -586,6 +586,11 @@ void ScXMLTableRowCellContext::PushParagraphFieldDocTitle()
     PushParagraphField(new SvxFileField);
 }
 
+void ScXMLTableRowCellContext::PushParagraphFieldURL(const OUString& rURL, const OUString& rRep)
+{
+    PushParagraphField(new SvxURLField(rURL, rRep, SVXURLFORMAT_REPR));
+}
+
 void ScXMLTableRowCellContext::PushParagraphEnd()
 {
     // EditEngine always has at least one paragraph even when its content is empty.
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 9fef82b..e59aa6e 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -139,6 +139,7 @@ public:
     void PushParagraphFieldDate();
     void PushParagraphFieldSheetName();
     void PushParagraphFieldDocTitle();
+    void PushParagraphFieldURL(const OUString& rURL, const OUString& rRep);
     void PushParagraphEnd();
 
     void SetAnnotation( const ScAddress& rPosition );
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index fb5516f..bd5fd4d 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1845,7 +1845,7 @@ const SvXMLTokenMap& ScXMLImport::GetConsolidationAttrTokenMap()
 
 const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap()
 {
-    if (!pCellTextParaElemTokemMap)
+    if (!pCellTextParaElemTokenMap)
     {
         static SvXMLTokenMapEntry aMap[] =
         {
@@ -1853,17 +1853,18 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap()
             { XML_NAMESPACE_TEXT, XML_SHEET_NAME, XML_TOK_CELL_TEXT_SHEET_NAME },
             { XML_NAMESPACE_TEXT, XML_DATE, XML_TOK_CELL_TEXT_DATE },
             { XML_NAMESPACE_TEXT, XML_TITLE, XML_TOK_CELL_TEXT_TITLE },
+            { XML_NAMESPACE_TEXT, XML_A, XML_TOK_CELL_TEXT_URL },
             XML_TOKEN_MAP_END
         };
 
-        pCellTextParaElemTokemMap = new SvXMLTokenMap(aMap);
+        pCellTextParaElemTokenMap = new SvXMLTokenMap(aMap);
     }
-    return *pCellTextParaElemTokemMap;
+    return *pCellTextParaElemTokenMap;
 }
 
 const SvXMLTokenMap& ScXMLImport::GetCellTextSpanAttrTokenMap()
 {
-    if (!pCellTextSpanAttrTokemMap)
+    if (!pCellTextSpanAttrTokenMap)
     {
         static SvXMLTokenMapEntry aMap[] =
         {
@@ -1871,9 +1872,25 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextSpanAttrTokenMap()
             XML_TOKEN_MAP_END
         };
 
-        pCellTextSpanAttrTokemMap = new SvXMLTokenMap(aMap);
+        pCellTextSpanAttrTokenMap = new SvXMLTokenMap(aMap);
     }
-    return *pCellTextSpanAttrTokemMap;
+    return *pCellTextSpanAttrTokenMap;
+}
+
+const SvXMLTokenMap& ScXMLImport::GetCellTextURLAttrTokenMap()
+{
+    if (!pCellTextURLAttrTokenMap)
+    {
+        static SvXMLTokenMapEntry aMap[] =
+        {
+            { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_CELL_TEXT_URL_ATTR_UREF },
+            { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_CELL_TEXT_URL_ATTR_TYPE },
+            XML_TOKEN_MAP_END
+        };
+
+        pCellTextURLAttrTokenMap = new SvXMLTokenMap(aMap);
+    }
+    return *pCellTextURLAttrTokenMap;
 }
 
 SvXMLImportContext *ScXMLImport::CreateContext( sal_uInt16 nPrefix,
@@ -1998,8 +2015,9 @@ ScXMLImport::ScXMLImport(
     pDataPilotMembersElemTokenMap( 0 ),
     pDataPilotMemberAttrTokenMap( 0 ),
     pConsolidationAttrTokenMap( 0 ),
-    pCellTextParaElemTokemMap(NULL),
-    pCellTextSpanAttrTokemMap(NULL),
+    pCellTextParaElemTokenMap(NULL),
+    pCellTextSpanAttrTokenMap(NULL),
+    pCellTextURLAttrTokenMap(NULL),
     aTables(*this),
     pMyNamedExpressions(NULL),
     pMyLabelRanges(NULL),
@@ -2137,8 +2155,9 @@ ScXMLImport::~ScXMLImport() throw()
     delete pDataPilotMembersElemTokenMap;
     delete pDataPilotMemberAttrTokenMap;
     delete pConsolidationAttrTokenMap;
-    delete pCellTextParaElemTokemMap;
-    delete pCellTextSpanAttrTokemMap;
+    delete pCellTextParaElemTokenMap;
+    delete pCellTextSpanAttrTokenMap;
+    delete pCellTextURLAttrTokenMap;
 
     delete pChangeTrackingImportHelper;
     delete pNumberFormatAttributesExportHelper;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index da35d640..09a3639 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -690,7 +690,8 @@ enum ScXMLCellTextParaElemTokens
     XML_TOK_CELL_TEXT_SPAN,
     XML_TOK_CELL_TEXT_SHEET_NAME,
     XML_TOK_CELL_TEXT_DATE,
-    XML_TOK_CELL_TEXT_TITLE
+    XML_TOK_CELL_TEXT_TITLE,
+    XML_TOK_CELL_TEXT_URL
 };
 
 /**
@@ -701,6 +702,12 @@ enum ScXMLCellTextSpanAttrTokens
     XML_TOK_CELL_TEXT_SPAN_ATTR_STYLE_NAME
 };
 
+enum ScXMLCellTextURLAttrTokens
+{
+    XML_TOK_CELL_TEXT_URL_ATTR_UREF,
+    XML_TOK_CELL_TEXT_URL_ATTR_TYPE,
+};
+
 class SvXMLTokenMap;
 class XMLShapeImportHelper;
 class ScXMLChangeTrackingImportHelper;
@@ -869,8 +876,9 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
     SvXMLTokenMap           *pDataPilotMembersElemTokenMap;
     SvXMLTokenMap           *pDataPilotMemberAttrTokenMap;
     SvXMLTokenMap           *pConsolidationAttrTokenMap;
-    SvXMLTokenMap           *pCellTextParaElemTokemMap;
-    SvXMLTokenMap           *pCellTextSpanAttrTokemMap;
+    SvXMLTokenMap           *pCellTextParaElemTokenMap;
+    SvXMLTokenMap           *pCellTextSpanAttrTokenMap;
+    SvXMLTokenMap           *pCellTextURLAttrTokenMap;
 
     ScMyTables              aTables;
 
@@ -1038,6 +1046,7 @@ public:
     const SvXMLTokenMap& GetConsolidationAttrTokenMap();
     const SvXMLTokenMap& GetCellTextParaElemTokenMap();
     const SvXMLTokenMap& GetCellTextSpanAttrTokenMap();
+    const SvXMLTokenMap& GetCellTextURLAttrTokenMap();
 
     void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
     {
commit 31ec3a4acdc9fe13b09c6c7cf8d135e9d90db565
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Feb 11 13:31:26 2013 -0500

    Import date fields.
    
    Change-Id: If37f5253e4e201aab30c54ce503b6c8b6d967d92

diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx
index a4ce72d..abca9d8 100644
--- a/sc/source/filter/xml/celltextparacontext.cxx
+++ b/sc/source/filter/xml/celltextparacontext.cxx
@@ -78,8 +78,9 @@ void ScXMLCellTextParaContext::PushFieldSheetName()
     mrParentCxt.PushParagraphFieldSheetName();
 }
 
-void ScXMLCellTextParaContext::PushFieldDate(const OUString& rOutput)
+void ScXMLCellTextParaContext::PushFieldDate()
 {
+    mrParentCxt.PushParagraphFieldDate();
 }
 
 void ScXMLCellTextParaContext::PushFieldTitle()
@@ -180,11 +181,11 @@ void ScXMLCellFieldDateContext::StartElement(const uno::Reference<xml::sax::XAtt
 
 void ScXMLCellFieldDateContext::EndElement()
 {
+    mrParentCxt.PushFieldDate();
 }
 
-void ScXMLCellFieldDateContext::Characters(const OUString& rChars)
+void ScXMLCellFieldDateContext::Characters(const OUString& /*rChars*/)
 {
-    maDate = rChars;
 }
 
 SvXMLImportContext* ScXMLCellFieldDateContext::CreateChildContext(
@@ -209,9 +210,8 @@ void ScXMLCellFieldTitleContext::EndElement()
     mrParentCxt.PushFieldTitle();
 }
 
-void ScXMLCellFieldTitleContext::Characters(const OUString& rChars)
+void ScXMLCellFieldTitleContext::Characters(const OUString& /*rChars*/)
 {
-    maTitle = rChars;
 }
 
 SvXMLImportContext* ScXMLCellFieldTitleContext::CreateChildContext(
diff --git a/sc/source/filter/xml/celltextparacontext.hxx b/sc/source/filter/xml/celltextparacontext.hxx
index 55ea8ef..e9d11aa 100644
--- a/sc/source/filter/xml/celltextparacontext.hxx
+++ b/sc/source/filter/xml/celltextparacontext.hxx
@@ -33,7 +33,7 @@ public:
 
     void PushSpan(const OUString& rSpan, const OUString& rStyleName);
     void PushFieldSheetName();
-    void PushFieldDate(const OUString& rOutput);
+    void PushFieldDate();
     void PushFieldTitle();
 };
 
@@ -79,7 +79,6 @@ public:
 class ScXMLCellFieldDateContext : public ScXMLImportContext
 {
     ScXMLCellTextParaContext& mrParentCxt;
-    OUString maDate;
 public:
     ScXMLCellFieldDateContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
 
@@ -97,7 +96,6 @@ public:
 class ScXMLCellFieldTitleContext : public ScXMLImportContext
 {
     ScXMLCellTextParaContext& mrParentCxt;
-    OUString maTitle;
 public:
     ScXMLCellFieldTitleContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
 
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 255d5ae..86a6f04 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -570,6 +570,11 @@ void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData)
     rField.maSelection.nEndPos = nPos+1;
 }
 
+void ScXMLTableRowCellContext::PushParagraphFieldDate()
+{
+    PushParagraphField(new SvxDateField);
+}
+
 void ScXMLTableRowCellContext::PushParagraphFieldSheetName()
 {
     SCTAB nTab = GetScImport().GetTables().GetCurrentCellPos().Tab();
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 022d5a2..9fef82b 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -136,6 +136,7 @@ public:
                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
     void PushParagraphSpan(const OUString& rSpan, const OUString& rStyleName);
+    void PushParagraphFieldDate();
     void PushParagraphFieldSheetName();
     void PushParagraphFieldDocTitle();
     void PushParagraphEnd();


More information about the Libreoffice-commits mailing list