bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlFileBasedDatabase.cxx
blob90f0b1f7c7316f20825426c649497444f89c5ca2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/processfactory.hxx>
30 #include <comphelper/sequence.hxx>
31 #include <svl/filenotation.hxx>
32 #include <unotools/pathoptions.hxx>
33 #include "dsntypes.hxx"
34 namespace dbaxml
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::xml::sax;
39 OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter& rImport,
40 sal_uInt16 nPrfx, const OUString& _sLocalName,
41 const Reference< XAttributeList > & _xAttrList) :
42 SvXMLImportContext( rImport, nPrfx, _sLocalName )
45 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
46 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
47 const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
49 Reference<XPropertySet> xDataSource = rImport.getDataSource();
51 PropertyValue aProperty;
53 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
54 OUString sLocation,sMediaType,sFileTypeExtension;
55 for(sal_Int16 i = 0; i < nLength; ++i)
57 OUString sLocalName;
58 const OUString sAttrName = _xAttrList->getNameByIndex( i );
59 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
60 const OUString sValue = _xAttrList->getValueByIndex( i );
62 aProperty.Name.clear();
63 aProperty.Value = Any();
65 switch( rTokenMap.Get( nPrefix, sLocalName ) )
67 case XML_TOK_DB_HREF:
69 SvtPathOptions aPathOptions;
70 OUString sFileName = aPathOptions.SubstituteVariable(sValue);
71 if ( sValue == sFileName )
73 const sal_Int32 nFileNameLength = sFileName.getLength();
74 if ( sFileName.endsWith("/") )
75 sFileName = sFileName.copy( 0, nFileNameLength - 1 );
77 sLocation = ::svt::OFileNotation( rImport.GetAbsoluteReference( sFileName ) ).get( ::svt::OFileNotation::N_SYSTEM );
80 if ( sLocation.isEmpty() )
81 sLocation = sValue;
83 break;
84 case XML_TOK_MEDIA_TYPE:
85 sMediaType = sValue;
86 break;
87 case XML_TOK_EXTENSION:
88 aProperty.Name = INFO_TEXTFILEEXTENSION;
89 sFileTypeExtension = sValue;
90 break;
92 if ( !aProperty.Name.isEmpty() )
94 if ( !aProperty.Value.hasValue() )
95 aProperty.Value <<= sValue;
96 rImport.addInfo(aProperty);
99 if ( !(sLocation.isEmpty() || sMediaType.isEmpty()) )
101 ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.GetComponentContext());
102 OUString sURL(aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension));
103 sURL += sLocation;
106 xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL));
108 catch(const Exception&)
110 DBG_UNHANDLED_EXCEPTION();
115 OXMLFileBasedDatabase::~OXMLFileBasedDatabase()
120 } // namespace dbaxml
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */