diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-02-11 14:08:01 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-02-11 22:33:35 -0500 |
commit | 9e9f863727d12ef1a397bfd9f3b13259ed8d71b1 (patch) | |
tree | 65f7cf5e5783fdd217b41f2a988fbe9566ee77b0 | |
parent | cbf0cad82100308d6094eabf2440e53961b3329e (diff) |
Import URL fields as well. Now I'm done.
Also fix Tokem to Token typos.
Change-Id: If22b673f6833f3fd485472b17ec508e616e0d59d
-rw-r--r-- | sc/source/filter/xml/celltextparacontext.cxx | 62 | ||||
-rw-r--r-- | sc/source/filter/xml/celltextparacontext.hxx | 22 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.cxx | 5 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.hxx | 1 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 39 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 15 |
6 files changed, 127 insertions, 17 deletions
diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx index abca9d8edaa0..ddc0fc3fed6e 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 e9d11aa3ad30..9390a3eec275 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 86a6f0451227..701e784fd8dd 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 9fef82bbfe7f..e59aa6eab839 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 fb5516f8ff02..bd5fd4de8010 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 da35d6408c7b..09a3639a6cf0 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) { |