nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / XMLTableSourceContext.cxx
blobc64fd897087efc83a41d460e95bb8e6cd35601b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/xmlnamespace.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <com/sun/star/sheet/XSheetLinkable.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
31 using namespace com::sun::star;
32 using namespace xmloff::token;
34 ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport& rImport,
35 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
36 ScXMLImportContext( rImport ),
37 sLink(),
38 sTableName(),
39 sFilterName(),
40 sFilterOptions(),
41 nRefresh(0),
42 nMode(sheet::SheetLinkMode_NORMAL)
44 if ( !rAttrList.is() )
45 return;
47 for (auto &aIter : *rAttrList)
49 switch (aIter.getToken())
51 case XML_ELEMENT( XLINK, XML_HREF ):
52 sLink = GetScImport().GetAbsoluteReference(aIter.toString());
53 break;
54 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
55 sTableName = aIter.toString();
56 break;
57 case XML_ELEMENT( TABLE, XML_FILTER_NAME):
58 sFilterName = aIter.toString();
59 break;
60 case XML_ELEMENT( TABLE, XML_FILTER_OPTIONS ):
61 sFilterOptions = aIter.toString();
62 break;
63 case XML_ELEMENT( TABLE, XML_MODE ):
64 if (IsXMLToken(aIter, XML_COPY_RESULTS_ONLY))
65 nMode = sheet::SheetLinkMode_VALUE;
66 break;
67 case XML_ELEMENT( TABLE, XML_REFRESH_DELAY ):
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;
76 ScXMLTableSourceContext::~ScXMLTableSourceContext()
80 void SAL_CALL ScXMLTableSourceContext::endFastElement( sal_Int32 /*nElement*/ )
82 if (sLink.isEmpty())
83 return;
85 uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
86 ScDocument* pDoc(GetScImport().GetDocument());
87 if (!(xLinkable.is() && pDoc))
88 return;
90 ScXMLImport::MutexGuard aGuard(GetScImport());
91 if (!pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
92 GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
93 return;
95 sLink = ScGlobal::GetAbsDocName( sLink, pDoc->GetDocumentShell() );
96 if (sFilterName.isEmpty())
97 ScDocumentLoader::GetFilterName( sLink, sFilterName, sFilterOptions, false, false );
99 ScLinkMode nLinkMode = ScLinkMode::NONE;
100 if ( nMode == sheet::SheetLinkMode_NORMAL )
101 nLinkMode = ScLinkMode::NORMAL;
102 else if ( nMode == sheet::SheetLinkMode_VALUE )
103 nLinkMode = ScLinkMode::VALUE;
105 pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
106 nLinkMode, sLink, sFilterName, sFilterOptions,
107 sTableName, nRefresh );
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */