Update ooo320-m1
[ooovba.git] / sc / source / filter / xml / XMLTableSourceContext.cxx
blobc52a34fa5a515d5e5ed1919dada6359f4e0c77db
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTableSourceContext.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include "XMLTableSourceContext.hxx"
38 #include "xmlimprt.hxx"
39 #include "document.hxx"
40 #include "xmlsubti.hxx"
41 #include "tablink.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmlnmspe.hxx>
44 #include <xmloff/nmspmap.hxx>
45 #include <xmloff/xmluconv.hxx>
46 #include <com/sun/star/sheet/XSheetLinkable.hpp>
48 using namespace com::sun::star;
49 using namespace xmloff::token;
51 //------------------------------------------------------------------
53 ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport& rImport,
54 USHORT nPrfx,
55 const ::rtl::OUString& rLName,
56 const ::com::sun::star::uno::Reference<
57 ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
58 SvXMLImportContext( rImport, nPrfx, rLName ),
59 sLink(),
60 sTableName(),
61 sFilterName(),
62 sFilterOptions(),
63 nRefresh(0),
64 nMode(sheet::SheetLinkMode_NORMAL)
66 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
67 for( sal_Int16 i=0; i < nAttrCount; ++i )
69 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
70 rtl::OUString aLocalName;
71 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
72 sAttrName, &aLocalName ));
73 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
74 if(nPrefix == XML_NAMESPACE_XLINK)
76 if (IsXMLToken(aLocalName, XML_HREF))
77 sLink = GetScImport().GetAbsoluteReference(sValue);
79 else if (nPrefix == XML_NAMESPACE_TABLE)
81 if (IsXMLToken(aLocalName, XML_TABLE_NAME))
82 sTableName = sValue;
83 else if (IsXMLToken(aLocalName, XML_FILTER_NAME))
84 sFilterName = sValue;
85 else if (IsXMLToken(aLocalName, XML_FILTER_OPTIONS))
86 sFilterOptions = sValue;
87 else if (IsXMLToken(aLocalName, XML_MODE))
89 if (IsXMLToken(sValue, XML_COPY_RESULTS_ONLY))
90 nMode = sheet::SheetLinkMode_VALUE;
92 else if (IsXMLToken(aLocalName, XML_REFRESH_DELAY))
94 double fTime;
95 if( SvXMLUnitConverter::convertTime( fTime, sValue ) )
96 nRefresh = Max( (sal_Int32)(fTime * 86400.0), (sal_Int32)0 );
102 ScXMLTableSourceContext::~ScXMLTableSourceContext()
106 SvXMLImportContext *ScXMLTableSourceContext::CreateChildContext( USHORT nPrefix,
107 const ::rtl::OUString& rLName,
108 const ::com::sun::star::uno::Reference<
109 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
111 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
114 void ScXMLTableSourceContext::EndElement()
116 if (sLink.getLength())
118 uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
119 ScDocument* pDoc(GetScImport().GetDocument());
120 if (xLinkable.is() && pDoc)
122 GetScImport().LockSolarMutex();
123 if (pDoc->RenameTab( static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet()),
124 GetScImport().GetTables().GetCurrentSheetName(), sal_False, sal_True))
126 String aFileString(sLink);
127 String aFilterString(sFilterName);
128 String aOptString(sFilterOptions);
129 String aSheetString(sTableName);
131 aFileString = ScGlobal::GetAbsDocName( aFileString, pDoc->GetDocumentShell() );
132 if ( !aFilterString.Len() )
133 ScDocumentLoader::GetFilterName( aFileString, aFilterString, aOptString, FALSE, FALSE );
135 BYTE nLinkMode = SC_LINK_NONE;
136 if ( nMode == sheet::SheetLinkMode_NORMAL )
137 nLinkMode = SC_LINK_NORMAL;
138 else if ( nMode == sheet::SheetLinkMode_VALUE )
139 nLinkMode = SC_LINK_VALUE;
141 pDoc->SetLink( static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet()),
142 nLinkMode, aFileString, aFilterString, aOptString,
143 aSheetString, nRefresh );
145 GetScImport().UnlockSolarMutex();