summaryrefslogtreecommitdiff
path: root/sc/source/ui/xmlsource
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-11-21 15:21:41 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-11-28 13:28:32 -0500
commit9d6ed5dd8ba3824ba0f1a9d179cfd9b2f8ba75b3 (patch)
treedd23779631b40ffca0f8becdda3223b484e9ee29 /sc/source/ui/xmlsource
parent3db55f9da3577653911c683091c72722288bc456 (diff)
Correctly handle xml namespaces when importing xml content.
But it's still not working. I need to dig some more. Change-Id: I06d4d70e1a4234b031741a496f2651d016c35ecc
Diffstat (limited to 'sc/source/ui/xmlsource')
-rw-r--r--sc/source/ui/xmlsource/xmlsourcedlg.cxx31
1 files changed, 24 insertions, 7 deletions
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 5019306d6e7f..38a1d09954d3 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -39,7 +39,8 @@ bool isAttribute(const SvTreeListEntry& rEntry)
return pUserData->meType == ScOrcusXMLTreeParam::Attribute;
}
-OUString getXPath(const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
+OUString getXPath(
+ const SvTreeListBox& rTree, const SvTreeListEntry& rEntry, std::vector<size_t>& rNamespaces)
{
OUStringBuffer aBuf;
for (const SvTreeListEntry* p = &rEntry; p; p = rTree.GetParent(p))
@@ -48,6 +49,11 @@ OUString getXPath(const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
if (!pItem)
continue;
+ // Collect used namespace.
+ const ScOrcusXMLTreeParam::EntryData* pData = ScOrcusXMLTreeParam::getUserData(*p);
+ if (pData)
+ rNamespaces.push_back(pData->mnNamespaceID);
+
const SvLBoxString* pStr = static_cast<const SvLBoxString*>(pItem);
aBuf.insert(0, pStr->GetText());
aBuf.insert(0, isAttribute(*p) ? '@' : '/');
@@ -428,7 +434,9 @@ namespace {
/**
* Pick only the leaf elements.
*/
-void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
+void getFieldLinks(
+ ScOrcusImportXMLParam::RangeLink& rRangeLink, std::vector<size_t>& rNamespaces,
+ const SvTreeListBox& rTree, const SvTreeListEntry& rEntry)
{
const SvTreeListEntries& rChildren = rEntry.GetChildEntries();
if (rChildren.empty())
@@ -439,7 +447,7 @@ void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeLis
for (; it != itEnd; ++it)
{
const SvTreeListEntry& rChild = *it;
- OUString aPath = getXPath(rTree, rChild);
+ OUString aPath = getXPath(rTree, rChild, rNamespaces);
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rChild);
if (pUserData && pUserData->mbLeafNode)
@@ -450,10 +458,17 @@ void getFieldLinks(ScOrcusImportXMLParam::RangeLink& rRangeLink, const SvTreeLis
}
// Walk recursively.
- getFieldLinks(rRangeLink, rTree, rChild);
+ getFieldLinks(rRangeLink, rNamespaces, rTree, rChild);
}
}
+void removeDuplicates(std::vector<size_t>& rArray)
+{
+ std::sort(rArray.begin(), rArray.end());
+ std::vector<size_t>::iterator it = std::unique(rArray.begin(), rArray.end());
+ rArray.erase(it, rArray.end());
+}
+
}
void ScXMLSourceDlg::OkPressed()
@@ -471,7 +486,7 @@ void ScXMLSourceDlg::OkPressed()
for (; it != itEnd; ++it)
{
const SvTreeListEntry& rEntry = **it;
- OUString aPath = getXPath(maLbTree, rEntry);
+ OUString aPath = getXPath(maLbTree, rEntry, aParam.maNamespaces);
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rEntry);
aParam.maCellLinks.push_back(
@@ -493,14 +508,16 @@ void ScXMLSourceDlg::OkPressed()
aRangeLink.maPos = pUserData->maLinkedPos;
// Go through all its child elements.
- getFieldLinks(aRangeLink, maLbTree, rEntry);
+ getFieldLinks(aRangeLink, aParam.maNamespaces, maLbTree, rEntry);
aParam.maRangeLinks.push_back(aRangeLink);
}
}
- // Now do the import.
+ // Remove duplicate namespace IDs.
+ removeDuplicates(aParam.maNamespaces);
+ // Now do the import.
mpXMLContext->importXML(aParam);
// Don't forget to broadcast the change.