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/xmlnmspe.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  sLink(),
38  sTableName(),
39  sFilterName(),
40  sFilterOptions(),
41  nRefresh(0),
42  nMode(sheet::SheetLinkMode_NORMAL)
43 {
44  if ( !rAttrList.is() )
45  return;
46 
47  for (auto &aIter : *rAttrList)
48  {
49  switch (aIter.getToken())
50  {
51  case XML_ELEMENT( XLINK, XML_HREF ):
52  sLink = GetScImport().GetAbsoluteReference(aIter.toString());
53  break;
55  sTableName = aIter.toString();
56  break;
58  sFilterName = aIter.toString();
59  break;
61  sFilterOptions = aIter.toString();
62  break;
63  case XML_ELEMENT( TABLE, XML_MODE ):
65  nMode = sheet::SheetLinkMode_VALUE;
66  break;
68  double fTime;
69  if (::sax::Converter::convertDuration( fTime, aIter.toString() ))
70  nRefresh = std::max( static_cast<sal_Int32>(fTime * 86400.0), sal_Int32(0) );
71  break;
72  }
73  }
74 }
75 
77 {
78 }
79 
80 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTableSourceContext::createFastChildContext(
81  sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
82 {
83  return nullptr;
84 }
85 
86 void SAL_CALL ScXMLTableSourceContext::endFastElement( sal_Int32 /*nElement*/ )
87 {
88  if (sLink.isEmpty())
89  return;
90 
91  uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
92  ScDocument* pDoc(GetScImport().GetDocument());
93  if (!(xLinkable.is() && pDoc))
94  return;
95 
97  if (!pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
98  GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
99  return;
100 
102  if (sFilterName.isEmpty())
104 
105  ScLinkMode nLinkMode = ScLinkMode::NONE;
106  if ( nMode == sheet::SheetLinkMode_NORMAL )
107  nLinkMode = ScLinkMode::NORMAL;
108  else if ( nMode == sheet::SheetLinkMode_VALUE )
109  nLinkMode = ScLinkMode::VALUE;
110 
111  pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
112  nLinkMode, sLink, sFilterName, sFilterOptions,
113  sTableName, nRefresh );
114 }
115 
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
XML_TABLE_NAME
virtual ~ScXMLTableSourceContext() override
XML_FILTER_OPTIONS
exports com.sun.star. sheet
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:852
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScLinkMode
Definition: global.hxx:225
XML_COPY_RESULTS_ONLY
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:284
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
XML_REFRESH_DELAY
ScXMLTableSourceContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
XML_HREF
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:527
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:392
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
ScXMLImport & GetScImport()
TABLE
OUString GetAbsoluteReference(const OUString &rValue) const
XML_FILTER_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:1061
XML_MODE
css::sheet::SheetLinkMode nMode