1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <comphelper/processfactory.hxx>
11 #include <sfx2/linkmgr.hxx>
12 #include <sfx2/bindings.hxx>
14 #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
15 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
16 #include <com/sun/star/io/XInputStream.hpp>
18 #include <tools/hostfilter.hxx>
19 #include <tools/urlobj.hxx>
22 #include <webservicelink.hxx>
24 #include <document.hxx>
27 ScWebServiceLink::ScWebServiceLink(ScDocument
* pD
, OUString _aURL
)
28 : ::sfx2::SvBaseLink(SfxLinkUpdateMode::ALWAYS
, SotClipboardFormatId::STRING
)
30 , aURL(std::move(_aURL
))
35 ScWebServiceLink::~ScWebServiceLink() {}
37 sfx2::SvBaseLink::UpdateResult
ScWebServiceLink::DataChanged(const OUString
&, const css::uno::Any
&)
42 INetURLObject
aURLObject(aURL
);
43 const OUString sHost
= aURLObject
.GetHost();
44 if (HostFilter::isForbidden(sHost
))
46 SAL_WARN("sc.ui", "ScWebServiceLink::DataChanged: blocked access to external file: \""
51 css::uno::Reference
<css::ucb::XSimpleFileAccess3
> xFileAccess
52 = css::ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext());
53 if (!xFileAccess
.is())
56 css::uno::Reference
<css::io::XInputStream
> xStream
;
59 xStream
= xFileAccess
->openFileRead(aURL
);
63 // don't let any exceptions pass
69 const sal_Int32 BUF_LEN
= 8000;
70 css::uno::Sequence
<sal_Int8
> buffer(BUF_LEN
);
71 OStringBuffer
aBuffer(64000);
74 while ((nRead
= xStream
->readBytes(buffer
, BUF_LEN
)) == BUF_LEN
)
75 aBuffer
.append(reinterpret_cast<const char*>(buffer
.getConstArray()), nRead
);
78 aBuffer
.append(reinterpret_cast<const char*>(buffer
.getConstArray()), nRead
);
80 xStream
->closeInput();
82 aResult
= OStringToOUString(aBuffer
, RTL_TEXTENCODING_UTF8
);
85 // Something happened...
88 Broadcast(ScHint(SfxHintId::ScDataChanged
, ScAddress()));
89 pDoc
->TrackFormulas(); // must happen immediately
90 pDoc
->StartTrackTimer();
96 void ScWebServiceLink::ListenersGone()
98 ScDocument
* pStackDoc
= pDoc
; // member pDoc can't be used after removing the link
100 sfx2::LinkManager
* pLinkMgr
= pDoc
->GetLinkManager();
101 pLinkMgr
->Remove(this); // deletes this
103 if (pLinkMgr
->GetLinks().empty()) // deleted the last one ?
105 SfxBindings
* pBindings
= pStackDoc
->GetViewBindings(); // don't use member pDoc!
107 pBindings
->Invalidate(SID_LINKS
);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */