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/xmlnamespace.hxx>
24 #include <strings.hxx>
25 #include <comphelper/diagnose_ex.hxx>
26 #include <svl/filenotation.hxx>
27 #include <unotools/pathoptions.hxx>
28 #include <dsntypes.hxx>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::xml::sax
;
34 OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter
& rImport
,
35 const Reference
< XFastAttributeList
> & _xAttrList
) :
36 SvXMLImportContext( rImport
)
38 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
40 PropertyValue aProperty
;
42 OUString sLocation
,sMediaType
,sFileTypeExtension
;
45 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
47 OUString sValue
= aIter
.toString();
49 aProperty
.Name
.clear();
50 aProperty
.Value
= Any();
52 switch( aIter
.getToken() )
54 case XML_ELEMENT(XLINK
, XML_HREF
):
56 SvtPathOptions aPathOptions
;
57 OUString sFileName
= aPathOptions
.SubstituteVariable(sValue
);
58 if ( sValue
== sFileName
)
60 const sal_Int32 nFileNameLength
= sFileName
.getLength();
61 if ( sFileName
.endsWith("/") )
62 sFileName
= sFileName
.copy( 0, nFileNameLength
- 1 );
64 sLocation
= ::svt::OFileNotation( rImport
.GetAbsoluteReference( sFileName
) ).get( ::svt::OFileNotation::N_SYSTEM
);
67 if ( sLocation
.isEmpty() )
71 case XML_ELEMENT(DB
, XML_MEDIA_TYPE
):
72 case XML_ELEMENT(DB_OASIS
, XML_MEDIA_TYPE
):
75 case XML_ELEMENT(DB
, XML_EXTENSION
):
76 case XML_ELEMENT(DB_OASIS
, XML_EXTENSION
):
77 aProperty
.Name
= INFO_TEXTFILEEXTENSION
;
78 sFileTypeExtension
= sValue
;
81 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
83 if ( !aProperty
.Name
.isEmpty() )
85 if ( !aProperty
.Value
.hasValue() )
86 aProperty
.Value
<<= sValue
;
87 rImport
.addInfo(aProperty
);
91 if ( sLocation
.isEmpty() || sMediaType
.isEmpty() )
94 ::dbaccess::ODsnTypeCollection
aTypeCollection(rImport
.GetComponentContext());
95 OUString sURL
= aTypeCollection
.getDatasourcePrefixFromMediaType(sMediaType
,sFileTypeExtension
) + sLocation
;
98 xDataSource
->setPropertyValue(PROPERTY_URL
,Any(sURL
));
100 catch(const Exception
&)
102 DBG_UNHANDLED_EXCEPTION("dbaccess");
106 OXMLFileBasedDatabase::~OXMLFileBasedDatabase()
111 } // namespace dbaxml
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */