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>
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>
30 using namespace com::sun::star
;
31 using namespace xmloff::token
;
33 ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport
& rImport
,
34 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
35 ScXMLImportContext( rImport
),
41 nMode(sheet::SheetLinkMode_NORMAL
)
45 for (auto &aIter
: *rAttrList
)
47 switch (aIter
.getToken())
49 case XML_ELEMENT( XLINK
, XML_HREF
):
50 sLink
= GetScImport().GetAbsoluteReference(aIter
.toString());
52 case XML_ELEMENT( TABLE
, XML_TABLE_NAME
):
53 sTableName
= aIter
.toString();
55 case XML_ELEMENT( TABLE
, XML_FILTER_NAME
):
56 sFilterName
= aIter
.toString();
58 case XML_ELEMENT( TABLE
, XML_FILTER_OPTIONS
):
59 sFilterOptions
= aIter
.toString();
61 case XML_ELEMENT( TABLE
, XML_MODE
):
62 if (IsXMLToken(aIter
, XML_COPY_RESULTS_ONLY
))
63 nMode
= sheet::SheetLinkMode_VALUE
;
65 case XML_ELEMENT( TABLE
, XML_REFRESH_DELAY
):
67 if (::sax::Converter::convertDuration( fTime
, aIter
.toString() ))
68 nRefresh
= std::max( static_cast<sal_Int32
>(fTime
* 86400.0), sal_Int32(0) );
75 ScXMLTableSourceContext::~ScXMLTableSourceContext()
79 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLTableSourceContext::createFastChildContext(
80 sal_Int32
/*nElement*/, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
82 return new SvXMLImportContext( GetImport() );
85 void SAL_CALL
ScXMLTableSourceContext::endFastElement( sal_Int32
/*nElement*/ )
89 uno::Reference
<sheet::XSheetLinkable
> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY
);
90 ScDocument
* pDoc(GetScImport().GetDocument());
91 if (xLinkable
.is() && pDoc
)
93 ScXMLImport::MutexGuard
aGuard(GetScImport());
94 if (pDoc
->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
95 GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
97 sLink
= ScGlobal::GetAbsDocName( sLink
, pDoc
->GetDocumentShell() );
98 if (sFilterName
.isEmpty())
99 ScDocumentLoader::GetFilterName( sLink
, sFilterName
, sFilterOptions
, false, false );
101 ScLinkMode nLinkMode
= ScLinkMode::NONE
;
102 if ( nMode
== sheet::SheetLinkMode_NORMAL
)
103 nLinkMode
= ScLinkMode::NORMAL
;
104 else if ( nMode
== sheet::SheetLinkMode_VALUE
)
105 nLinkMode
= ScLinkMode::VALUE
;
107 pDoc
->SetLink( GetScImport().GetTables().GetCurrentSheet(),
108 nLinkMode
, sLink
, sFilterName
, sFilterOptions
,
109 sTableName
, nRefresh
);
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */