LibreOffice Module dbaccess (master) 1
xmlFileBasedDatabase.cxx
Go to the documentation of this file.
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
21#include "xmlfilter.hxx"
22#include <xmloff/xmltoken.hxx>
24#include <strings.hxx>
26#include <svl/filenotation.hxx>
28#include <dsntypes.hxx>
29namespace dbaxml
30{
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
33
35 const Reference< XFastAttributeList > & _xAttrList) :
36 SvXMLImportContext( rImport )
37{
38 Reference<XPropertySet> xDataSource = rImport.getDataSource();
39
40 PropertyValue aProperty;
41
42 OUString sLocation,sMediaType,sFileTypeExtension;
43 if (xDataSource.is())
44 {
45 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
46 {
47 OUString sValue = aIter.toString();
48
49 aProperty.Name.clear();
50 aProperty.Value = Any();
51
52 switch( aIter.getToken() )
53 {
54 case XML_ELEMENT(XLINK, XML_HREF):
55 {
56 SvtPathOptions aPathOptions;
57 OUString sFileName = aPathOptions.SubstituteVariable(sValue);
58 if ( sValue == sFileName )
59 {
60 const sal_Int32 nFileNameLength = sFileName.getLength();
61 if ( sFileName.endsWith("/") )
62 sFileName = sFileName.copy( 0, nFileNameLength - 1 );
63
64 sLocation = ::svt::OFileNotation( rImport.GetAbsoluteReference( sFileName ) ).get( ::svt::OFileNotation::N_SYSTEM );
65 }
66
67 if ( sLocation.isEmpty() )
68 sLocation = sValue;
69 }
70 break;
72 case XML_ELEMENT(DB_OASIS, XML_MEDIA_TYPE):
73 sMediaType = sValue;
74 break;
75 case XML_ELEMENT(DB, XML_EXTENSION):
76 case XML_ELEMENT(DB_OASIS, XML_EXTENSION):
77 aProperty.Name = INFO_TEXTFILEEXTENSION;
78 sFileTypeExtension = sValue;
79 break;
80 default:
81 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
82 }
83 if ( !aProperty.Name.isEmpty() )
84 {
85 if ( !aProperty.Value.hasValue() )
86 aProperty.Value <<= sValue;
87 rImport.addInfo(aProperty);
88 }
89 }
90 }
91 if ( sLocation.isEmpty() || sMediaType.isEmpty() )
92 return;
93
94 ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.GetComponentContext());
95 OUString sURL = aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension) + sLocation;
96 try
97 {
98 xDataSource->setPropertyValue(PROPERTY_URL,Any(sURL));
99 }
100 catch(const Exception&)
101 {
102 DBG_UNHANDLED_EXCEPTION("dbaccess");
103 }
104}
105
107{
108
109}
110
111} // namespace dbaxml
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sMediaType
OUString SubstituteVariable(const OUString &rVar) const
OUString getDatasourcePrefixFromMediaType(std::u16string_view _sMediaType, std::u16string_view _sExtension)
returns the dsn prefix for a given media type
Definition: dsntypes.cxx:159
void addInfo(const css::beans::PropertyValue &_rInfo)
add an Info to the sequence which will be appended to the data source
Definition: xmlfilter.hxx:108
const Reference< XPropertySet > & getDataSource() const
Definition: xmlfilter.hxx:97
OXMLFileBasedDatabase(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_xAttrList)
OUString get(NOTATION _eOutputNotation) const
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_HREF
XML_MEDIA_TYPE
XML_EXTENSION
constexpr OUStringLiteral INFO_TEXTFILEEXTENSION
Definition: strings.hxx:207
constexpr OUStringLiteral PROPERTY_URL(u"URL")
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)