LibreOffice Module sc (master) 1
XMLTableSourceContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21#include "xmlimprt.hxx"
22#include <document.hxx>
23#include "xmlsubti.hxx"
24#include <tablink.hxx>
25#include <xmloff/xmltoken.hxx>
28#include <com/sun/star/sheet/XSheetLinkable.hpp>
29#include <com/sun/star/sheet/XSpreadsheet.hpp>
30
31using namespace com::sun::star;
32using namespace xmloff::token;
33
36 ScXMLImportContext( rImport ),
37 nRefresh(0),
38 nMode(sheet::SheetLinkMode_NORMAL)
39{
40 if ( !rAttrList.is() )
41 return;
42
43 for (auto &aIter : *rAttrList)
44 {
45 switch (aIter.getToken())
46 {
47 case XML_ELEMENT( XLINK, XML_HREF ):
48 sLink = GetScImport().GetAbsoluteReference(aIter.toString());
49 break;
51 sTableName = aIter.toString();
52 break;
54 sFilterName = aIter.toString();
55 break;
57 sFilterOptions = aIter.toString();
58 break;
59 case XML_ELEMENT( TABLE, XML_MODE ):
61 nMode = sheet::SheetLinkMode_VALUE;
62 break;
64 double fTime;
65 if (::sax::Converter::convertDuration( fTime, aIter.toView() ))
66 nRefresh = std::max( static_cast<sal_Int32>(fTime * 86400.0), sal_Int32(0) );
67 break;
68 }
69 }
70}
71
73{
74}
75
76void SAL_CALL ScXMLTableSourceContext::endFastElement( sal_Int32 /*nElement*/ )
77{
78 if (sLink.isEmpty())
79 return;
80
81 uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
82 ScDocument* pDoc(GetScImport().GetDocument());
83 if (!(xLinkable.is() && pDoc))
84 return;
85
87 if (!pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
88 GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
89 return;
90
92 if (sFilterName.isEmpty())
94
95 ScLinkMode nLinkMode = ScLinkMode::NONE;
96 if ( nMode == sheet::SheetLinkMode_NORMAL )
97 nLinkMode = ScLinkMode::NORMAL;
98 else if ( nMode == sheet::SheetLinkMode_VALUE )
99 nLinkMode = ScLinkMode::VALUE;
100
101 pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
102 nLinkMode, sLink, sFilterName, sFilterOptions,
104}
105
106/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool GetFilterName(const OUString &rFileName, OUString &rFilter, OUString &rOptions, bool bWithContent, bool bWithInteraction)
Returns the filter name and options from a file name.
Definition: tablink.cxx:431
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:837
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:544
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
Definition: global2.cxx:287
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:289
css::sheet::SheetLinkMode nMode
virtual ~ScXMLTableSourceContext() override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLTableSourceContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
ScLinkMode
Definition: global.hxx:215
TABLE
XML_TABLE_NAME
XML_HREF
XML_MODE
XML_FILTER_OPTIONS
XML_REFRESH_DELAY
XML_FILTER_NAME
XML_COPY_RESULTS_ONLY
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
#define XML_ELEMENT(prefix, name)