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>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <com/sun/star/sheet/XSheetLinkable.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
30 
31 using namespace com::sun::star;
32 using 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.toString() ))
66  nRefresh = std::max( static_cast<sal_Int32>(fTime * 86400.0), sal_Int32(0) );
67  break;
68  }
69  }
70 }
71 
73 {
74 }
75 
76 void 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,
103  sTableName, nRefresh );
104 }
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_COPY_RESULTS_ONLY
virtual ~ScXMLTableSourceContext() override
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
exports com.sun.star. sheet
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:853
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScLinkMode
Definition: global.hxx:212
XML_HREF
XML_FILTER_OPTIONS
This class exists only to provide GetScImport() to its derived classes.
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
Definition: global2.cxx:285
XML_REFRESH_DELAY
ScXMLTableSourceContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:546
XML_FILTER_NAME
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:288
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
ScXMLImport & GetScImport()
TABLE
OUString GetAbsoluteReference(const OUString &rValue) const
XML_TABLE_NAME
#define XML_ELEMENT(prefix, name)
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:432
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1057
XML_MODE
css::sheet::SheetLinkMode nMode