Line data Source code
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 :
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 <xmloff/nmspmap.hxx>
28 : #include <sax/tools/converter.hxx>
29 : #include <com/sun/star/sheet/XSheetLinkable.hpp>
30 :
31 : using namespace com::sun::star;
32 : using namespace xmloff::token;
33 :
34 : //------------------------------------------------------------------
35 :
36 0 : ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport& rImport,
37 : sal_uInt16 nPrfx,
38 : const ::rtl::OUString& rLName,
39 : const ::com::sun::star::uno::Reference<
40 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
41 : SvXMLImportContext( rImport, nPrfx, rLName ),
42 : sLink(),
43 : sTableName(),
44 : sFilterName(),
45 : sFilterOptions(),
46 : nRefresh(0),
47 0 : nMode(sheet::SheetLinkMode_NORMAL)
48 : {
49 0 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
50 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
51 : {
52 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
53 0 : rtl::OUString aLocalName;
54 0 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
55 0 : sAttrName, &aLocalName ));
56 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
57 0 : if(nPrefix == XML_NAMESPACE_XLINK)
58 : {
59 0 : if (IsXMLToken(aLocalName, XML_HREF))
60 0 : sLink = GetScImport().GetAbsoluteReference(sValue);
61 : }
62 0 : else if (nPrefix == XML_NAMESPACE_TABLE)
63 : {
64 0 : if (IsXMLToken(aLocalName, XML_TABLE_NAME))
65 0 : sTableName = sValue;
66 0 : else if (IsXMLToken(aLocalName, XML_FILTER_NAME))
67 0 : sFilterName = sValue;
68 0 : else if (IsXMLToken(aLocalName, XML_FILTER_OPTIONS))
69 0 : sFilterOptions = sValue;
70 0 : else if (IsXMLToken(aLocalName, XML_MODE))
71 : {
72 0 : if (IsXMLToken(sValue, XML_COPY_RESULTS_ONLY))
73 0 : nMode = sheet::SheetLinkMode_VALUE;
74 : }
75 0 : else if (IsXMLToken(aLocalName, XML_REFRESH_DELAY))
76 : {
77 : double fTime;
78 0 : if (::sax::Converter::convertDuration( fTime, sValue ))
79 0 : nRefresh = Max( (sal_Int32)(fTime * 86400.0), (sal_Int32)0 );
80 : }
81 : }
82 0 : }
83 0 : }
84 :
85 0 : ScXMLTableSourceContext::~ScXMLTableSourceContext()
86 : {
87 0 : }
88 :
89 0 : SvXMLImportContext *ScXMLTableSourceContext::CreateChildContext( sal_uInt16 nPrefix,
90 : const ::rtl::OUString& rLName,
91 : const ::com::sun::star::uno::Reference<
92 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
93 : {
94 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
95 : }
96 :
97 0 : void ScXMLTableSourceContext::EndElement()
98 : {
99 0 : if (!sLink.isEmpty())
100 : {
101 0 : uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
102 0 : ScDocument* pDoc(GetScImport().GetDocument());
103 0 : if (xLinkable.is() && pDoc)
104 : {
105 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
106 0 : if (pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
107 0 : GetScImport().GetTables().GetCurrentSheetName(), false, sal_True))
108 : {
109 0 : sLink = ScGlobal::GetAbsDocName( sLink, pDoc->GetDocumentShell() );
110 0 : if (sFilterName.isEmpty())
111 0 : ScDocumentLoader::GetFilterName( sLink, sFilterName, sFilterOptions, false, false );
112 :
113 0 : sal_uInt8 nLinkMode = SC_LINK_NONE;
114 0 : if ( nMode == sheet::SheetLinkMode_NORMAL )
115 0 : nLinkMode = SC_LINK_NORMAL;
116 0 : else if ( nMode == sheet::SheetLinkMode_VALUE )
117 0 : nLinkMode = SC_LINK_VALUE;
118 :
119 0 : pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
120 : nLinkMode, sLink, sFilterName, sFilterOptions,
121 0 : sTableName, nRefresh );
122 0 : }
123 0 : }
124 : }
125 0 : }
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|