Skip to content

Commit

Permalink
One more proper construction of vnd.sun.star.pkg URL
Browse files Browse the repository at this point in the history
Change-Id: I4b1bfc9c9b158506424ec0b5e2fd71c6ccb7d3ec
Reviewed-on: https://gerrit.libreoffice.org/44917
Tested-by: Jenkins <[email protected]>
Reviewed-by: Mike Kaganski <[email protected]>
  • Loading branch information
mikekaganski committed Nov 18, 2017
1 parent 49098da commit 06756e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions sw/inc/dbmgr.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ public:
void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
const OUString& getEmbeddedName() const;

// rOwnURL should be taken using INetURLObject::GetMainURL(INetURLObject::DecodeMechanism::NONE)
static void StoreEmbeddedDataSource(const css::uno::Reference<css::frame::XStorable>& xStorable,
const css::uno::Reference<css::embed::XStorage>& xStorage,
const OUString& rStreamRelPath,
Expand Down
39 changes: 23 additions & 16 deletions sw/source/uibase/dbui/dbmgr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ OUString lcl_getOwnURL(SwDocShell const * pDocShell)
return aRet;

const INetURLObject& rURLObject = pDocShell->GetMedium()->GetURLObject();
aRet = rURLObject.GetMainURL(INetURLObject::DecodeMechanism::WithCharset);
aRet = rURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE);
return aRet;
}

Expand Down Expand Up @@ -2781,11 +2781,11 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const

uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, uno::UNO_QUERY_THROW);
uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW);
OUString sOutputExt = ".odb";
OUString aOwnURL = lcl_getOwnURL(pDocShell);
if (aOwnURL.isEmpty())
{
// Cannot embed, as embedded data source would need the URL of the parent document.
OUString const sOutputExt = ".odb";
OUString sHomePath(SvtPathOptions().GetWorkPath());
utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath);
OUString sTmpName = aTempFile.GetURL();
Expand Down Expand Up @@ -2816,15 +2816,30 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
return sFind;
}

namespace {
// Construct vnd.sun.star.pkg:// URL
OUString ConstructVndSunStarPkgUrl(const OUString& rMainURL, const OUString& rStreamRelPath)
{
auto xContext(comphelper::getProcessComponentContext());
auto xUri = css::uri::UriReferenceFactory::create(xContext)->parse(rMainURL);
assert(xUri.is());
xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)
->createVndSunStarPkgUrlReference(xUri);
assert(xUri.is());
return xUri->getUriReference() + "/"
+ INetURLObject::encode(
rStreamRelPath, INetURLObject::PART_FPATH,
INetURLObject::EncodeMechanism::All);
}
}

void SwDBManager::StoreEmbeddedDataSource(const uno::Reference<frame::XStorable>& xStorable,
const uno::Reference<embed::XStorage>& xStorage,
const OUString& rStreamRelPath,
const OUString& rOwnURL)
{
// Construct vnd.sun.star.pkg:// URL for later loading, and TargetStorage/StreamRelPath for storing.
OUString sTmpName = "vnd.sun.star.pkg://";
sTmpName += INetURLObject::encode(rOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::EncodeMechanism::All);
sTmpName += "/" + rStreamRelPath;
OUString const sTmpName = ConstructVndSunStarPkgUrl(rOwnURL, rStreamRelPath);

uno::Sequence<beans::PropertyValue> aSequence = comphelper::InitPropertySequence(
{
Expand Down Expand Up @@ -2863,17 +2878,9 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const

// Encode the stream name and the real path into a single URL.
const INetURLObject& rURLObject = rDocShell.GetMedium()->GetURLObject();
auto xContext(comphelper::getProcessComponentContext());
auto xUri = css::uri::UriReferenceFactory::create(xContext)
->parse(rURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE));
assert(xUri.is());
xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)
->createVndSunStarPkgUrlReference(xUri);
assert(xUri.is());
OUString const aURL = xUri->getUriReference() + "/"
+ INetURLObject::encode(
m_sEmbeddedName, INetURLObject::PART_FPATH,
INetURLObject::EncodeMechanism::All);
OUString const aURL = ConstructVndSunStarPkgUrl(
rURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE),
m_sEmbeddedName);

uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
xDatabaseContext->registerObject( sDataSource, xDataSource );
Expand Down

0 comments on commit 06756e4

Please sign in to comment.