1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLTableSourceContext.hxx"
21 #include "xmlimprt.hxx"
22 #include <document.hxx>
24 #include "xmlsubti.hxx"
25 #include <tablink.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnamespace.hxx>
28 #include <sax/tools/converter.hxx>
29 #include <com/sun/star/sheet/XSheetLinkable.hpp>
30 #include <com/sun/star/sheet/XSpreadsheet.hpp>
32 using namespace com::sun::star
;
33 using namespace xmloff::token
;
35 ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport
& rImport
,
36 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
37 ScXMLImportContext( rImport
),
39 nMode(sheet::SheetLinkMode_NORMAL
)
41 if ( !rAttrList
.is() )
44 for (auto &aIter
: *rAttrList
)
46 switch (aIter
.getToken())
48 case XML_ELEMENT( XLINK
, XML_HREF
):
49 sLink
= GetScImport().GetAbsoluteReference(aIter
.toString());
51 case XML_ELEMENT( TABLE
, XML_TABLE_NAME
):
52 sTableName
= aIter
.toString();
54 case XML_ELEMENT( TABLE
, XML_FILTER_NAME
):
55 sFilterName
= aIter
.toString();
57 case XML_ELEMENT( TABLE
, XML_FILTER_OPTIONS
):
58 sFilterOptions
= aIter
.toString();
60 case XML_ELEMENT( TABLE
, XML_MODE
):
61 if (IsXMLToken(aIter
, XML_COPY_RESULTS_ONLY
))
62 nMode
= sheet::SheetLinkMode_VALUE
;
64 case XML_ELEMENT( TABLE
, XML_REFRESH_DELAY
):
66 if (::sax::Converter::convertDuration( fTime
, aIter
.toView() ))
67 nRefresh
= std::max( static_cast<sal_Int32
>(fTime
* 86400.0), sal_Int32(0) );
73 ScXMLTableSourceContext::~ScXMLTableSourceContext()
77 void SAL_CALL
ScXMLTableSourceContext::endFastElement( sal_Int32
/*nElement*/ )
82 uno::Reference
<sheet::XSheetLinkable
> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY
);
83 ScDocument
* pDoc(GetScImport().GetDocument());
84 if (!(xLinkable
.is() && pDoc
))
87 ScXMLImport::MutexGuard
aGuard(GetScImport());
88 if (!pDoc
->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
89 GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
92 sLink
= ScGlobal::GetAbsDocName( sLink
, pDoc
->GetDocumentShell() );
93 if (sFilterName
.isEmpty())
94 ScDocumentLoader::GetFilterName( sLink
, sFilterName
, sFilterOptions
, false, false );
96 ScLinkMode nLinkMode
= ScLinkMode::NONE
;
97 if ( nMode
== sheet::SheetLinkMode_NORMAL
)
98 nLinkMode
= ScLinkMode::NORMAL
;
99 else if ( nMode
== sheet::SheetLinkMode_VALUE
)
100 nLinkMode
= ScLinkMode::VALUE
;
102 pDoc
->SetLink( GetScImport().GetTables().GetCurrentSheet(),
103 nLinkMode
, sLink
, sFilterName
, sFilterOptions
,
104 sTableName
, nRefresh
);
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */