LibreOffice Module sc (master) 1
webservicelink.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11#include <sfx2/linkmgr.hxx>
12#include <sfx2/bindings.hxx>
13
14#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
15#include <com/sun/star/ucb/SimpleFileAccess.hpp>
16#include <com/sun/star/io/XInputStream.hpp>
17
18#include <utility>
19#include <webservicelink.hxx>
20#include <brdcst.hxx>
21#include <document.hxx>
22#include <sc.hrc>
23
26 , pDoc(pD)
27 , aURL(std::move(_aURL))
28 , bHasResult(false)
29{
30}
31
33
35{
36 aResult.clear();
37 bHasResult = false;
38
39 css::uno::Reference<css::ucb::XSimpleFileAccess3> xFileAccess
40 = css::ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext());
41 if (!xFileAccess.is())
42 return ERROR_GENERAL;
43
44 css::uno::Reference<css::io::XInputStream> xStream;
45 try
46 {
47 xStream = xFileAccess->openFileRead(aURL);
48 }
49 catch (...)
50 {
51 // don't let any exceptions pass
52 return ERROR_GENERAL;
53 }
54 if (!xStream.is())
55 return ERROR_GENERAL;
56
57 const sal_Int32 BUF_LEN = 8000;
58 css::uno::Sequence<sal_Int8> buffer(BUF_LEN);
59 OStringBuffer aBuffer(64000);
60
61 sal_Int32 nRead = 0;
62 while ((nRead = xStream->readBytes(buffer, BUF_LEN)) == BUF_LEN)
63 aBuffer.append(reinterpret_cast<const char*>(buffer.getConstArray()), nRead);
64
65 if (nRead > 0)
66 aBuffer.append(reinterpret_cast<const char*>(buffer.getConstArray()), nRead);
67
68 xStream->closeInput();
69
70 aResult = OStringToOUString(aBuffer, RTL_TEXTENCODING_UTF8);
71 bHasResult = true;
72
73 // Something happened...
74 if (HasListeners())
75 {
76 Broadcast(ScHint(SfxHintId::ScDataChanged, ScAddress()));
77 pDoc->TrackFormulas(); // must happen immediately
79 }
80
81 return SUCCESS;
82}
83
85{
86 ScDocument* pStackDoc = pDoc; // member pDoc can't be used after removing the link
87
89 pLinkMgr->Remove(this); // deletes this
90
91 if (pLinkMgr->GetLinks().empty()) // deleted the last one ?
92 {
93 SfxBindings* pBindings = pStackDoc->GetViewBindings(); // don't use member pDoc!
94 if (pBindings)
95 pBindings->Invalidate(SID_LINKS);
96 }
97}
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Reference< XInputStream > xStream
void TrackFormulas(SfxHintId nHintId=SfxHintId::ScDataChanged)
Definition: documen7.cxx:524
SfxBindings * GetViewBindings()
Definition: documen8.cxx:1183
void StartTrackTimer()
Definition: documen2.cxx:332
SC_DLLPUBLIC sfx2::LinkManager * GetLinkManager()
Definition: documen2.cxx:231
void Invalidate(sal_uInt16 nId)
bool HasListeners() const
void Broadcast(const SfxHint &rHint)
void Remove(SvBaseLink const *pLink)
const SvBaseLinks & GetLinks() const
URL aURL
SotClipboardFormatId
STRING
SfxLinkUpdateMode
Reference< XComponentContext > getProcessComponentContext()
std::unique_ptr< char[]> aBuffer