bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / filter / xml / xmlFileBasedDatabase.cxx
blob5f24a9fb2bef57b7f14705d7f1ab61a15341bd6b
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;
38 DBG_NAME(OXMLFileBasedDatabase)
40 OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter& rImport,
41 sal_uInt16 nPrfx, const OUString& _sLocalName,
42 const Reference< XAttributeList > & _xAttrList) :
43 SvXMLImportContext( rImport, nPrfx, _sLocalName )
45 DBG_CTOR(OXMLFileBasedDatabase,NULL);
47 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
48 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
49 const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
51 Reference<XPropertySet> xDataSource = rImport.getDataSource();
53 PropertyValue aProperty;
55 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
56 OUString sLocation,sMediaType,sFileTypeExtension;
57 for(sal_Int16 i = 0; i < nLength; ++i)
59 OUString sLocalName;
60 const OUString sAttrName = _xAttrList->getNameByIndex( i );
61 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
62 const OUString sValue = _xAttrList->getValueByIndex( i );
64 aProperty.Name = OUString();
65 aProperty.Value = Any();
67 switch( rTokenMap.Get( nPrefix, sLocalName ) )
69 case XML_TOK_DB_HREF:
71 SvtPathOptions aPathOptions;
72 OUString sFileName = aPathOptions.SubstituteVariable(sValue);
73 if ( sValue == sFileName )
75 const sal_Int32 nFileNameLength = sFileName.getLength();
76 if ( ( nFileNameLength > 0 ) && ( sFileName.getStr()[ nFileNameLength - 1 ] == '/' ) )
77 sFileName = sFileName.copy( 0, nFileNameLength - 1 );
79 sLocation = ::svt::OFileNotation( rImport.GetAbsoluteReference( sFileName ) ).get( ::svt::OFileNotation::N_SYSTEM );
82 if ( sLocation.isEmpty() )
83 sLocation = sValue;
85 break;
86 case XML_TOK_MEDIA_TYPE:
87 sMediaType = sValue;
88 break;
89 case XML_TOK_EXTENSION:
90 aProperty.Name = INFO_TEXTFILEEXTENSION;
91 sFileTypeExtension = sValue;
92 break;
94 if ( !aProperty.Name.isEmpty() )
96 if ( !aProperty.Value.hasValue() )
97 aProperty.Value <<= sValue;
98 rImport.addInfo(aProperty);
101 if ( !(sLocation.isEmpty() || sMediaType.isEmpty()) )
103 ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.GetComponentContext());
104 OUString sURL(aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension));
105 sURL += sLocation;
108 xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL));
110 catch(const Exception&)
112 DBG_UNHANDLED_EXCEPTION();
116 // -----------------------------------------------------------------------------
118 OXMLFileBasedDatabase::~OXMLFileBasedDatabase()
121 DBG_DTOR(OXMLFileBasedDatabase,NULL);
123 // -----------------------------------------------------------------------------
124 //----------------------------------------------------------------------------
125 } // namespace dbaxml
126 // -----------------------------------------------------------------------------
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */