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 "xmlFileBasedDatabase.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "xmlEnums.hxx"
26 #include "xmlstrings.hrc"
27 #include <tools/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 #include <comphelper/sequence.hxx>
30 #include <svl/filenotation.hxx>
31 #include <unotools/pathoptions.hxx>
32 #include "dsntypes.hxx"
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::xml::sax
;
37 DBG_NAME(OXMLFileBasedDatabase
)
39 OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter
& rImport
,
40 sal_uInt16 nPrfx
, const ::rtl::OUString
& _sLocalName
,
41 const Reference
< XAttributeList
> & _xAttrList
) :
42 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
44 DBG_CTOR(OXMLFileBasedDatabase
,NULL
);
46 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
47 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
48 const SvXMLTokenMap
& rTokenMap
= rImport
.GetDataSourceElemTokenMap();
50 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
52 PropertyValue aProperty
;
54 const sal_Int16 nLength
= (xDataSource
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
55 ::rtl::OUString sLocation
,sMediaType
,sFileTypeExtension
;
56 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
58 ::rtl::OUString sLocalName
;
59 const rtl::OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
60 const sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
61 const rtl::OUString sValue
= _xAttrList
->getValueByIndex( i
);
63 aProperty
.Name
= ::rtl::OUString();
64 aProperty
.Value
= Any();
66 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
70 SvtPathOptions aPathOptions
;
71 rtl::OUString sFileName
= aPathOptions
.SubstituteVariable(sValue
);
72 if ( sValue
== sFileName
)
74 const sal_Int32 nFileNameLength
= sFileName
.getLength();
75 if ( ( nFileNameLength
> 0 ) && ( sFileName
.getStr()[ nFileNameLength
- 1 ] == '/' ) )
76 sFileName
= sFileName
.copy( 0, nFileNameLength
- 1 );
78 sLocation
= ::svt::OFileNotation( rImport
.GetAbsoluteReference( sFileName
) ).get( ::svt::OFileNotation::N_SYSTEM
);
81 if ( sLocation
.isEmpty() )
85 case XML_TOK_MEDIA_TYPE
:
88 case XML_TOK_EXTENSION
:
89 aProperty
.Name
= INFO_TEXTFILEEXTENSION
;
90 sFileTypeExtension
= sValue
;
93 if ( !aProperty
.Name
.isEmpty() )
95 if ( !aProperty
.Value
.hasValue() )
96 aProperty
.Value
<<= sValue
;
97 rImport
.addInfo(aProperty
);
100 if ( !(sLocation
.isEmpty() || sMediaType
.isEmpty()) )
102 ::dbaccess::ODsnTypeCollection
aTypeCollection(rImport
.getORB());
103 ::rtl::OUString
sURL(aTypeCollection
.getDatasourcePrefixFromMediaType(sMediaType
,sFileTypeExtension
));
107 xDataSource
->setPropertyValue(PROPERTY_URL
,makeAny(sURL
));
109 catch(const Exception
&)
111 DBG_UNHANDLED_EXCEPTION();
115 // -----------------------------------------------------------------------------
117 OXMLFileBasedDatabase::~OXMLFileBasedDatabase()
120 DBG_DTOR(OXMLFileBasedDatabase
,NULL
);
122 // -----------------------------------------------------------------------------
123 //----------------------------------------------------------------------------
124 } // namespace dbaxml
125 // -----------------------------------------------------------------------------
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */