merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / filter / xml / xmlFileBasedDatabase.cxx
blobab348bcc21ec0442d980a262744ee49bac907c18
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlFileBasedDatabase.cxx,v $
10 * $Revision: 1.6.68.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBA_XMLFILEBASEDDATABASE_HXX_INCLUDED
34 #include "xmlFileBasedDatabase.hxx"
35 #endif
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
38 #endif
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
41 #endif
42 #ifndef _XMLOFF_XMLNMSPE_HXX
43 #include <xmloff/xmlnmspe.hxx>
44 #endif
45 #ifndef _XMLOFF_NMSPMAP_HXX
46 #include <xmloff/nmspmap.hxx>
47 #endif
48 #ifndef DBA_XMLENUMS_HXX
49 #include "xmlEnums.hxx"
50 #endif
51 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
52 #include "xmlstrings.hrc"
53 #endif
54 #ifndef _TOOLS_DEBUG_HXX
55 #include <tools/debug.hxx>
56 #endif
57 #ifndef TOOLS_DIAGNOSE_EX_H
58 #include <tools/diagnose_ex.h>
59 #endif
60 #include <comphelper/sequence.hxx>
61 #include <svtools/filenotation.hxx>
62 #include <svtools/pathoptions.hxx>
63 #include "dsntypes.hxx"
64 namespace dbaxml
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::xml::sax;
68 DBG_NAME(OXMLFileBasedDatabase)
70 OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter& rImport,
71 sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
72 const Reference< XAttributeList > & _xAttrList) :
73 SvXMLImportContext( rImport, nPrfx, _sLocalName )
75 DBG_CTOR(OXMLFileBasedDatabase,NULL);
77 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
78 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
79 const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
81 Reference<XPropertySet> xDataSource = rImport.getDataSource();
83 PropertyValue aProperty;
85 const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
86 ::rtl::OUString sLocation,sMediaType,sFileTypeExtension;
87 for(sal_Int16 i = 0; i < nLength; ++i)
89 ::rtl::OUString sLocalName;
90 const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
91 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
92 const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
94 aProperty.Name = ::rtl::OUString();
95 aProperty.Value = Any();
97 switch( rTokenMap.Get( nPrefix, sLocalName ) )
99 case XML_TOK_DB_HREF:
101 SvtPathOptions aPathOptions;
102 rtl::OUString sFileName = aPathOptions.SubstituteVariable(sValue);
103 if ( sValue == sFileName )
105 sLocation = ::svt::OFileNotation(rImport.GetAbsoluteReference(sValue)).get( ::svt::OFileNotation::N_SYSTEM );
108 if ( sLocation.getLength() == 0 )
109 sLocation = sValue;
111 break;
112 case XML_TOK_MEDIA_TYPE:
113 sMediaType = sValue;
114 break;
115 case XML_TOK_EXTENSION:
116 aProperty.Name = INFO_TEXTFILEEXTENSION;
117 sFileTypeExtension = sValue;
118 break;
120 if ( aProperty.Name.getLength() )
122 if ( !aProperty.Value.hasValue() )
123 aProperty.Value <<= sValue;
124 rImport.addInfo(aProperty);
127 if ( sLocation.getLength() && sMediaType.getLength() )
129 ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.getORB());
130 ::rtl::OUString sURL(aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension));
131 sURL += sLocation;
134 xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL));
136 catch(Exception)
138 DBG_UNHANDLED_EXCEPTION();
142 // -----------------------------------------------------------------------------
144 OXMLFileBasedDatabase::~OXMLFileBasedDatabase()
147 DBG_DTOR(OXMLFileBasedDatabase,NULL);
149 // -----------------------------------------------------------------------------
150 //----------------------------------------------------------------------------
151 } // namespace dbaxml
152 // -----------------------------------------------------------------------------